s LearnSqueak.com

New to the language? Start with Smalltalk in Squeak, then return here.

SMALLTALK YOU CAN SEE

Your first
Morphic objects.

Draw a shape. Send it a message. Watch it change.

Morphic is Squeak’s live graphical world. Its shapes, labels, buttons, and windows are objects you can inspect and program. Build seven small examples, one at a time.

Beginner friendly7 runnable examples2 recorded demos
Six real Squeak objects: blue rectangle, orange ellipse, text label, green triangle, outlined rectangle, and a button
A real Squeak scene. You’ll build each of these objects below.

BEFORE YOU BEGIN

Open a Workspace. Make a Morph.

  1. Open Squeak and choose Tools → Workspace. You can also use the desktop’s World menu to open a Workspace.
  2. Copy one complete example into the Workspace, including its first line. Select that example’s text.
  3. Choose do it from the text pane’s context menu. The usual shortcut is Ctrl+D on Windows/Linux or Cmd+D on macOS.

Every example is independent. Run just one at a time, then remove its Morph before trying the next; the examples share starting coordinates and can overlap. These are Squeak examples, not browser JavaScript.

Squeak Workspace containing the complete blue rectangle example
100@100

A Point: x across, y down. The origin is the top-left of the Squeak world.

extent: 160@90

Width and height in pixels. Position sets the top-left of the Morph’s bounds.

color: Color blue

A message sent to an object. A semicolon sends the next message to the same receiver.

openInWorld

Adds the object to the visible world. Creating an object alone doesn’t display it.

The names between vertical bars, such as | m |, are temporary variables for that evaluation. The final m or stage returns the result; it does not keep a reference for the next do-it.

Try the finished example

Run in the SqueakJS playground

The separate playground loads the real Smalltalk image on demand. This lesson keeps its native setup instructions; browser compatibility notes appear beside each demo.

01

Morph

Your first rectangle

Start with the simplest visible object. A plain Morph draws a solid rectangle.

Smalltalk · Workspace
| m |
m := Morph new.
m color: Color blue;
    extent: 160@90;
    position: 100@100;
    openInWorld.
m
Download .st
SQUEAK CAPTURESCREENSHOT
Solid blue rectangular Morph
Rendered directly in Squeak 6.1.
Try itChange 160@90 to 90@160. What happens when you make both numbers equal?
02

EllipseMorph

A circle—or an ellipse

Use the same messages with a different class. Equal width and height give you a circle.

Smalltalk · Workspace
| m |
m := EllipseMorph new.
m color: Color orange;
    extent: 150@100;
    position: 100@100;
    openInWorld.
m
Download .st
SQUEAK CAPTURESCREENSHOT
Orange ellipse rendered by EllipseMorph
Rendered directly in Squeak 6.1.
Try itTry extent: 100@100 for a circle, then 200@60 for a wide ellipse.
03

BorderedMorph

Give a shape an outline

A border has its own width and color. RGB components here range from 0 to 1.

Smalltalk · Workspace
| m |
m := BorderedMorph new.
m color: (Color r: 0.83 g: 0.87 b: 1);
    borderWidth: 4;
    borderColor: Color blue;
    extent: 170@120;
    position: 100@100;
    openInWorld.
m
Download .st
SQUEAK CAPTURESCREENSHOT
Pale blue rectangle with a thick blue outline
Rendered directly in Squeak 6.1.
Try itTry borderWidth: 8 and borderColor: Color red.
04

PolygonMorph

Connect points into a triangle

Each point is a vertex. This three-vertex polygon closes the shape and fills its interior.

Smalltalk · Workspace
| m |
m := PolygonMorph
    vertices: {100@230. 250@230. 175@100}
    color: Color green
    borderWidth: 3
    borderColor: Color black.
m openInWorld.
m
Download .st
SQUEAK CAPTURESCREENSHOT
Green triangle with black outline
Rendered directly in Squeak 6.1.
Try itMove the top vertex from 175@100 to 210@80 to tilt the triangle.
05

StringMorph

Put words in your world

Text can be a Morph too. StringMorph is a lightweight, single-line label.

Smalltalk · Workspace
| m |
m := StringMorph contents: 'Hello, Morphic!'.
m color: (Color r: 0.1 g: 0.2 b: 0.45);
    position: 100@100;
    openInWorld.
m
Download .st
SQUEAK CAPTURESCREENSHOT
Blue Hello, Morphic! text label
Rendered directly in Squeak 6.1.
Try itChange the string inside the single quotes. Double an apostrophe inside a string.
06

SimpleButtonMorph

Make something happen

Build a small composition: a container, a colored swatch, and a button. Each click evaluates a block that chooses a new color.

Smalltalk · Workspace
| stage swatch button |
stage := Morph new color: Color white;
    extent: 360@210; position: 100@100; openInWorld.
swatch := Morph new color: Color blue;
    extent: 160@90; position: stage position + (25@25).
stage addMorph: swatch.
button := SimpleButtonMorph new
    label: 'Change color';
    target: [swatch color: Color random];
    actionSelector: #value;
    position: stage position + (25@145).
stage addMorph: button.
stage
Download .st
SQUEAK CAPTUREGIF DEMO
Squeak stage with blue swatch and Change color button
Three actual button clicks in Squeak. Stopping the demo restores the first frame.
Try itReplace Color random with Color orange for a predictable result.
07

A tiny custom class

Let a Morph take a step

Morphic calls step repeatedly while stepping is active. Our ball moves four pixels per step and reverses at the edges of its container.

This example installs a class named LearnSqueakBall in the LearnSqueak-Tutorial category. If Squeak asks for author initials, enter your own. Re-running it reuses that class. The other examples do not install classes.

Smalltalk · Workspace
| stage ball stop |
EllipseMorph subclass: #LearnSqueakBall
    instanceVariableNames: 'velocity'
    classVariableNames: ''
    poolDictionaries: ''
    category: 'LearnSqueak-Tutorial'.
(Smalltalk at: #LearnSqueakBall) compile: 'initialize
    super initialize.
    velocity := 4@0.
    self color: Color orange; extent: 40@40'.
(Smalltalk at: #LearnSqueakBall) compile: 'stepTime
    ^ 30'.
(Smalltalk at: #LearnSqueakBall) compile: 'step
    self owner ifNil: [^ self stopStepping].
    ((self right + velocity x > self owner right)
        or: [self left + velocity x < self owner left])
        ifTrue: [velocity := velocity negated].
    self position: self position + velocity'.
stage := Morph new color: (Color r: 0.95 g: 0.97 b: 1);
    extent: 420@180; position: 100@100; openInWorld.
ball := (Smalltalk at: #LearnSqueakBall) new
    position: stage position + (15@30).
stage addMorph: ball.
stop := SimpleButtonMorph new label: 'Stop animation';
    target: ball; actionSelector: #stopStepping;
    position: stage position + (15@120).
stage addMorph: stop.
ball startStepping.
stage
Download .st
SQUEAK CAPTUREGIF DEMO
Squeak stage with orange ball and Stop animation button
A real-time recording of Morphic stepping. Stopping the demo restores the first frame.
Try itChange the velocity to 2@0 for slower motion. stepTime returns milliseconds: 30 requests about 33 steps per second, not a guaranteed frame rate.

LEAVE YOUR WORLD TIDY

Stop, inspect, and clean up

Remove a Morph

Open its halo with Alt+click on Windows/Linux or Option+click on macOS (input mappings can vary). Click the red delete handle, often marked ×. For a composition, choose the outer container so its children go with it.

If those keys don’t bring up a halo, use Squeak’s configured blue-button/halo gesture. Don’t confuse the Morph’s halo with the operating-system window’s close button.

Stop the ball first

Click Stop animation inside Squeak, then delete the outer stage using its halo. This sends stopStepping to the ball. The web page’s demo control only stops its GIF.

The animation class remains in your image. If you want it removed too, open a Browser, find LearnSqueak-Tutorial → LearnSqueakBall, and remove that class after deleting its instances.

Prefer cleanup in code? Within the same evaluation, a reference can receive m delete. For a stepping Morph, use ball stopStepping; delete. A temporary variable from an earlier do-it is no longer available.

When something goes wrong

  • Nothing visible? Make sure you selected the whole example, used do it, and included openInWorld. Look behind existing windows.
  • A syntax error? Copy the whole block again. Keep single quotes, periods, semicolons, and vertical bars intact.
  • An unfamiliar message? Check your image version. These exact snippets were executed successfully in Squeak 6.1 build 23976.

Keep exploring

Open a Browser and inspect these classes and their methods. The image’s source is the best guide to the version you’re actually using.

All screenshots are genuine Squeak renders. The animated GIFs were assembled from frames captured in the running image, not browser simulations. Demos start only when you press Play. Historical wiki examples may differ from current Squeak APIs.