Draw Ellipse / Oval

Previous topic - Next topic

Kitty Hello

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

Ian Price

Ah, that's easy Gernot - but an internal function... ;)

Cheers anyway :)
I came. I saw. I played.

Schranz0r

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Ã,° ?
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Kitty Hello

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

Schranz0r

ooops right, my bad :D
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

S. P. Gardebiter

Thanks Gernot.
How fast is this function?
~ Cave Story rules! ~

Kitty Hello

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

kanonet

#7
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.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64