Search code examples
smalltalkpharomorphic

Iterating through Diameter of a Circle Morph


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?


Solution

  • 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 ]