Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
World's smallest drawing program
Last updated at 10:03 pm UTC on 31 March 2017

2006

With no cascading:

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

Version with cascading:

| myPen | myPen := Pen new defaultNib: 2; place: How Morphic processes events mousePoint. [Sensor waitButton ; yellowButtonPressed] whileFalse: [Sensor redButtonPressed ifTrue: [myPen goto: Sensor mousePoint]].
Another version:
| myPen | myPen := Pen new defaultNib: 2. myPen up; goto: Sensor mousePoint; down. [Sensor waitButton ; yellowButtonPressed] whileFalse: [Sensor redButtonPressed ifTrue: [myPen goto: Sensor mousePoint]].


Ward's 3d Version:

nib := Form fromUser.
100000 timesRepeat: [nib displayAt: Sensor cursorPoint]

I use to do this as a demo all the time. I would type each line and doit, explaining as I typed. To draw in 3d I would grab a tall skinny form that was all white except for a little black bit at the top. Then I would gracefully wave this back and forth so as to paint a surface with hidden-line elimination due to the white tail on the nib. – WardCunningham

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 How Morphic processes events, 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

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


see also World's smallest drawing program, Yellow button and Blue button