[Coco] Turtle Graphics

Mathieu Bouchard matju at artengine.ca
Fri Nov 8 05:49:50 EST 2013


Le 2013-11-08 à 01:15:00, mcnd96 at aol.com a écrit :

> I used to have both Color Logo and Super Logo.  The only real difference 
> with Super Logo that I knew of was the fact it could do decimal math so 
> you could create circles.  Color Logo was integer based so circles 
> looked like a figure with a bunch of sides.

In Bresenham's circle algorithm, you don't need decimal math, nor a 
square-root function, nor even multiplications & divisions :

'BY MATHIEU L BOUCHARD NOV 2013
TO CERCLE
   HT SETH 90 MAKE :X 128
   REPEAT 128 (
     MAKE :Y (:Y+1)
     MAKE :K (:K+:Y)
     MAKE :U :X
     WHILE :K>:X (
       MAKE :K (:K-:X)
       MAKE :X (:X-1)
     )
     SETX :X SETY (192-:Y)
     FD (:U-:X)
   )
END

this computes squares and square-roots incrementally. The trick is that 
successive results of 1+2+3+4+5+... make a square-like sequence : 1, 3, 6, 
10, 15, ... also follows the pattern (x*x+x)/2. This allows to find 
differences between consecutive points in the circle equation.

  ______________________________________________________________________
| Mathieu BOUCHARD ----- téléphone : +1.514.383.3801 ----- Montréal, QC


More information about the Coco mailing list