[Newbies] Drawing a line on a morph

Christine Wolfe cwdw01 at earthlink.net
Fri Oct 30 15:52:26 UTC 2009


If anyone has followed the dice example in Chapter 11 of Squeak By Example
you will recognize that I'm trying to build a variation of the dice.  The
difference is that I am trying to draw figures on the faces instead of dots.

 

What I am trying to do is have a group (array, set, collection?) of "faces"
on a rectangle - sort of like a child's building block with an image on each
of the faces. I want 1 face to be blank, one to have a line, one to have a
diamond, and one to have a rectangle. In the dice example, they draw dots on
the faces but I think I can use the same logic to draw lines on the faces.

 

I've pasted what I tried to the end of this post but I'm open to other ways
to do it.  I can't even get a simple line to draw on the face of the
rectangle.  You can see that I tried to have the "face" methods send a pair
of points that define the ends of the line and have drawLineOn draw a line
between the points.  Any help or advice will be greatly appreciated.

 

In the dice example they use: 

 

BorderedMorph subclass: #DieMorph

                instanceVariableNames: 'faces dieValue isStopped'

                classVariableNames: ''

                poolDictionaries: ''

                category: 'SBEexamples'

 

and

 

drawOn: aCanvas

super drawOn: aCanvas.

(self perform: ('face', dieValue asString) asSymbol)

do: [:aPoint | self drawDotOn: aCanvas at: aPoint]

 

and

 

drawDotOn: aCanvas at: aPoint

aCanvas

fillOval: (Rectangle

center: self position + (self extent * aPoint)

extent: self extent / 6)

color: Color black.

 

and

 

face1

^{0.5 at 0.5}

 

And

 

face2

^{0.25 at 0.25 . 0.75 at 0.75}

 

I tried:

 

BorderedMorph subclass: #MyMorph

                instanceVariableNames: 'faces dieValue isStopped'

                classVariableNames: ''

                poolDictionaries: ''

                category: 'SBEexamples'

 

and

 

drawOn: aCanvas

super drawOn: aCanvas.

(self perform: ('face', dieValue asString) asSymbol)

do: [{:aPoint, anotherPoint} | self drawLineOn: aCanvas from: aPoint to:
anotherPoint]

 

and

 

drawLineOn: aCanvas from: aPoint to anotherPoint

aCanvas

line: aPoint to: anotherPoint width: 2 color: Color black.

 

and

 

face1

^{{2 at 2, 2 at 10}, {2 at 2, 10 at 2}, {10 at 10, 2 at 10}, {10 at 10, 10 at 2}}

 

And

 

face2

^{{5 at 5, 5 at 7}, {5 at 2, 7 at 2}, {7 at 7, 5 at 7}, {7 at 7, 7 at 5}}

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20091030/3251c477/attachment.htm


More information about the Beginners mailing list