By Daniel · December 24, 2008
A highly generalized function for drawing circular shapes
/*
draw_circle_ext( x, y, r, color1, color2, alpha1, alpha2, outline, sides, rot )
ARGUMENTS
- x: the X coordinate of the center
- y: the Y coordinate of the center
- r: the radious of the circle
- color1: the color value at the center
- color2: the color value at the outer edge
- alpha1: the alpha value at the center
- alpha2: the alpha value at the outer edge
- outline: true to draw only an outline, false to fill the circle
- sides: number of sides that will comprise the circle
- rot: the angular offset to apply
by Daniel Lubarov, 2008
*/
var x_center, y_center, r, color1, color2, alpha1, outline, sides, rot,
pr_type, n, theta, x_vertex, y_vertex;
x_center = argument0;
y_center = argument1;
r = argument2;
color1 = argument3;
color2 = argument4;
alpha1 = argument5;
alpha2 = argument6;
outline = argument7;
sides = argument8;
rot = argument9;
// Determine primitive type
if ( outline )
pr_type = pr_linestrip;
else
pr_type = pr_trianglefan;
// Initiate primitive
draw_primitive_begin( pr_type );
// Draw center vertex if needed
if ( !outline )
draw_vertex_color( x_center, y_center, color1, alpha1 );
// Compute each vertex and add them to the primitive
for ( n = 0; n <= sides; n += 1 ) {
theta = (n/sides)*360 + rot;
x_vertex = x_center + lengthdir_x( r, theta );
y_vertex = y_center + lengthdir_y( r, theta );
draw_vertex_color( x_vertex, y_vertex, color2, alpha2 );
}
// Render the primitive & clear the buffer
draw_primitive_end();
Categories: 2D graphics
There are no comments to display.
You must be signed in to post comments.