[squeak-dev] ENC: How to draw a 2D line

Jakob Reschke jakob.reschke at student.hpi.de
Sat Jun 24 12:59:36 UTC 2017

Hi Lorenzo,

Are you familiar with browsing existing code in Squeak already? If
not, I advise you have a look at the Squeak by Example book:
It also contains a chapter on drawing your own morphs.

Otherwise you probably want to have a look at the classes Canvas and
Form. A Form contains pixels and a Canvas can be used to draw things
like points, lines, and other images to a graphical medium. A
FormCanvas (a subclass of Canvas) can be used to draw on a Form. To
display a Form in the world you can use an ImageMorph.

The following creates a 32-Bit Form of 200x200 pixels, draws two lines
on it and attaches the image to the mouse cursor (hand).

form := Form extent: 200 at 200 depth: 32.
canvas := FormCanvas on: form.
canvas line: 0 at 0 to: 200 at 200 color: Color red.
canvas line: 200 at 0 to: 0 at 200 color: Color blue.
morph := ImageMorph new.
morph image: form.
morph openInHand.

You can then draw further stuff with the canvas and the morph will be
updated accordingly.

Does this help you?

Best regards,

2017-06-23 22:43 GMT+02:00 Lorenzo Berendsen <lorenzoberendsen at hotmail.com>:
> Hi All,
> I am trying to draw a simples 2D Line in months.
> I can’t understand what to do.
> Could someone help me with this?
> I have C, Pascal, VBA background, but none of these knowledge is helping me…
> Regards,
> Lorenzo.

More information about the Squeak-dev mailing list