Advertisement
Guest User

scr_draw_button()

a guest
Aug 6th, 2011
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //scr_draw_button( x1, y1, x2, y2, coltop, colbias, colbottom, outline, coloutline, shadow, colshadow, percent, steps )
  2. /*
  3. x1,y1,x2,y2 are the boundaries of the shape
  4. coltop is the color of the top of the button
  5. colbias is the color that the middle is blended towards between coltop and colbottom using a nurb-like technique, it's really cool
  6. colbottom is the color of the bottom of the button
  7. outline is whether or not there should be an outline (TRUE/FALSE)
  8. coloutline is the color of the outline
  9. shadow is whether there should be a shadow, and how much (0 to 1, 0 is disabled)
  10. colshadow is the color of the shadow
  11. percent is the percent of the shape should be rounded (0 to 1, 0 being a rectangle, and 1 being a circle)
  12. steps is how smooth you want the shape to be, but the smoother it is, the more repetitions it takes in the loop
  13. */
  14.  
  15. //~Jonathan Pearl. No credit neccessary, just don't try to say you made it, because that would be a jerk move. ;)
  16.  
  17. var _i,_x1,_y1,_x2,_y2,_col1,_col2,_col3,_perc,_steps,_rat,_doo,_dist,_tcol;
  18. _x1    = argument0;
  19. _y1    = argument1;
  20. _x2    = argument2;
  21. _y2    = argument3;
  22. _col1  = argument4;
  23. _col2  = argument5;
  24. _col3  = argument6;
  25. _perc  = argument11;
  26. _steps = argument12;
  27.  
  28.  
  29. draw_primitive_begin( pr_trianglestrip );
  30. draw_vertex_color( _x1 + _perc*(_x2-_x1)/2, _y1, _col1, 1 );
  31. draw_vertex_color( _x2 - _perc*(_x2-_x1)/2, _y1, _col1, 1 );
  32. for( _i = 0; _i < _steps; _i += 1 )
  33. {
  34.     _rat = scr_linearaverage( _y1, _y2, ( ( -(cos((12*((_i+1) / (_steps+1))-pi)/2)-6*((_i+1) / (_steps+1)))/12)*6/pi ) );
  35.     _doo = abs( ((_y1 + _y2)/2)-_rat)/((_y2 - _y1)/2);
  36.     _dist = -cos(arcsin( _doo ))*_perc*(_x2-_x1)/2;
  37.  
  38.     _tcol = make_color_rgb( scr_linearaverage( scr_linearaverage(color_get_red(_col1),color_get_red(_col2),(_i+1) / (_steps+1)),
  39.                                 scr_linearaverage(color_get_red(_col2),color_get_red(_col3),(_i+1) / (_steps+1)), (_i+1) / (_steps+1)),
  40.                             scr_linearaverage( scr_linearaverage(color_get_green(_col1),color_get_green(_col2),(_i+1) / (_steps+1)),
  41.                                 scr_linearaverage(color_get_green(_col2),color_get_green(_col3),(_i+1) / (_steps+1)), (_i+1) / (_steps+1)),
  42.                             scr_linearaverage( scr_linearaverage(color_get_blue(_col1),color_get_blue(_col2),(_i+1) / (_steps+1)),
  43.                                 scr_linearaverage(color_get_blue(_col2),color_get_blue(_col3),(_i+1) / (_steps+1)), (_i+1) / (_steps+1)));
  44.     draw_vertex_color( _x1 + _dist + _perc*(_x2-_x1)/2, _rat , _tcol , 1 );
  45.     draw_vertex_color( _x2 - _dist - _perc*(_x2-_x1)/2, _rat , _tcol , 1 );
  46. }
  47. draw_vertex_color( _x1 + _perc*(_x2-_x1)/2, _y2, _col3, 1 );
  48. draw_vertex_color( _x2 - _perc*(_x2-_x1)/2, _y2, _col3, 1 );
  49. draw_primitive_end();
  50.  
  51. if (argument9!=0)
  52. {
  53.     draw_primitive_begin( pr_trianglefan );
  54.     draw_vertex_color( (_x2+_x1)/2, (_y1+3*_y2)/4, argument10, .1*argument9 );
  55.    
  56.     draw_vertex_color( _x1 + _perc*(_x2-_x1)/2, _y1, argument10, 0 );
  57.     draw_vertex_color( _x2 - _perc*(_x2-_x1)/2, _y1, argument10, 0 );
  58.     for( _i = 0; _i < _steps; _i += 1 )
  59.     {
  60.         _rat = scr_linearaverage( _y1, _y2, ( ( -(cos((12*((_i+1) / (_steps+1))-pi)/2)-6*((_i+1) / (_steps+1)))/12)*6/pi ) );
  61.         _doo = abs( ((_y1 + _y2)/2)-_rat)/((_y2 - _y1)/2);
  62.         _dist = -cos(arcsin( _doo ))*_perc*(_x2-_x1)/2;
  63.         draw_vertex_color( _x2 - _dist - _perc*(_x2-_x1)/2, _rat , argument10 , (1-( ((_y1 + _y2)/2)-_rat)/((_y2 - _y1)/2))*argument9 );
  64.     }
  65.     draw_vertex_color( _x2 - _perc*(_x2-_x1)/2, _y2, argument10, (1-( ((_y1 + _y2)/2)-(scr_linearaverage( _y1, _y2, ( ( -(cos((12*((_steps+1) / (_steps+1))-pi)/2)-6*((_i+1) / (_steps+1)))/12)*6/pi ) )))/((_y2 - _y1)/2))*argument9 );
  66.     for( _i = _steps; _i >= 0; _i -= 1 )
  67.     {
  68.         _rat = scr_linearaverage( _y1, _y2, ( ( -(cos((12*((_i+1) / (_steps+1))-pi)/2)-6*((_i+1) / (_steps+1)))/12)*6/pi ) );
  69.         _doo = abs( ((_y1 + _y2)/2)-_rat)/((_y2 - _y1)/2);
  70.         _dist = -cos(arcsin( _doo ))*_perc*(_x2-_x1)/2;
  71.         draw_vertex_color( _x1 + _dist + _perc*(_x2-_x1)/2, _rat , argument10 , (1-( ((_y1 + _y2)/2)-_rat)/((_y2 - _y1)/2))*argument9 );
  72.     }
  73.     draw_vertex_color( _x1 + _perc*(_x2-_x1)/2, _y1, argument10, 0 );
  74.    
  75.     draw_primitive_end();
  76.    
  77. }
  78.  
  79. if (argument7)
  80. {
  81.     draw_primitive_begin( pr_linestrip );
  82.     draw_vertex_color( _x1 + _perc*(_x2-_x1)/2, _y1, argument8, 1 );
  83.     draw_vertex_color( _x2 - _perc*(_x2-_x1)/2, _y1, argument8, 1 );
  84.     for( _i = 0; _i < _steps; _i += 1 )
  85.     {
  86.         _rat = scr_linearaverage( _y1, _y2, ( ( -(cos((12*((_i+1) / (_steps+1))-pi)/2)-6*((_i+1) / (_steps+1)))/12)*6/pi ) );
  87.         _doo = abs( ((_y1 + _y2)/2)-_rat)/((_y2 - _y1)/2);
  88.         _dist = -cos(arcsin( _doo ))*_perc*(_x2-_x1)/2;
  89.         draw_vertex_color( _x2 - _dist - _perc*(_x2-_x1)/2, _rat , argument8 , 1 );
  90.     }
  91.     draw_vertex_color( _x2 - _perc*(_x2-_x1)/2, _y2, argument8, 1 );
  92.     for( _i = _steps; _i >= 0; _i -= 1 )
  93.     {
  94.         _rat = scr_linearaverage( _y1, _y2, ( ( -(cos((12*((_i+1) / (_steps+1))-pi)/2)-6*((_i+1) / (_steps+1)))/12)*6/pi ) );
  95.         _doo = abs( ((_y1 + _y2)/2)-_rat)/((_y2 - _y1)/2);
  96.         _dist = -cos(arcsin( _doo ))*_perc*(_x2-_x1)/2;
  97.         draw_vertex_color( _x1 + _dist + _perc*(_x2-_x1)/2, _rat , argument8 , 1 );
  98.     }
  99.     draw_vertex_color( _x1 + _perc*(_x2-_x1)/2, _y1, argument8, 1 );
  100.    
  101.     draw_primitive_end();
  102.    
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement