Animation question

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

Animation question

Jim O'Brien
I am having difficulty getting the following example to work using either delay or step:

aMorph := Morph new.
aMorph position: (100@100).
aMorph openInWorld.
30 timesRepeat: [aMorph position: aMorph position +(1@0). Transcript show: 'test '; cr.].
(aMorph position) >= (120@100) ifTrue: [aMorph color: Color yellow].
Transcript show: 'position: ', aMorph position; cr.

For example:

aMorph := Morph new.
aMorph position: (100@100).
aMorph openInWorld.
delay := Delay forMilliseconds: 20.
[30 timesRepeat: [aMorph position: aMorph position +(1@0). delay wait.].] fork.
(aMorph position) >= (110@100) ifTrue: [aMorph color: Color yellow].
Transcript show: 'position: ', aMorph position; cr.

In the first example the morph moves, changes color, and the Transcript shows its final position. However, in the second example the morph moves but does not change color and the Transcript shows its starting position.

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

Re: Animation question

Bert Freudenberg
On Thu, Oct 12, 2017 at 6:24 PM, obrienj <[hidden email]> wrote:
I am having difficulty getting the following example to work using either delay or step:

aMorph := Morph new.
aMorph position: (100@100).
aMorph openInWorld.
30 timesRepeat: [aMorph position: aMorph position +(1@0). Transcript show: 'test '; cr.].
(aMorph position) >= (120@100) ifTrue: [aMorph color: Color yellow].
Transcript show: 'position: ', aMorph position; cr.

For example:

aMorph := Morph new.
aMorph position: (100@100).
aMorph openInWorld.
delay := Delay forMilliseconds: 20.
[30 timesRepeat: [aMorph position: aMorph position +(1@0). delay wait.].] fork.
(aMorph position) >= (110@100) ifTrue: [aMorph color: Color yellow].
Transcript show: 'position: ', aMorph position; cr.

In the first example the morph moves, changes color, and the Transcript shows its final position. However, in the second example the morph moves but does not change color and the Transcript shows its starting position.


Morphic animation is based on stepping. That means, you don't move a Morph repeatedly in a loop, but Morphic tells your morph to update its position repeatedly.

You need to make your own Morph subclass and implement a "step" method. Whenever that method is called, it moves the morph by a little. For example, you could use an existing method called" translateBy:"

| aMorph |
aMorph := Morph new openInWorld. 
aMorph startStepping: #transformedBy: at: Time millisecondClockValue arguments: {MorphicTransform offset: -3 @ -3} stepTime: 200.

However, it's unlikely no existing method does your specific animation, so you indeed need to implement it, eg

step
    self position: self position + (1@0).
    (self position) >= (120@100) ifTrue: [self color: Color yellow].

So this is the Right Way. Without bad hacks you cannot do meaningful animation from a workspace. There is a hack however: If you insert "World doOneCycle" in the while loop of your first example, it will actually work, because it will redraw the world in each loop. However, this would prevent two objects animating independently, that's why the design calls for the "step" method approach.

- Bert -


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

Re: Animation question

Bert Freudenberg
No, you have to put that test in the step method, because it has to be checked every time the position changes.

Or you have to wait until the animation is done before doing the test - it does work in your first example with my "hack". It does not work in the second example because the forked code is executed after that test (plus forking is bad for this anyways).

- Bert -

On Thu, Oct 12, 2017 at 7:39 PM, obrienj <[hidden email]> wrote:
The problem is that I want use something like (self position) >= (120@100) ifTrue: [self color: Color yellow] outside of the step method. Even though the morph moves, it's position remains unchanged and the boolean tests false. Hope this makes sense.



-------- Original Message --------
Subject: Re: [Newbies] Animation question
Local Time: October 12, 2017 10:25 AM
UTC Time: October 12, 2017 5:25 PM
To: obrienj <[hidden email]>, A friendly place to get answers to even the most basic questions about Squeak. <[hidden email]>

On Thu, Oct 12, 2017 at 6:24 PM, obrienj <[hidden email]> wrote:
I am having difficulty getting the following example to work using either delay or step:

aMorph := Morph new.
aMorph position: (100@100).
aMorph openInWorld.
30 timesRepeat: [aMorph position: aMorph position +(1@0). Transcript show: 'test '; cr.].
(aMorph position) >= (120@100) ifTrue: [aMorph color: Color yellow].
Transcript show: 'position: ', aMorph position; cr.

For example:

aMorph := Morph new.
aMorph position: (100@100).
aMorph openInWorld.
delay := Delay forMilliseconds: 20.
[30 timesRepeat: [aMorph position: aMorph position +(1@0). delay wait.].] fork.
(aMorph position) >= (110@100) ifTrue: [aMorph color: Color yellow].
Transcript show: 'position: ', aMorph position; cr.

In the first example the morph moves, changes color, and the Transcript shows its final position. However, in the second example the morph moves but does not change color and the Transcript shows its starting position.

Morphic animation is based on stepping. That means, you don't move a Morph repeatedly in a loop, but Morphic tells your morph to update its position repeatedly.

You need to make your own Morph subclass and implement a "step" method. Whenever that method is called, it moves the morph by a little. For example, you could use an existing method called" translateBy:"

| aMorph |
aMorph := Morph new openInWorld. 
aMorph startStepping: #transformedBy: at: Time millisecondClockValue arguments: {MorphicTransform offset: -3 @ -3} stepTime: 200.

However, it's unlikely no existing method does your specific animation, so you indeed need to implement it, eg

step
    self position: self position + (1@0).
    (self position) >= (120@100) ifTrue: [self color: Color yellow].

So this is the Right Way. Without bad hacks you cannot do meaningful animation from a workspace. There is a hack however: If you insert "World doOneCycle" in the while loop of your first example, it will actually work, because it will redraw the world in each loop. However, this would prevent two objects animating independently, that's why the design calls for the "step" method approach.

- Bert -




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

Re: Animation question

LawsonEnglish
In reply to this post by Bert Freudenberg



Because of garbage collection issues, smooth animation in Squeak isn’t really possible.

My little OpenGL spaceship firing a missile animation had this annoying pause every so-often, as the GC activated and froze the screen.

Was hoping that Craig Latta would release a minimal Spoon image that allowed me to load the OpenGL plugin code, because the GC in the minimal image took about 1/50th (or less) of the time that the complete image takes, but he got sidetracked with his Caffeine project.

Lawson

"Debugging is twice as hard as writing the code in the first place.

Therefore, if you write the code as cleverly as possible, you are,

by definition, not smart enough to debug it."

-Brian Kernighan




On Oct 12, 2017, at 11:18, Bert Freudenberg <[hidden email]> wrote:

No, you have to put that test in the step method, because it has to be checked every time the position changes.

Or you have to wait until the animation is done before doing the test - it does work in your first example with my "hack". It does not work in the second example because the forked code is executed after that test (plus forking is bad for this anyways).

- Bert -

On Thu, Oct 12, 2017 at 7:39 PM, obrienj <[hidden email]> wrote:
The problem is that I want use something like (self position) >= (120@100) ifTrue: [self color: Color yellow] outside of the step method. Even though the morph moves, it's position remains unchanged and the boolean tests false. Hope this makes sense.



-------- Original Message --------
Subject: Re: [Newbies] Animation question
Local Time: October 12, 2017 10:25 AM
UTC Time: October 12, 2017 5:25 PM
To: obrienj <[hidden email]>, A friendly place to get answers to even the most basic questions about Squeak. <[hidden email]>

On Thu, Oct 12, 2017 at 6:24 PM, obrienj <[hidden email]> wrote:
I am having difficulty getting the following example to work using either delay or step:

aMorph := Morph new.
aMorph position: (100@100).
aMorph openInWorld.
30 timesRepeat: [aMorph position: aMorph position +(1@0). Transcript show: 'test '; cr.].
(aMorph position) >= (120@100) ifTrue: [aMorph color: Color yellow].
Transcript show: 'position: ', aMorph position; cr.

For example:

aMorph := Morph new.
aMorph position: (100@100).
aMorph openInWorld.
delay := Delay forMilliseconds: 20.
[30 timesRepeat: [aMorph position: aMorph position +(1@0). delay wait.].] fork.
(aMorph position) >= (110@100) ifTrue: [aMorph color: Color yellow].
Transcript show: 'position: ', aMorph position; cr.

In the first example the morph moves, changes color, and the Transcript shows its final position. However, in the second example the morph moves but does not change color and the Transcript shows its starting position.

Morphic animation is based on stepping. That means, you don't move a Morph repeatedly in a loop, but Morphic tells your morph to update its position repeatedly.

You need to make your own Morph subclass and implement a "step" method. Whenever that method is called, it moves the morph by a little. For example, you could use an existing method called" translateBy:"

| aMorph |
aMorph := Morph new openInWorld. 
aMorph startStepping: #transformedBy: at: Time millisecondClockValue arguments: {MorphicTransform offset: -3 @ -3} stepTime: 200.

However, it's unlikely no existing method does your specific animation, so you indeed need to implement it, eg

step
    self position: self position + (1@0).
    (self position) >= (120@100) ifTrue: [self color: Color yellow].

So this is the Right Way. Without bad hacks you cannot do meaningful animation from a workspace. There is a hack however: If you insert "World doOneCycle" in the while loop of your first example, it will actually work, because it will redraw the world in each loop. However, this would prevent two objects animating independently, that's why the design calls for the "step" method approach.

- Bert -



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


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

Re: Animation question

cbc
Hi Lawson,

Actually smooth animation in Squeak is possible.  The best I've seen is at:
This is pure squeak/morphic, using stepping.

This isn't to say there aren't issue lurking about, of course.

-cbc

On Thu, Oct 12, 2017 at 3:41 PM, LEnglish <[hidden email]> wrote:



Because of garbage collection issues, smooth animation in Squeak isn’t really possible.

My little OpenGL spaceship firing a missile animation had this annoying pause every so-often, as the GC activated and froze the screen.

Was hoping that Craig Latta would release a minimal Spoon image that allowed me to load the OpenGL plugin code, because the GC in the minimal image took about 1/50th (or less) of the time that the complete image takes, but he got sidetracked with his Caffeine project.

Lawson

"Debugging is twice as hard as writing the code in the first place.

Therefore, if you write the code as cleverly as possible, you are,

by definition, not smart enough to debug it."

-Brian Kernighan




On Oct 12, 2017, at 11:18, Bert Freudenberg <[hidden email]> wrote:

No, you have to put that test in the step method, because it has to be checked every time the position changes.

Or you have to wait until the animation is done before doing the test - it does work in your first example with my "hack". It does not work in the second example because the forked code is executed after that test (plus forking is bad for this anyways).

- Bert -

On Thu, Oct 12, 2017 at 7:39 PM, obrienj <[hidden email]> wrote:
The problem is that I want use something like (self position) >= (120@100) ifTrue: [self color: Color yellow] outside of the step method. Even though the morph moves, it's position remains unchanged and the boolean tests false. Hope this makes sense.



-------- Original Message --------
Subject: Re: [Newbies] Animation question
Local Time: October 12, 2017 10:25 AM
UTC Time: October 12, 2017 5:25 PM
To: obrienj <[hidden email]>, A friendly place to get answers to even the most basic questions about Squeak. <[hidden email]>

On Thu, Oct 12, 2017 at 6:24 PM, obrienj <[hidden email]> wrote:
I am having difficulty getting the following example to work using either delay or step:

aMorph := Morph new.
aMorph position: (100@100).
aMorph openInWorld.
30 timesRepeat: [aMorph position: aMorph position +(1@0). Transcript show: 'test '; cr.].
(aMorph position) >= (120@100) ifTrue: [aMorph color: Color yellow].
Transcript show: 'position: ', aMorph position; cr.

For example:

aMorph := Morph new.
aMorph position: (100@100).
aMorph openInWorld.
delay := Delay forMilliseconds: 20.
[30 timesRepeat: [aMorph position: aMorph position +(1@0). delay wait.].] fork.
(aMorph position) >= (110@100) ifTrue: [aMorph color: Color yellow].
Transcript show: 'position: ', aMorph position; cr.

In the first example the morph moves, changes color, and the Transcript shows its final position. However, in the second example the morph moves but does not change color and the Transcript shows its starting position.

Morphic animation is based on stepping. That means, you don't move a Morph repeatedly in a loop, but Morphic tells your morph to update its position repeatedly.

You need to make your own Morph subclass and implement a "step" method. Whenever that method is called, it moves the morph by a little. For example, you could use an existing method called" translateBy:"

| aMorph |
aMorph := Morph new openInWorld. 
aMorph startStepping: #transformedBy: at: Time millisecondClockValue arguments: {MorphicTransform offset: -3 @ -3} stepTime: 200.

However, it's unlikely no existing method does your specific animation, so you indeed need to implement it, eg

step
    self position: self position + (1@0).
    (self position) >= (120@100) ifTrue: [self color: Color yellow].

So this is the Right Way. Without bad hacks you cannot do meaningful animation from a workspace. There is a hack however: If you insert "World doOneCycle" in the while loop of your first example, it will actually work, because it will redraw the world in each loop. However, this would prevent two objects animating independently, that's why the design calls for the "step" method approach.

- Bert -



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


_______________________________________________
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: Animation question

LawsonEnglish
In reply to this post by LawsonEnglish

LEnglish


Unfortunately, can’t run that without windows, if I read the title correctly (“for windows”)

Also, I was using OpenGL, which might have complicated things.

Thanks for the link. I’ll try to figure out what they did differently than my experiment.

L

On Oct 12, 2017, at 16:09, Chris Cunningham <[hidden email]> wrote:

Hi Lawson,

Actually smooth animation in Squeak is possible.  The best I've seen is at:
This is pure squeak/morphic, using stepping.

This isn't to say there aren't issue lurking about, of course.

-cbc

On Thu, Oct 12, 2017 at 3:41 PM, LEnglish <[hidden email]> wrote:



Because of garbage collection issues, smooth animation in Squeak isn’t really possible.

My little OpenGL spaceship firing a missile animation had this annoying pause every so-often, as the GC activated and froze the screen.

Was hoping that Craig Latta would release a minimal Spoon image that allowed me to load the OpenGL plugin code, because the GC in the minimal image took about 1/50th (or less) of the time that the complete image takes, but he got sidetracked with his Caffeine project.

Lawson

"Debugging is twice as hard as writing the code in the first place.

Therefore, if you write the code as cleverly as possible, you are,

by definition, not smart enough to debug it."

-Brian Kernighan




On Oct 12, 2017, at 11:18, Bert Freudenberg <[hidden email]> wrote:

No, you have to put that test in the step method, because it has to be checked every time the position changes.

Or you have to wait until the animation is done before doing the test - it does work in your first example with my "hack". It does not work in the second example because the forked code is executed after that test (plus forking is bad for this anyways).

- Bert -

On Thu, Oct 12, 2017 at 7:39 PM, obrienj <[hidden email]> wrote:
The problem is that I want use something like (self position) >= (120@100) ifTrue: [self color: Color yellow] outside of the step method. Even though the morph moves, it's position remains unchanged and the boolean tests false. Hope this makes sense.



-------- Original Message --------
Subject: Re: [Newbies] Animation question
Local Time: October 12, 2017 10:25 AM
UTC Time: October 12, 2017 5:25 PM
To: obrienj <[hidden email]>, A friendly place to get answers to even the most basic questions about Squeak. <[hidden email]>

On Thu, Oct 12, 2017 at 6:24 PM, obrienj <[hidden email]> wrote:
I am having difficulty getting the following example to work using either delay or step:

aMorph := Morph new.
aMorph position: (100@100).
aMorph openInWorld.
30 timesRepeat: [aMorph position: aMorph position +(1@0). Transcript show: 'test '; cr.].
(aMorph position) >= (120@100) ifTrue: [aMorph color: Color yellow].
Transcript show: 'position: ', aMorph position; cr.

For example:

aMorph := Morph new.
aMorph position: (100@100).
aMorph openInWorld.
delay := Delay forMilliseconds: 20.
[30 timesRepeat: [aMorph position: aMorph position +(1@0). delay wait.].] fork.
(aMorph position) >= (110@100) ifTrue: [aMorph color: Color yellow].
Transcript show: 'position: ', aMorph position; cr.

In the first example the morph moves, changes color, and the Transcript shows its final position. However, in the second example the morph moves but does not change color and the Transcript shows its starting position.

Morphic animation is based on stepping. That means, you don't move a Morph repeatedly in a loop, but Morphic tells your morph to update its position repeatedly.

You need to make your own Morph subclass and implement a "step" method. Whenever that method is called, it moves the morph by a little. For example, you could use an existing method called" translateBy:"

| aMorph |
aMorph := Morph new openInWorld. 
aMorph startStepping: #transformedBy: at: Time millisecondClockValue arguments: {MorphicTransform offset: -3 @ -3} stepTime: 200.

However, it's unlikely no existing method does your specific animation, so you indeed need to implement it, eg

step
    self position: self position + (1@0).
    (self position) >= (120@100) ifTrue: [self color: Color yellow].

So this is the Right Way. Without bad hacks you cannot do meaningful animation from a workspace. There is a hack however: If you insert "World doOneCycle" in the while loop of your first example, it will actually work, because it will redraw the world in each loop. However, this would prevent two objects animating independently, that's why the design calls for the "step" method approach.

- Bert -



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


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


_______________________________________________
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: Animation question

marcel.taeumel
In reply to this post by LawsonEnglish
Hi Lawson,

smooth animation in Squeak is indeed possible. :) I use the Animation [1] package in Widgets [2] and Vivide [3] to improve UX with several (simple) effects (sorry for the GIF artifacts):


Am 13.10.2017 00:42:08 schrieb LEnglish <[hidden email]>:




Because of garbage collection issues, smooth animation in Squeak isn’t really possible.

My little OpenGL spaceship firing a missile animation had this annoying pause every so-often, as the GC activated and froze the screen.

Was hoping that Craig Latta would release a minimal Spoon image that allowed me to load the OpenGL plugin code, because the GC in the minimal image took about 1/50th (or less) of the time that the complete image takes, but he got sidetracked with his Caffeine project.

Lawson

"Debugging is twice as hard as writing the code in the first place.

Therefore, if you write the code as cleverly as possible, you are,

by definition, not smart enough to debug it."

-Brian Kernighan




On Oct 12, 2017, at 11:18, Bert Freudenberg <[hidden email]> wrote:

No, you have to put that test in the step method, because it has to be checked every time the position changes.

Or you have to wait until the animation is done before doing the test - it does work in your first example with my "hack". It does not work in the second example because the forked code is executed after that test (plus forking is bad for this anyways).

- Bert -

On Thu, Oct 12, 2017 at 7:39 PM, obrienj <[hidden email]> wrote:
The problem is that I want use something like (self position) >= (120@100) ifTrue: [self color: Color yellow] outside of the step method. Even though the morph moves, it's position remains unchanged and the boolean tests false. Hope this makes sense.



-------- Original Message --------
Subject: Re: [Newbies] Animation question
Local Time: October 12, 2017 10:25 AM
UTC Time: October 12, 2017 5:25 PM
To: obrienj <[hidden email]>, A friendly place to get answers to even the most basic questions about Squeak. <[hidden email]>

On Thu, Oct 12, 2017 at 6:24 PM, obrienj <[hidden email]> wrote:
I am having difficulty getting the following example to work using either delay or step:

aMorph := Morph new.
aMorph position: (100@100).
aMorph openInWorld.
30 timesRepeat: [aMorph position: aMorph position +(1@0). Transcript show: 'test '; cr.].
(aMorph position) >= (120@100) ifTrue: [aMorph color: Color yellow].
Transcript show: 'position: ', aMorph position; cr.

For example:

aMorph := Morph new.
aMorph position: (100@100).
aMorph openInWorld.
delay := Delay forMilliseconds: 20.
[30 timesRepeat: [aMorph position: aMorph position +(1@0). delay wait.].] fork.
(aMorph position) >= (110@100) ifTrue: [aMorph color: Color yellow].
Transcript show: 'position: ', aMorph position; cr.

In the first example the morph moves, changes color, and the Transcript shows its final position. However, in the second example the morph moves but does not change color and the Transcript shows its starting position.

Morphic animation is based on stepping. That means, you don't move a Morph repeatedly in a loop, but Morphic tells your morph to update its position repeatedly.

You need to make your own Morph subclass and implement a "step" method. Whenever that method is called, it moves the morph by a little. For example, you could use an existing method called" translateBy:"

| aMorph |
aMorph := Morph new openInWorld. 
aMorph startStepping: #transformedBy: at: Time millisecondClockValue arguments: {MorphicTransform offset: -3 @ -3} stepTime: 200.

However, it's unlikely no existing method does your specific animation, so you indeed need to implement it, eg

step
    self position: self position + (1@0).
    (self position) >= (120@100) ifTrue: [self color: Color yellow].

So this is the Right Way. Without bad hacks you cannot do meaningful animation from a workspace. There is a hack however: If you insert "World doOneCycle" in the while loop of your first example, it will actually work, because it will redraw the world in each loop. However, this would prevent two objects animating independently, that's why the design calls for the "step" method approach.

- Bert -



_______________________________________________
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: Animation question

Stephan Eggermont-3
In reply to this post by LawsonEnglish
On 13-10-17 00:41, LEnglish wrote:
> Because of garbage collection issues, smooth animation in Squeak isn’t really possible.

That shouldn't stop you as that problem will solve itself next year with
the incremental garbage collector.

Stephan

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