LoginLogin

Fast ellipses with precomputed sines and ARYOP

Root / Submissions / [.]

MZ952Created:
OPTION STRICT
OPTION DEFINT
DIM _POINTS=30
DIM SIN#[_POINTS],COS#[_POINTS]
FILL_SINES

DEF ELLIPSE X,Y,RX,RY,FL,C
 DIM I,LX[_POINTS],LY[_POINTS]
 ARYOP #AOPMAD,LX,SIN#,RX,X
 ARYOP #AOPMAD,LY,COS#,RY,Y
 FOR I=1 TO _POINTS-1
  IF FL THEN
   GTRI X,Y,LX[I],LY[I],LX[I-1],LY[I-1],C
  ELSE
   GLINE LX[I],LY[I],LX[I-1],LY[I-1],C
  ENDIF
 NEXT I
 IF FL THEN
  GTRI X,Y,LX[0],LY[0],LX[_POINTS-1],LY[_POINTS-1],C
 ELSE
  GLINE LX[0],LY[0],LX[_POINTS-1],LY[_POINTS-1],C
 ENDIF
END

DEF FILL_SINES
 DIM I
 FOR I=.TO _POINTS-1
  SIN#[I]=SIN(PI()*2*I/_POINTS)
  COS#[I]=COS(PI()*2*I/_POINTS)
 NEXT I
END
ELLIPSE OriginX, OriginY, RadiusX, RadiusY, Fill Condition (TRUE=fill, FALSE=no fill), Color Code Without fill, it draws any given ellipse in 1/3 of a millisecond on average (the size of the ellipse has little impact on the computational time because the amount of points [resolution] is fixed). With fill, it's about 1 millisecond. Outperforms the generic ellipse drawing function by a factor of over 3.

Damn! good job!

Replying to:DFrost
Damn! good job!
Thanks, but there's actually an even faster method lol

Replying to:DFrost
Damn! good job!
It's a trade off of quality for performance