home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / NEWS / 554 / JUIN / ELLIPSE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-10-07  |  2KB  |  43 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 385 of 393
  3. From : Sean Palmer                         1:104/123.0          12 Jun 93  00:05
  4. To   : Wouter Goderis
  5. Subj : Circle 320x200x256
  6. ────────────────────────────────────────────────────────────────────────────────
  7. WG> does someone have a circle routine for the 320x200x256 mode.
  8. WG> I need one using the assembler...  (FAST) ( or isn't that
  9. WG> possible) I doesn't need to be very perfect, if it has the
  10. WG> shape of a circle, I'm satisfied.
  11. WG> Can someone give me some hints ?
  12.  
  13. Just noticed a big, slow circle routine being posted at you and thought
  14. you'd be more interested in this general-purpose ellipse routine... just
  15. call it with a and b both equal to the desired radius and it'll make a
  16. circle (with 1:1 aspect ratio)
  17.  
  18. LOTS faster than anything that uses SQRT()
  19.  
  20. I'm sure you can figure out how to make a PLOT() routine...}
  21.  
  22. procedure oval(xc,yc,a,b:integer);
  23. var x,y:integer;aa,aa2,bb,bb2,d,dx,dy:longint;
  24. begin
  25.  x:=0;y:=b;
  26.  aa:=longint(a)*a;aa2:=2*aa;
  27.  bb:=longint(b)*b;bb2:=2*bb;
  28.  d:=bb-aa*b+aa div 4;
  29.  dx:=0;dy:=aa2*b;
  30.  plot(xc,yc-y);plot(xc,yc+y);plot(xc-a,yc);plot(xc+a,yc);
  31.  
  32.  while(dx<dy)do begin
  33.   if(d>0)then begin dec(y); dec(dy,aa2); dec(d,dy); end;
  34.   inc(x); inc(dx,bb2); inc(d,bb+dx);
  35.   plot(xc+x,yc+y); plot(xc-x,yc+y); plot(xc+x,yc-y); plot(xc-x,yc-y);
  36.   end;
  37.  inc(d,(3*(aa-bb)div 2-(dx+dy))div 2);
  38.  while(y>0)do begin
  39.   if(d<0)then begin inc(x); inc(dx,bb2); inc(d,bb+dx); end;
  40.   dec(y); dec(dy,aa2); inc(d,aa-dy);
  41.   plot(xc+x,yc+y); plot(xc-x,yc+y); plot(xc+x,yc-y); plot(xc-x,yc-y);
  42.   end;
  43.  end;