GLBasic forum
Codesnippets => 2Dsnippets => Topic started by: Kitty Hello on 2010May04

DrawOval(100,100,99,33,RGB(255,0,0))
SHOWSCREEN
MOUSEWAIT
FUNCTION DrawOval%: x, y, w, h, col%
INC x, w/2
INC y, h/2
LOCAL phi
STARTPOLY 1, 0
POLYVECTOR x,y, 0,0,col
FOR phi = 0 TO 360 STEP 5 // how poly do you want it?
POLYVECTOR x+COS(phi)*w, ySIN(phi)*h, 0,0,col
NEXT
ENDPOLY
ENDFUNCTION
Keywords: draw ellipse, draw oval, drawoval, drawellipse, circle, elipse

Ah, that's easy Gernot  but an internal function... ;)
Cheers anyway :)

FOR phi = 0 TO 360 STEP 5 // how poly do you want it?
Then you have 361Ã‚Â° ?

no. First point is at 0Ã‚Â°, last point is at 360Ã‚Â°, which is the same as 0Ã‚Â° (close the circle)

ooops right, my bad :D

Thanks Gernot.
How fast is this function?

for opengl(es) platforms, fastest possible. For wiz/pocketpc you might be faster with a drawrect method.

This dont work as expected, it should be:
FUNCTION DrawOval%: x, y, w, h, col%
w = w/2
h = h/2
INC x, w
INC y, h
STARTPOLY 1, 0
POLYVECTOR x,y, 0,0,col
FOR phi = 0 TO 360 STEP 5 // how poly do you want it?
POLYVECTOR x+COS(phi)*w, ySIN(phi)*h, 0,0,col
NEXT
ENDPOLY
ENDFUNCTION
Or if you want to include drawing arcs:
FUNCTION DrawOval%: x, y, w, h, col%, arc=360, arcs=0 // arc MUST be >0! arcs=starting of the arc 0=top
w = w/2
h = h/2
INC x, w
INC y, h
INC arcs, 90
INC arc, arcs
STARTPOLY 1, 0
POLYVECTOR x,y, 0,0,col
FOR phi = arcs TO arc STEP 5 // how poly do you want it?
POLYVECTOR x+COS(phi)*w, ySIN(phi)*h, 0,0,col
NEXT
ENDPOLY
ENDFUNCTION
If you need more speed, change the STEP 5 to higher number or try QSIN and QCOS.