How to put a delay between Morph movements/changes ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to put a delay between Morph movements/changes ?

Nicola Mingotti
Hi,

I would like a Morph to move and then wait a bit, move and wait a bit ... and so on. I can't get it.

For example, this code works as expected:
------------
1 to: 10 do: [:x |
    Transcript show: ('[{1} -- hello]' format: {x}); cr.
    (Delay forMilliseconds: 500) wait.
    ].
--------------

But once i try to put the Delay between a Morph changes it does not do what i want. That is, the morph does all the actions together at the end of the loop.

---------------------------
e := PolygonMorph new.
e openInWorld.
e position: 300@300.
e heading.
e forward: 50.

1 to: 10 do: [:x |
    e forward: 10.
    (Delay forMilliseconds: 500) wait.
    ].
---------------------

bye
Nicola






_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: How to put a delay between Morph movements/changes ?

K K Subbu
Nicola,

Morphic updates to Display are buffered, so you can't animate them
through delays. Morphic core already has built-in facilities to support
animation in an efficient way. There is an excellent tutorial by John
Maloney at:

 
http://sdmeta.gforge.inria.fr/FreeBooks/CollectiveNBlueBook/morphic.final.pdf

See the section on "Adding Liveness" (page 11) for the specifics.

HTH .. Subbu

On 24/10/19 5:03 AM, Nicola Mingotti wrote:

> Hi,
>
> I would like a Morph to move and then wait a bit, move and wait a bit
> ... and so on. I can't get it.
>
> For example, this code works as expected:
> ------------
> 1 to: 10 do: [:x |
>      Transcript show: ('[{1} -- hello]' format: {x}); cr.
>      (Delay forMilliseconds: 500) wait.
>      ].
> --------------
>
> But once i try to put the Delay between a Morph changes it does not do
> what i want. That is, the morph does all the actions together at the end
> of the loop.
>
> ---------------------------
> e := PolygonMorph new.
> e openInWorld.
> e position: 300@300.
> e heading.
> e forward: 50.
>
> 1 to: 10 do: [:x |
>      e forward: 10.
>      (Delay forMilliseconds: 500) wait.
>      ].
> ---------------------
>
> bye
> Nicola
>
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: How to put a delay between Morph movements/changes ?

Nicola Mingotti
Hi KK Subbu,

I own that book and luckily I red already that chapter. Anyhow it was a good recommendation;)

I am aware of the `step` method, that is not really what I want in this case. I am preparing a video tutorial, I need changes to be slow and the user to be able to modify stuff. Something feeling like Etoys, but in Smalltalk.

I discovered by accident that what i wanted is not difficult to achieve running this:
----------- for some reason it works -------------------
1 to: 10 do: [:x |
     e forward: 10.
     Transcript show: ('[{1} -- hello]' format: {x}); cr.
     (Delay forMilliseconds: 500) wait.
         ].
--------------------------------------------------------

Then after your suggestion I went to review that chapter in search for inspirations. And I remembered the `World` is just a `PasteUpMorph`, so I started to dig into the class and I found this method which I already read about somewhere else, probably "the white book": `doOneCycleNow`
-------- working, reasonable, easy to read --------------
1 to: 20 do: [:x |
     e forward: 10.
     World doOneCycleNow.
     (Delay forMilliseconds: 200) wait.
         ].
---------------------------------------------------------


Then I wrote this, but i don't think i will use it because it starts to be difficult to understand for new users.
----- better looping to not starve UI --------------
[1 to: 10 do: [:x |
     e forward: 10.
     World doOneCycleNow.
     (Delay forMilliseconds: 500) wait.
      ] ] fork.
-----------------------------------------------------


If you have other recommendations for improvement let me know.

bye
Nicola




On 10/23/19 10:46 PM, K K Subbu wrote:
Nicola,

Morphic updates to Display are buffered, so you can't animate them through delays. Morphic core already has built-in facilities to support animation in an efficient way. There is an excellent tutorial by John Maloney at:


http://sdmeta.gforge.inria.fr/FreeBooks/CollectiveNBlueBook/morphic.final.pdf

See the section on "Adding Liveness" (page 11) for the specifics.

HTH .. Subbu

On 24/10/19 5:03 AM, Nicola Mingotti wrote:
Hi,

I would like a Morph to move and then wait a bit, move and wait a bit ... and so on. I can't get it.

For example, this code works as expected:
------------
1 to: 10 do: [:x |
     Transcript show: ('[{1} -- hello]' format: {x}); cr.
     (Delay forMilliseconds: 500) wait.
     ].
--------------

But once i try to put the Delay between a Morph changes it does not do what i want. That is, the morph does all the actions together at the end of the loop.

---------------------------
e := PolygonMorph new.
e openInWorld.
e position: 300@300.
e heading.
e forward: 50.

1 to: 10 do: [:x |
     e forward: 10.
     (Delay forMilliseconds: 500) wait.
     ].
---------------------

bye
Nicola






_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners




_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners