Drawing commands

Previous topic - Next topic

Lazarus

Hello.

I have a question about GLBasic's drawing commands.  At the moment there are only "setpixel" "drawline" and "fillrect".  Very basic, to be sure. ;)

Why no circle command, at least?  
I wrote this function in GLBasic to draw a circle, and it runs quite well - but wouldn't a built-in circle function run faster?

Code (glbasic) Select
FUNCTION circle: xCenter, yCenter, radius, color
//These values are defined LOCAL:
 //x, y, radius, color
 LET x = 0; y = 0; r2 = 0;
 
r2 = radius*radius
SETPIXEL xCenter, yCenter + radius, color
SETPIXEL xCenter, yCenter - radius, color
SETPIXEL xCenter + radius, yCenter, color
SETPIXEL xCenter - radius, yCenter, color
x= 1
y = INTEGER(SQR(r2-1) + 0.5)

WHILE x < y
SETPIXEL xCenter+x, yCenter+y, color
SETPIXEL xCenter+x, yCenter-y, color
SETPIXEL xCenter-x, yCenter+y, color
SETPIXEL xCenter-x, yCenter-y, color
SETPIXEL xCenter+y, yCenter+x, color
SETPIXEL xCenter+y, yCenter-x, color
SETPIXEL xCenter-y, yCenter+x, color
SETPIXEL xCenter-y, yCenter-x, color
x = x + 1
y = INTEGER(SQR(r2 - x*x) + 0.5)
WEND
IF x = y
SETPIXEL xCenter+x, yCenter+y, color
SETPIXEL xCenter+x, yCenter-y, color
SETPIXEL xCenter-x, yCenter+y, color
SETPIXEL xCenter-x, yCenter-y, color
ENDIF
ENDFUNCTION // CIRCLE
Is there a reason it is not a built-in command?

Minion

Lazarus,

slight improvement on your code function, ive tested it it it appears to be about a quater faster than yours (will help if you intend to draw lots of circles).

Code (glbasic) Select
// ------------------------------------------------------------- //
// -=#  CIRC  #=-
// ------------------------------------------------------------- //
FUNCTION circ: x, y, r, c
// These values are defined LOCAL:
// x, y, r, c

x1=SIN(0)*r
y1=COS(0)*r
FOR j=1 TO 360
x2=SIN(j)*r
y2=COS(j)*r
DRAWLINE x+x1,y+y1,x+x2,y+y2,c
x1=x2
y1=y2
NEXT

ENDFUNCTION // CIRC

Lazarus

Yes, that does seem to work faster.  Thank you. :)

Kitty Hello