antun
05-14-2004, 10:01 AM
A quick and easy way of doing there and back animation is to constrain the x-attribute of the view to a function of the squareroot of a value that gets animated.
This works because when a negative number is squared, it produces a positive number, so the -n to +n range is in effect an oscillator from 0 to n squared.
<canvas>
<view width="10" height="10" bgcolor="red"
x="${225 - ( this.sqrtx * this.sqrtx )}">
<attribute name="sqrtx" value="-15"/>
<animator attribute="sqrtx" from ="-15" to="15"
duration="3000" repeat="Infinity"/>
</view>
</canvas>
Enjoy!
This works because when a negative number is squared, it produces a positive number, so the -n to +n range is in effect an oscillator from 0 to n squared.
<canvas>
<view width="10" height="10" bgcolor="red"
x="${225 - ( this.sqrtx * this.sqrtx )}">
<attribute name="sqrtx" value="-15"/>
<animator attribute="sqrtx" from ="-15" to="15"
duration="3000" repeat="Infinity"/>
</view>
</canvas>
Enjoy!