//
// Scribble program
// 
// When press mouse and drag, draw lines segments from each point to next,
// giving impression of a smooth scribble.  Each new scribble is given a
// randomly chosen color
// 
// @author Kim Bruce
//

dialect "rtobjectdraw"

def scribble: GraphicApplication = object {
   inherit graphicApplicationSize (400 @ 400)

   // beginning point for next line
   var nextLineStarts: Point

   var currentColor: Color

   // Choose color randomly for next line and remember start
   method onMousePress (point: Point) -> Done {
      nextLineStarts := point
      currentColor := colorGen.random
   }

   // Draw lines to follow mouse
   method onMouseDrag(pt: Point) -> Done {
      def segment: Line = lineFrom (nextLineStarts) to (pt) on (canvas)
      segment.color := currentColor

      nextLineStarts := pt
   }

   // required to pop up window and start graphics
   startGraphics
}