2

How would you implement Morph>>#moveTo:inSteps: in Pharo Smalltalk? Assume a hard-coded delay between steps. And don't necessarily worry about updating the World (i.e. say it will be forked in the background). I'm only concerned with the algorithm.

From https://stackoverflow.com/a/17906567/424245, I came up with:

Morph>>#moveTo: pointB inSteps: anInteger

    | deltaX deltaY |
    deltaX := (pointB x - self center x) / anInteger.
    deltaY := (pointB y - self center y) / anInteger.

    anInteger timesRepeat: [ 
        self align: self center with: self center + (deltaX @ deltaY).
        10 milliSeconds asDelay wait ].

But I'm wondering if there's something I'm missing in core that and reinventing the wheel...

Community
  • 1
  • 1
Sean DeNigris
  • 6,306
  • 1
  • 31
  • 37
  • Does your algorithm work? Also, does it freeze the UI when anInteger is large? – Lyn Headley Jan 11 '14 at 18:35
  • No, there was a missing $+, thanks. It's working now. Also, it does freeze the UI in that case, but note that I said to assume it would be running in the background. My question is more whether Pharo core includes API about moving along a linear path. – Sean DeNigris Jan 12 '14 at 19:21

0 Answers0