// 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 lines being drawn
   var lineColor: Color

   // when the mouse is pressed remember where mouse was
   // and choose new color for lines
   method onMousePress (point: Point) -> Done {
      nextLineStarts := point
      def colorNumber: Number = random.integerIn (1) to (3)
      match (colorNumber) 
         case {1 -> lineColor := colorGen.red}
         case {2 -> lineColor := colorGen.white}
         case {3 -> 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

}