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(a)0.5}
And
face2
^{0.25(a)0.25 . 0.75(a)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@2, 2@10}, {2@2, 10@2}, {10@10, 2@10}, {10@10, 10@2}}
And
face2
^{{5@5, 5@7}, {5@2, 7@2}, {7@7, 5@7}, {7@7, 7@5}}