BASIC

### Author Topic: Draw Ellipse / Oval  (Read 4670 times)

#### Kitty Hello

• code monkey
• Prof. Inline
• Posts: 10695
• here on my island the sea says 'hello'
##### Draw Ellipse / Oval
« 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

#### Ian Price

• Prof. Inline
• Posts: 4144
• On the shoulders of giants.
##### Re: Draw Ellipse / Oval
« Reply #1 on: 2010-May-04 »
Ah, that's easy Gernot - but an internal function...

Cheers anyway
I came. I saw. I played.

#### Schranz0r

• Prof. Inline
• Posts: 5013
• O Rly?
##### Re: Draw Ellipse / Oval
« Reply #2 on: 2010-May-04 »
FOR phi = 0 TO 360 STEP 5 // how poly do you want it?

Then you have 361Ã‚Â° ?
I DGArray's

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

#### Kitty Hello

• code monkey
• Prof. Inline
• Posts: 10695
• here on my island the sea says 'hello'
##### Re: Draw Ellipse / Oval
« Reply #3 on: 2010-May-04 »
no. First point is at 0Ã‚Â°, last point is at 360Ã‚Â°, which is the same as 0Ã‚Â° (close the circle)

#### Schranz0r

• Prof. Inline
• Posts: 5013
• O Rly?
##### Re: Draw Ellipse / Oval
« Reply #4 on: 2010-May-04 »
I DGArray's

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

#### S. P. Gardebiter

• Mr. Polyvector
• Posts: 245
##### Re: Draw Ellipse / Oval
« Reply #5 on: 2010-Jun-04 »
Thanks Gernot.
How fast is this function?
~ Cave Story rules! ~

#### Kitty Hello

• code monkey
• Prof. Inline
• Posts: 10695
• here on my island the sea says 'hello'
##### Re: Draw Ellipse / Oval
« Reply #6 on: 2010-Jun-04 »
for opengl(es) platforms, fastest possible. For wiz/pocketpc you might be faster with a drawrect method.

#### kanonet

• Prof. Inline
• Posts: 1142
##### Re: Draw Ellipse / Oval
« Reply #7 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.
« Last Edit: 2011-May-11 by kanonet »
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64