Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
SimplePaintingProgram
Last updated at 9:19 pm UTC on 2 May 2018
Worlds Smallest Drawing Program


 | myPen |
 myPen := Pen new defaultNib: 2.
 myPen up; goto: Sensor mousePoint; down.
 [Sensor waitButton ; yellowButtonPressed] whileFalse: 
 [Sensor redButtonPressed 
 ifTrue: [myPen goto: Sensor mousePoint]].

Purpose:r
Enter this into your workspace, then Do It. Now, whenever you click with your left (red) mouse button, a line will be drawn from the last place you clicked to your current mouse location. Click with your middle (yellow) mouse button to stop it. This draws directly to the display, so be sure to use Restore Display afterward to clean everything up. This Bon Mot uses a Pen class, which is basically a Logo turtle. It also uses Sensor, a global which accesses input from the user.

Why This is Interesting:

When you demonstrate this, be sure to draw over window boundaries, through scroll bars, and over title bars.

In my classes, when I do this for undergraduate and graduate students who have grown up with Microsoft Windows and the Apple Macintosh, their jaws drop. "But, you can't do that!" Suddenly, windows become software: You can draw on them, change them, do something different with them. That's scary. They tell me how inherently unreliable this is, to have windows that you can change. Yeah. Freedom is scary. :-)

Mark Guzdial