Author Topic: Draw Ellipse / Oval  (Read 4516 times)

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10682
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
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

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4141
  • On the shoulders of giants.
    • View Profile
    • My Apps
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.

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5006
  • O Rly?
    • View Profile
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 <3 DGArray's :D

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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10682
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
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)

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5006
  • O Rly?
    • View Profile
Re: Draw Ellipse / Oval
« Reply #4 on: 2010-May-04 »
ooops right, my bad :D
I <3 DGArray's :D

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

Offline S. P. Gardebiter

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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10682
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
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.

Offline kanonet

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1142
    • View Profile
    • My GLBasic code archiv
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