=== Top of the Swiki === Attachments ===

WorldsSmallestDrawingProgram

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

Purpose:

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. :-)

--MarkGuzdial


(Changed to use #place: instead of #up;#goto:;#down and to increase cascading -- BillTrost)