Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ellpise routine
#1
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?
Reply
#2
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.
Reply
#3
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.]
Reply
#4
http://mathworld.wolfram.com/Ellipse.html
Reply
#5
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.]
Reply
#6
Yeah i know the formula for an ellipse, the problem is that drawing one on a pixel screen is difficult for me.
Reply
#7
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
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#8
Thanks man! You are a legend.
Reply
#9
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.
Reply
#10
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.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)