Lua: Fixed drawdisk which was drawing a square instead of a circle (doh!). Radius can now be a multiple of 0.5 to draw circles of even sizes (r=0 -> 1x1, r=0.5 -> 2x2, r=1 -> 3x3 etc.)
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1798 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
@@ -457,30 +457,44 @@ int L_DrawCircle(lua_State* L)
|
||||
|
||||
int L_DrawDisk(lua_State* L)
|
||||
{
|
||||
int center_x, center_y, r, c;
|
||||
int center_x, center_y, diameter, c, r, even;
|
||||
long circle_limit;
|
||||
short x_pos,y_pos;
|
||||
short min_x,max_x,min_y,max_y;
|
||||
double r_float;
|
||||
|
||||
int nb_args = lua_gettop(L);
|
||||
|
||||
LUA_ARG_LIMIT(4, "drawdisk");
|
||||
LUA_ARG_NUMBER(1, "drawdisk", center_x, INT_MIN, INT_MAX);
|
||||
LUA_ARG_NUMBER(2, "drawdisk", center_y, INT_MIN, INT_MAX);
|
||||
LUA_ARG_NUMBER(3, "drawdisk", r, INT_MIN, INT_MAX);
|
||||
LUA_ARG_NUMBER(3, "drawdisk", r_float, INT_MIN, INT_MAX);
|
||||
LUA_ARG_NUMBER(4, "drawdisk", c, INT_MIN, INT_MAX);
|
||||
|
||||
circle_limit = r*r;
|
||||
if (r_float<0.0)
|
||||
return 0;
|
||||
diameter=(int)(floor(r_float*2.0+1.0));
|
||||
r=diameter/2;
|
||||
even=!(diameter&1);
|
||||
|
||||
circle_limit = Circle_squared_diameter(diameter);
|
||||
|
||||
// Compute clipping limits
|
||||
min_x=center_x-r<0 ? 0 : center_x-r;
|
||||
min_x=center_x-r+even<0 ? 0 : center_x-r+even;
|
||||
max_x=center_x+r>=Main_image_width? Main_image_width-1 : center_x+r;
|
||||
min_y=center_y-r<0 ? 0 : center_y-r;
|
||||
min_y=center_y-r+even<0 ? 0 : center_y-r+even;
|
||||
max_y=center_y+r>=Main_image_height? Main_image_height-1 : center_y+r;
|
||||
|
||||
for (y_pos=min_y;y_pos<=max_y;y_pos++)
|
||||
{
|
||||
short y=(y_pos-center_y)*2-even;
|
||||
for (x_pos=min_x;x_pos<=max_x;x_pos++)
|
||||
Pixel_in_current_screen(x_pos,y_pos,c,0);
|
||||
{
|
||||
short x=(x_pos-center_x)*2-even;
|
||||
if (x*x+y*y <= circle_limit)
|
||||
Pixel_in_current_screen(x_pos,y_pos,c,0);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user