0

Smalltalk: Draw Circle using the Pen

Introduction

In this post, I am showing how to use Squeak Small talk to draw a circle on the screen using a Pen object and math functions. Not only it shows you how to draw a circle, but it also shows how to create a basic window and set it up for drawing functionality.

Source Code

Here is code to draw a circle using Pen.

"Create Window"
window := SystemWindow new.
window setLabel:'New Window'.
pasteUpMorph := PasteUpMorph new.
window addMorph: pasteUpMorph frame: (0@0 corner: 1@1).
window openInWorld.

"Create ImageMorph"
myImageMorph := ImageMorph new.
pasteUpMorph addMorph: myImageMorph.
myImageMorph newForm: (Form extent: (pasteUpMorph extent) depth: 32).
myImageMorph bounds: (pasteUpMorph bounds).

"Create Pen and use it to draw on ImageMorph"
myPen := Pen newOnForm: myImageMorph image.
myPen squareNib: 3.
myPen color: Color blue.

x := 0.0.
y := 0.0.
th := 0.0.

1 to: 200 do: [:i |
th := i * (3.14 / 100).
x := th sin * 100 + 200.
y := th cos * 100 + 200.
myPen place: x@y.
myPen go: 0@0.
].

Result

And, here is theΒ screenshot of code from Squeak.

humayun