logo animation

// do the landscape background using landscape1 procedure..
set horizon = 400
include landscape1
landscape1 :horizon 5 120


message "Cruiser" "Slow|Fast|Reverse|Done"

set waitamount = 10
set direction = "forward"
set toggle = 0

// generate the perspective point pairs in advance..
set yofs = 0
set linelen = 2
set ydelta = 1.2
set lendelta = 2
pointlist startcapture
pu
repeat 80 [
    set vertpos = calc :horizon - :yofs
    set leftside = calc center - :linelen
    set rightside = calc center + :linelen
    pu; moveto :leftside :vertpos; 
    pd; moveto :rightside :vertpos  
    pu
  
    // increment the vertical position and length of the cross lines..
    // we also gradually increase the increment the delta amounts to give
    // a non-linear perspective spacing of the cross lines..
    incr yofs by :ydelta
    incr linelen by :lendelta
    set ydelta = calc :ydelta * 1.05
    set lendelta = calc :lendelta * 1.05
    ]
pointlist endcapture   
set npts = pointlist size // always 160  (80 left & right point pairs)

logo linethick = 0.5



// begin the animation..

set toggle = 0
repeat untilbreak [   // this loop runs once per animation "frame"...

  // handle user buttons...
  if keypress = 1 [ 
    if whichkey = "Done" [ break ]
    else [
      if whichkey = "Fast" [ set waitamount = 0 ]
      elseif whichkey = "Slow" [ set waitamount = 10 ]
      elseif whichkey = "Reverse" [
        if :direction = "forward" [ set direction = "backward" ]
	else [ set direction = "forward" ]
        ]
      samemessage
      ]
    ]

  set icolor = 1
  repeat 4 [  // loop runs once for each of the four colors...
	      // this approach minimizes the # of color changes
    if :icolor = 1 [ logo linecolor = "orange" ]
    elseif :icolor = 2 [ logo linecolor = "red" ]
    elseif :icolor = 3 [ logo linecolor = "lightpurple" ]
    else [ logo linecolor = "black" ]
    
    set ipt = calc (calc :icolor * 2) + (calc :toggle * 2)
    decr ipt by 1
    repeat 20 [  // loop runs once for each crossline & pole pair..
      set leftside = pointx :ipt
      set vertpos = pointy :ipt
      // printf "%s %s %s" linecolor :ipt (calc :ipt + 1)
      incr ipt by 1
      set rightside = pointx :ipt
      set polehi = calc (calc :rightside - :leftside) * 0.1
    
      // draw the stuff...
      pu; moveto :leftside :vertpos; pd
      if :icolor = 1 or :icolor = 4 [ 
        moveto :leftside (calc :vertpos + :polehi) // left pole..
        pu; moveto :leftside :vertpos; pd          // go back..
        ]
      moveto :rightside :vertpos            // do the cross line..
      if :icolor = 1 or :icolor = 4 [ 
        moveto :rightside (calc :vertpos + :polehi)  // and the right pole..
        ]
      pu
  
      incr ipt by 7  // jump ahead to next point for this color..
      if :ipt >= :npts [ break ]
      ]

    incr icolor by 1
    ]


  // increment the toggle that controls color "movement"..
  if :direction = "forward" [
    incr toggle by 1
    if :toggle >= 4 [ set toggle = 0 ]
    ]
  else [
    decr toggle by 1
    if :toggle < 0 [ set toggle = 3 ]
    ]

  // delay amount..
  if :waitamount > 0 [ wait :waitamount ]

  ]
