GLBasic forum

Codesnippets => 2D-snippets => Topic started by: Kitty Hello on 2010-May-04

Title: Draw Ellipse / Oval
Post by: Kitty Hello on 2010-May-04
Code (glbasic) Select

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, y-SIN(phi)*h, 0,0,col
NEXT
ENDPOLY

ENDFUNCTION

Keywords: draw ellipse, draw oval, drawoval, drawellipse, circle, elipse
Title: Re: Draw Ellipse / Oval
Post by: Ian Price on 2010-May-04
Ah, that's easy Gernot - but an internal function... ;)

Cheers anyway :)
Title: Re: Draw Ellipse / Oval
Post by: Schranz0r on 2010-May-04
Quote from: Kitty Hello on 2010-May-04
   FOR phi = 0 TO 360 STEP 5 // how poly do you want it?

Then you have 361Ã,° ?
Title: Re: Draw Ellipse / Oval
Post by: Kitty Hello on 2010-May-04
no. First point is at 0Ã,°, last point is at 360Ã,°, which is the same as 0Ã,° (close the circle)
Title: Re: Draw Ellipse / Oval
Post by: Schranz0r on 2010-May-04
ooops right, my bad :D
Title: Re: Draw Ellipse / Oval
Post by: S. P. Gardebiter on 2010-Jun-04
Thanks Gernot.
How fast is this function?
Title: Re: Draw Ellipse / Oval
Post by: Kitty Hello on 2010-Jun-04
for opengl(es) platforms, fastest possible. For wiz/pocketpc you might be faster with a drawrect method.
Title: Re: Draw Ellipse / Oval
Post by: kanonet on 2011-May-11
This dont work as expected, it should be:
Code (glbasic) Select
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, y-SIN(phi)*h, 0,0,col
NEXT
ENDPOLY

ENDFUNCTION


Or if you want to include drawing arcs:
Code (glbasic) Select
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, y-SIN(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.