Reputation: 303
I have a CircleMorph
and I want to extend its diameter, possibly to create a small animation with it.
b := CircleMorph new.
b color: Color transparent.
b borderWidth: 2.
b extent:100 @ 100.
b openInWorld.
Would it be good if I used a loop or the step
method to do this? If you recommend the step
method, then how do I do that?
Upvotes: 3
Views: 401
Reputation: 1142
You might make a subclass of CircleMorph
called GrowingCircleMorph
.
Then implement step
:
step
self extent: (self extent) + 1.
(self extent) > (200@200) ifTrue: [ self stopStepping ]
Now if you open an instance of your new GrowingCircleMorph in the World it will start growing up to 201@201.
To change the speed, implement stepTime
and return the desired time between steps in milliseconds.
update: if you want the center to stay the same, change the bounds of your circle morph, not the extent:
step
self bounds: ((self bounds) expandBy: 1).
(self extent) > (200@200) ifTrue: [ self stopStepping ]
Upvotes: 3
Reputation: 801
If you want to have fun with such things, make it generic:
HOCanvasMorph>>drawOn: aCanvas
super drawOn: aCanvas.
drawBlock ifNotNil: [
aCanvas
translateBy: self bounds origin
clippingTo: self bounds
during: [:canvas | drawBlock value: canvas]]
HOCanvasMorph>>drawBlock: aBlock
drawBlock := aBlock.
self changed.
HOCanvasMorph class>>example
|m|
m := HOCanvasMorph new openInWorld.
"to draw:"
m drawBlock: [:c |
c line: 10@10 to: 100@100 color: Color red
]
HOCanvasMorph class>>napperons
"Some mathematical fun"
| m |
m := HOCanvasMorph new openInWorld. "to draw:"
m
drawBlock: [ :aCanvas |
| n r t xa xc xb yc ya yb longueur nombreDeDroites |
longueur := 150.
nombreDeDroites := 30. "super drawOn: aCanvas."
xc := 200.
yc := 200.
n := 15.
r := 100.
0 to: n - 2 do: [ :i |
t := 2 * Float pi * i / n.
i + 1 to: n - 1 do: [ :j |
| tj |
tj := 2 * Float pi * j / n.
xa := xc + (r * t cos).
ya := yc + (r * t sin).
xb := xc + (r * tj cos).
yb := yc + (r * tj sin).
(aCanvas asBalloonCanvas) line: xa @ ya to: xb @ yb color: Color green ] ] ]
As the block can use about anything that changes, put those changes in a step method.
Upvotes: 0