{
   "labels" : [
      "gui",
      "art",
      "paint",
      "drawing",
      "sketch",
      "doodle",
      "color",
      "rgb",
      "environment"
   ],
   "code" : "//LET'S PAINT!\r\n//select all and compile\r\n\r\nvar point, red, green, blue, win, view, colorTask;\r\nvar redChange, greenChange, blueChange;\r\n\r\n//rate of change of each color component\r\n//mess around with these values for fun\r\n//zero results in no color change\r\nredChange = 0.01;\r\ngreenChange = 0.015;\r\nblueChange = 0.02;\r\n\r\n//default starting RGB values\r\n//these values can be changed as well\r\n//maintain range of 0≤x≤1\r\nred=0; green=0.33; blue=0.67;\r\n\r\n//window creation\r\nwin = Window(\"FANCY ARTWORK\", resizable:true, border:false);\r\nwin.fullScreen;\r\nwin.onClose = {\r\n\tif( \r\n\t\tcolorTask.isPlaying,\r\n\t\t{colorTask.stop},\r\n\t\t{}\r\n\t);\r\n};\r\n\r\n//userview creation\r\nview = UserView(win, Window.screenBounds);\r\nview.clearOnRefresh = false;\r\nview.background = Color.white;\r\n\r\n//any click sets point as current mouse location\r\n//left-click does nothing special\r\n//right-click clears palette\r\nview.mouseDownAction = {\r\n\t|v, x, y, mod, butNum, clkCnt|\r\n\tpoint = [x,y];\r\n\tif(butNum == 1,\r\n\t\t{\r\n\t\t\tview.drawFunc_({nil});\r\n\t\t\tview.clearDrawing;\r\n\t\t\tview.refresh},{}\r\n\t);\r\n};\r\n\r\n//mouse drag redefines userview drawFunc\r\n//Pen draws line from old point to current point\r\n//then sets old point equal to current point\r\nview.mouseMoveAction = {\r\n\t|v, x, y, mod|\r\n\tview.drawFunc = {\r\n\t\tPen.strokeColor = Color.new(\r\n\t\t\tred.fold(0,1),\r\n\t\t\tgreen.fold(0,1),\r\n\t\t\tblue.fold(0,1)\r\n\t\t);\r\n\t\tPen.width = 3;\r\n\t\tPen.line(point.asPoint,x@y);\r\n\t\tpoint = [x,y];\r\n\t\tPen.stroke;\r\n\t\t};\r\n\twin.refresh;\r\n};\r\n\r\n//RGB values wrap through range 0≤x<2\r\n//and are folded into 0≤x≤1 via mouseMove function\r\n//thus RGB values oscillate linearly, out of phase with\r\n//one another, back and forth from 0 to 1\r\ncolorTask = Task({\r\n\t{\r\n\t\tred = (red + redChange)%2;\r\n\t\tgreen = (green + greenChange)%2;\r\n\t\tblue = (blue + blueChange)%2;\r\n\t\t0.05.wait; //arbitrary wait time\r\n\t}.loop;\r\n});\r\n\r\n//comment out for no color change\r\ncolorTask.start;\r\n\r\nwin.front;",
   "is_private" : null,
   "id" : "1-Y",
   "author" : "eli.fieldsteel",
   "name" : "Sketch Pad",
   "description" : "An environment in which the user can draw using the mouse.",
   "ancestor_list" : []
}
