Posts: 294
Threads: 9
Joined: Oct 2002
Hey. Im wondering if anybody can help me with an ellipse routine. Im trying to code a routine that will draw an ellipse for a sprite editor. Currently the ellipse tool works very badly. One that works like the one in MsPaint would be the goal. Any resources or algorithms?
Posts: 3,616
Threads: 287
Joined: Jan 2003
I'm not at all experienced with this, but wouldn't it involve taking a regular CIRCLE routine and altering the radius with each iteration (for each pixel to be set).
f only life let you press CTRL-Z.
--------------------------------------
Freebasic is like QB, except it doesn't suck.
Posts: 95
Threads: 8
Joined: Nov 2003
well, elipses have two foci, instead of one, like a circle. I forgot the exact equation, but its very similar to a hyperboli equation. Look it up on google.
url=http://webberboy.no-ip.com]Fine Hand-Crafted Pens[/url]
Pneumonoultramicroscopicsilicovolcanoconiosis: Noun, A hypothetical, invented disease of the lungs, caused by inhaling mineral or metallic dust, such as silicon and quartzite, over a long period.]
Posts: 42
Threads: 9
Joined: Jul 2004
Posts: 95
Threads: 8
Joined: Nov 2003
right. r1+r2=2a. I think for a hyperboly it is r1-r2=2a or something. Anyways...
url=http://webberboy.no-ip.com]Fine Hand-Crafted Pens[/url]
Pneumonoultramicroscopicsilicovolcanoconiosis: Noun, A hypothetical, invented disease of the lungs, caused by inhaling mineral or metallic dust, such as silicon and quartzite, over a long period.]
Posts: 294
Threads: 9
Joined: Oct 2002
Yeah i know the formula for an ellipse, the problem is that drawing one on a pixel screen is difficult for me.
Posts: 3,288
Threads: 167
Joined: Nov 2001
Code:
SUB Rel.Ellipse (VideoBuf(), Xcenter, Ycenter, Xrad, Yrad, Clr)
'Original Code by Rich Geldreich
'Taken from the ABC packets and converted by me :*)
'Draws an ellipse with Xcenter and Ycenter as the centercoords
'with radius of Xrad and Yrad,. if xrad=yrad then a circle is drawn
'Clipping supported!!!
DEF SEG = VARSEG(VideoBuf(0))
VpSaddr = VARPTR(VideoBuf(2))
DIM xe AS LONG, ye AS LONG, e AS LONG
IF Yrad = 0 THEN 'special cases for horizontal & vertical ellipses
Rel.Line VideoBuf(), Xcenter - Xrad, Ycenter, Xcenter + Xrad, Ycenter, Clr
EXIT SUB
END IF
IF Xrad = 0 THEN
Rel.Line VideoBuf(), Xcenter, Ycenter - Yrad, Xcenter, Ycenter + Yrad, Clr
EXIT SUB
END IF
'work with largest axis to avoid rounding errors
IF Yrad <= Xrad THEN
X = 0: Y = Yrad
xe = 0: ye = CLNG(Xrad) * Xrad
e = -ye \ 2: C = ye \ Yrad
DO
IF e <= 0 THEN
DO
Xput = Xcenter + X
Yput = Ycenter + Y
GOSUB PutPixelEllipse
Xput = Xcenter - X
Yput = Ycenter + Y
GOSUB PutPixelEllipse
Xput = Xcenter + X
Yput = Ycenter - Y
GOSUB PutPixelEllipse
Xput = Xcenter - X
Yput = Ycenter - Y
GOSUB PutPixelEllipse
X = X + 1
xe = xe + Yrad
e = e + xe
LOOP WHILE e <= 0
ELSE
Xput = Xcenter + X
Yput = Ycenter + Y
GOSUB PutPixelEllipse
Xput = Xcenter - X
Yput = Ycenter + Y
GOSUB PutPixelEllipse
Xput = Xcenter + X
Yput = Ycenter - Y
GOSUB PutPixelEllipse
Xput = Xcenter - X
Yput = Ycenter - Y
GOSUB PutPixelEllipse
END IF
Y = Y - 1
ye = ye - C
e = e - ye
LOOP UNTIL Y = 0
Xput = Xcenter + X
Yput = Ycenter
GOSUB PutPixelEllipse
Xput = Xcenter - X
Yput = Ycenter
GOSUB PutPixelEllipse
Xput = Xcenter + X
Yput = Ycenter
GOSUB PutPixelEllipse
Xput = Xcenter - X
Yput = Ycenter
GOSUB PutPixelEllipse
ELSE
X = 0: Y = Xrad
xe = 0: ye = CLNG(Yrad) * Yrad
e = -ye \ 2: C = ye \ Xrad
DO
IF e <= 0 THEN
DO
Xput = Xcenter + Y
Yput = Ycenter + X
GOSUB PutPixelEllipse
Xput = Xcenter - Y
Yput = Ycenter + X
GOSUB PutPixelEllipse
Xput = Xcenter + Y
Yput = Ycenter - X
GOSUB PutPixelEllipse
Xput = Xcenter - Y
Yput = Ycenter - X
GOSUB PutPixelEllipse
X = X + 1
xe = xe + Xrad
e = e + xe
LOOP WHILE e <= 0
ELSE
Xput = Xcenter + Y
Yput = Ycenter + X
GOSUB PutPixelEllipse
Xput = Xcenter - Y
Yput = Ycenter + X
GOSUB PutPixelEllipse
Xput = Xcenter + Y
Yput = Ycenter - X
GOSUB PutPixelEllipse
Xput = Xcenter - Y
Yput = Ycenter - X
GOSUB PutPixelEllipse
END IF
Y = Y - 1
ye = ye - C
e = e - ye
LOOP UNTIL Y = 0
Xput = Xcenter
Yput = Ycenter + X
GOSUB PutPixelEllipse
Xput = Xcenter
Yput = Ycenter + X
GOSUB PutPixelEllipse
Xput = Xcenter
Yput = Ycenter - X
GOSUB PutPixelEllipse
Xput = Xcenter
Yput = Ycenter - X
GOSUB PutPixelEllipse
END IF
DEF SEG
EXIT SUB
PutPixelEllipse:
NotClip = (((Xput < 0) + (Yput < 0) + (Xput > Scr.Xmax) + (Yput > Scr.Ymax)) = 0)
IF NotClip THEN POKE YsegLUT(Yput) + Xput + VpSaddr, Clr
RETURN
END SUB
Posts: 294
Threads: 9
Joined: Oct 2002
Thanks man! You are a legend.
Posts: 3,279
Threads: 170
Joined: Nov 2003
Ouch rel, that's a little huge, don't you think? I'm pretty sure I've got a far smaller routine than that kicking around somewhere that works perfectly...
I'd knock on wood, but my desk is particle board.
Posts: 6,419
Threads: 74
Joined: Mar 2002
I have one in C that draws tilted ellipses taking the two radiuses and an angle... In my dev computer. If you can wait a couple o'days I'll dig for it.