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

Discussion 4 - Ryan Nigro

I chose to answer a Midterm Review Question off of Summer 2001 Midterm Review. In the "Write Smalltalk Code" question, you're asked to draw two boxes with CS2340 written inside. My code is as follows.

'CS2340' displayAt: 110 @ 380. "The easy part: draw out the string"
myPen := Pen new. "Instantiate the pen"
myPen up. "Put the pen up, move it where it should be, and orient it."
myPen goto: 100 @ 400.
myPen north.
myPen down. "Put the pen down and draw the inner box"
1 to: 2 do: [:index | myPen go: 25.
myPen turn: 90.
myPen go: 52.
myPen turn: 90.].
myPen up. "Put the pen up, move to outer box location, and orient"
myPen goto: 90 @ 410.
myPen north.
myPen down. "Put the pen down and draw the outer box"
1 to: 2 do: [:index | myPen go: 45.
myPen turn: 90.
myPen go: 72.
myPen turn: 90.]."Done!"

This code gets the job done, but the centering of text and boxes is done by hand. There might be a cleaner way to center text than trial and error, but this is easy and works.

Link to this Page