View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Sum2001 Midterm Review: Write Smalltalk Code

This ain't pretty, and it's terribly long and repetative, but it works:
| pen |
pen _ Pen new.
pen up.
pen goto: 200@200.
pen north.
pen down.
pen go: 75.
pen turn: 90.
pen go: 150.
pen turn: 90.
pen go: 75.
pen turn: 90.
pen go: 150.
pen north.
pen up.
pen turn: 45.
pen go: 18.
pen north.
pen down.
pen go: 50.
pen turn: 90.
pen go: 100.
pen turn: 90.
pen go: 50.
pen turn: 90.
pen go: 100.
pen up.
'CS2340' displayAt: 220@150.

Looks pretty good, though the inner boxes aren't centered very well. Anyone (including "no loops") care to try for a version with a little less repetition? -Lex Spoon


how about this?
pen
pen := Pen new.
pen up.
pen place: 40@40.
pen north.
pen down.
1 to: 2 do:
[:item |
pen turn: 90.
pen go: 60.
pen turn: 90.
pen go: 40.
].

pen place: 45@45.
pen north.
1 to: 2 do:
[:item |
pen turn: 90.
pen go: 50.
pen turn: 90.
pen go: 30.
].

'CS2340' displayAt: 50@50

sdfdf



Link to this Page