A Polyspiral is a spiral made of multiple line segments, whereby each segment is larger (or smaller) than the previous one by a given amount. Each segment also changes direction at a given angle.



Task
Animate a series of polyspirals, by drawing a complete spiral then incrementing the angle, and (after clearing the background) drawing the next, and so on. Every spiral will be a frame of the animation. The animation may stop as it goes full circle or continue indefinitely. The given input values may be varied.

If animation is not practical in your programming environment, you may show a single frame instead.



Pseudo code
    set incr to 0.0

    // animation loop
    WHILE true 

        incr = (incr + 0.05) MOD 360
        x = width / 2
        y = height / 2
        length = 5
        angle = incr

        // spiral loop
        FOR 1 TO 150
            drawline
            change direction by angle
            length = length + 3
            angle = (angle + incr) MOD 360
        ENDFOR
    



INCLUDE "H6:REALMATH.ACT"
 
INT ARRAY SinTab=[
  0 4 9 13 18 22 27 31 36 40 44 49 53 58 62 66 71 75 79 83
  88 92 96 100 104 108 112 116 120 124 128 132 136 139 143
  147 150 154 158 161 165 168 171 175 178 181 184 187 190
  193 196 199 202 204 207 210 212 215 217 219 222 224 226
  228 230 232 234 236 237 239 241 242 243 245 246 247 248
  249 250 251 252 253 254 254 255 255 255 256 256 256 256]
 
INT FUNC Sin(INT a)
  WHILE a<0 DO a==+360 OD
  WHILE a>360 DO a==-360 OD
  IF a<=90 THEN
    RETURN (SinTab(a))
  ELSEIF a<=180 THEN
    RETURN (SinTab(180-a))
  ELSEIF a<=270 THEN
    RETURN (-SinTab(a-180))
  ELSE
    RETURN (-SinTab(360-a))
  FI
RETURN (0)
 
INT FUNC Cos(INT a)
RETURN (Sin(a-90))
 
PROC DrawSpiral(INT x0,y0)
  INT i,angle,x,y,tmp
  REAL rx,ry,len,dlen,r1,r2,r3,r256
 
  IntToReal(x0,rx)
  IntToReal(y0,ry)
  ValR("1.9",len)
  ValR("1.14",dlen)
  IntToReal(256,r256)
  angle=0
  Plot(x0,y0)
  FOR i=1 TO 150
  DO
    tmp=Cos(angle)
    IntToRealForNeg(tmp,r1)
    RealDiv(r1,r256,r2)
    RealMult(r2,len,r1)
    RealAdd(rx,r1,r2)
    RealAssign(r2,rx)
 
    tmp=Sin(angle)
    IntToRealForNeg(tmp,r1)
    RealDiv(r1,r256,r2)
    RealMult(r2,len,r1)
    RealAdd(ry,r1,r2)
    RealAssign(r2,ry)
 
    x=RealToInt(rx)
    y=RealToInt(ry)
    DrawTo(x,y)
 
    RealAdd(len,dlen,r1)
    RealAssign(r1,len)
    angle==+123
    IF angle>360 THEN
      angle==-360
    FI
  OD
RETURN
 
PROC Main()
  BYTE CH=$02FC,COLOR1=$02C5,COLOR2=$02C6
 
  Graphics(8+16)
  Color=1
  COLOR1=$0C
  COLOR2=$02
 
  DrawSpiral(160,96)
 
  DO UNTIL CH#$FF OD
  CH=$FF
RETURN