[Newbies] Bounce Example

summae3443 at mypacks.net summae3443 at mypacks.net
Fri Nov 21 00:16:42 UTC 2014

Many thanks to Bert, David, and Ron!

Bert wins the prize for being closest to what I saw.
This I can work with.

- Dan
-----Original Message-----
>From: Bert Freudenberg <bert at freudenbergs.de>
>Sent: Nov 20, 2014 9:52 AM
>To: "A friendly place to get answers to even the most basic questions about
>	Squeak." <beginners at lists.squeakfoundation.org>
>Subject: Re: [Newbies] Bounce Example
>
>On 20.11.2014, at 04:14, <summae3443 at mypacks.net> <summae3443 at mypacks.net> wrote:
>
>> Hello,
>>
>>
>> I once saw a workspace example which caused a morph to move along an arc in a realistic way - appearing to be affected by gravity. Possibly written by someone from Disney?  Now I search in vain to find it. Please give me a reference.
>
>Morphic is not really set up for workspace-style programming. It assumes you will create your own morph class and implement methods to specify behavior.
>
>It's certainly possible to do. But you will run into various problems that you wouldn't have if you did it properly.
>
>That said, try the following. Assuming constant mass and gravity, the acceleration is constant (since F = ma).
>
>m := Morph new openInWorld.
>m position: World center.
>speed := 5 @ 0.	"move horizontally at start"
>acceleration := 0 @ 1.	"accelerate downwards"
>move := [m owner ifNotNil: [
>	"Acceleration is a 2nd-order (quadratic) function. Physics and Math FTW"
>	speed := speed + acceleration.			"accel is 1st derivative of speed"
>	m position: m position + speed.		"speed is 1st derivative of pos"
>	m left < m owner left ifTrue: [speed := speed x abs @ speed y].		"bounce"
>	m right > m owner right ifTrue: [speed := speed x abs negated @ speed y].
>	m top < m owner top ifTrue: [speed := speed x @ speed y abs].
>	m bottom > m owner bottom ifTrue: [speed := speed x @ speed y abs negated].
>	(move future: 20) value.		"repeat every 20ms"
>]].
>move value.		"first step"
>
>For even more fun you could control the morph with a joystick:
>
>	j := JoystickMorph new openInWorld.
>
>And insert this inside the move block:
>
>	acceleration := (j leftRight @ j upDown negated) * 0.1.
>
>Have fun!
>
>- Bert -
>
>