'From Squeak2.8alpha of 19 January 2000 [latest update: #1899] on 17 March 2000 at 6:44:09 pm'!
IconicButton subclass: #MyIconicButton
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Morphic Documentation example'!
!MyIconicButton methodsFor: 'as yet unclassified' stamp: 'jlb 3/15/2000 04:50'!
mouseDown: evt
| p1 p2 p3 s pa pb k delay |
" do what we're supposed to do first "
super mouseDown: evt.
" We're going to drive ourselves around a little arc,
then come back. We put in a little delay so that we
can see our little friend on fast machines. Also, we
randomize the delay so it looks kind of herky jerky.
Just a little fun stuff "
" Prepare an arc for our friend to follow "
p1 _ bounds origin.
p2 _ bounds origin + ( 400 @ 0 ).
p3 _ bounds origin + ( 200 @ 200).
" Here's the Path we're going to travel "
s _ Path new.
s add: p1.
pa _ p2 - p1.
pb _ p3 - p2.
" Now some horrible math bits to figure out the points on the arc "
k _ 5 max: pa x abs + pa y abs + pb x abs + pb y abs // 20.
"k is a guess as to how many line segments to use to approximate
the curve."
1 to: k do:
[:i |
s add: pa * i // k + p1 * (k - i) + (pb * (i - 1) // k + p2 * (i - 1)) //
(k - 1)].
s add: p3.
1 to: ( s size - 1 ) do: [ :j | delay _ Delay forMilliseconds: ( 10 to:
50) atRandom.
" Move to the place on the arc that we want to display at"
self position: ( s at: j ).
" make sure that we display ourselves "
self refreshWorld.
" and wait for some amount of time "
delay wait.
].
" Now it's time to go back "
( s size - 1 ) to: 1 by: -1 do: [ :j |
delay _ Delay forMilliseconds: ( 10 to: 30 ) atRandom.
self position: ( s at: j ).
self refreshWorld.
delay wait.
].
! !