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@0.5}
And
face2
^{0.25@0.25 . 0.75@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}}
On Friday 30 October 2009 09:22:26 pm Christine Wolfe wrote:
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.
How about: drawOn: aCanvas super drawOn: aCanvas. self perform: ('drawFace', dieValue asString) asSymbol with: aCanvas
drawFace1: aCanvas "leave blank"
drawFace2: aCanvas self drawLineOn: aCanvas from: self topLeft to: self bottomRight. .....
HTH .. Subbu
I tried it but the debugger says it doesn't understand drawFace1: I've double and triple checked and drawFace1: is there.
-----Original Message----- From: K. K. Subramaniam [mailto:subbukk@gmail.com] Sent: Friday, October 30, 2009 1:18 PM To: beginners@lists.squeakfoundation.org Cc: Christine Wolfe Subject: Re: [Newbies] Drawing a line on a morph
On Friday 30 October 2009 09:22:26 pm Christine Wolfe wrote:
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.
How about: drawOn: aCanvas super drawOn: aCanvas. self perform: ('drawFace', dieValue asString) asSymbol with: aCanvas
drawFace1: aCanvas "leave blank"
drawFace2: aCanvas self drawLineOn: aCanvas from: self topLeft to: self bottomRight. .....
HTH .. Subbu
On Friday 30 October 2009 11:41:23 pm Christine Wolfe wrote:
I tried it but the debugger says it doesn't understand drawFace1: I've double and triple checked and drawFace1: is there.
The drawFace1 selector needs a ':' at the end. My mistake. The corrected statement is: self perform: ('drawFace', dieValue asString, ':') asSymbol with: aCanvas
Sorry .. Subbu
On 30.10.2009, at 11:52, Christine Wolfe wrote:
drawOn: aCanvas super drawOn: aCanvas. (self perform: ('face', dieValue asString) asSymbol) do: [{:aPoint, anotherPoint} | self drawLineOn: aCanvas from: aPoint to: anotherPoint]
In my version of Squeak this won't even compile.
How did you accept that method?
The curly-bracket array notation can not be used to extract multiple arguments. Instead, you would have to do something like this:
[:aPointPair | self drawLineOn: aCanvas from: aPointPair first to: aPointPair second]
And secondly, this expression is valid syntactically but does not do what you might expect:
face1 ^{{2@2, 2@10}, {2@2, 10@2}, {10@10, 2@10}, {10@10, 10@2}}
In non-literal Array notation, expressions must be separated by periods, not commas:
{{2@2. 2@10}. {2@2. 10@2}. {10@10, 2@10}. {10@10. 10@2}}
The way you would verify a line like this or your's above is you simply select it and press cmd-p so it will print the result. You can do this in any browser or workspace.
- Bert -
Thank you so much for the information about the . instead of , and for the aPointPair first to aPointPair last. They look like they are going to be a big help.
When I made the changes, I received the following error message with either of the workspace instructions shown below. MyMorph(Object)>>doesNotUnderstand: [] in MyMorph>>drawOn: {[:aPointPair | self drawLineOn: aCanvas from: aPointPair first to: aPo...]}
This is my current code: In Workspace I type: (MyMorph faces: 2) openInWorld Or MyMorph new openInWorld
My messages are:
initialize super initialize. "taken directly from SBE" self extent: 50@50. self useGradientFill; borderWidth: 2; useRoundedCorners. self setBorderStyle: #complexRaised. self fillStyle direction: self extent. self color: Color green. dieValue := 1. faces := 6. isStopped := false.
and
drawOn: aCanvas super drawOn: aCanvas. (self perform: ('face', dieValue asString) asSymbol) perform: [:aPointPair | self drawLineOn: aCanvas from: aPointPair first to: aPointPair second]
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 {{2@2. 2@10}. {2@2. 10@2}. {10@10. 2@10}. {10@10. 10@2}}
-----Original Message----- From: beginners-bounces@lists.squeakfoundation.org [mailto:beginners-bounces@lists.squeakfoundation.org] On Behalf Of Bert Freudenberg Sent: Friday, October 30, 2009 2:00 PM To: A friendly place to get answers to even the most basic questions about Squeak. Subject: Re: [Newbies] Drawing a line on a morph
On 30.10.2009, at 11:52, Christine Wolfe wrote:
drawOn: aCanvas super drawOn: aCanvas. (self perform: ('face', dieValue asString) asSymbol) do: [{:aPoint, anotherPoint} | self drawLineOn: aCanvas from: aPoint to: anotherPoint]
In my version of Squeak this won't even compile.
How did you accept that method?
The curly-bracket array notation can not be used to extract multiple arguments. Instead, you would have to do something like this:
[:aPointPair | self drawLineOn: aCanvas from: aPointPair first to: aPointPair second]
And secondly, this expression is valid syntactically but does not do what you might expect:
face1 ^{{2@2, 2@10}, {2@2, 10@2}, {10@10, 2@10}, {10@10, 10@2}}
In non-literal Array notation, expressions must be separated by periods, not commas:
{{2@2. 2@10}. {2@2. 10@2}. {10@10, 2@10}. {10@10. 10@2}}
The way you would verify a line like this or your's above is you simply select it and press cmd-p so it will print the result. You can do this in any browser or workspace.
- Bert -
_______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
beginners@lists.squeakfoundation.org