// program to draw lines radiating out from where mouse
// was pressed.
// Written by Kim Bruce, 9/2014
dialect "od8"
import "random" as random

def Spirograph: GraphicApplication = object {
   inherit graphicApplicationSize (400 @ 400)
   
   // make background black
   filledRectAt (0 @ 0) size (canvas.size) on (canvas)
   
   // remember where the mouse was pressed
   var nextLineStarts: Point
   
   // color of line being drawn
   var lineColor: Color

   // when the mouse is pressed remember where mouse was
   // and randomly choose new color for lines
   method onMousePress (point: Point) -> Done {
      nextLineStarts := point
      def colorNumber: Number = random.integerIn (1) to (3)
      if (colorNumber == 1) then {
         lineColor := colorGen.red
      } elseif {colorNumber == 2} then {
         lineColor := colorGen.white
      } else {
         lineColor := colorGen.blue
      }
   }

   // Draw a new colored line from where mouse was pressed to current
   // location when mouse is dragged.
   method onMouseDrag (point: Point) -> Done {
      def newLine: Line = lineFrom (nextLineStarts) to (point) on (canvas)
      newLine.color := lineColor
   }

   startGraphics

}