LIMITFPS -1
LOCAL x_start =0
LOCAL x_end = 400
remake:
LOCAL tstart = GETTIMERALL()
LOCAL duration = 2000 // [ms]
WHILE TRUE
DRAWRECT x_start,0,4,100,0xffffff
DRAWRECT x_end,0,4,100,0xffffff
// find a position of the left to right movement
// in the range [0.0 ... 1.0]
LOCAL pos = (GETTIMERALL()-tstart) / duration
IF pos > 1.0 THEN BREAK // ok, reached the end
// move at linear speed
LOCAL x
x = x_start + pos * (x_end-x_start)
PRINT "Linear", x, 0
// accelerating
x = x_start + SIN(pos*90) * (x_end-x_start)
PRINT "sin", x, 30
// decelerating
x = x_start + (1.0-COS(pos*90)) * (x_end-x_start)
PRINT "cos", x, 60
// accellerating and decelerating
x = x_start - (COS(pos*180)-1)/2 * (x_end-x_start)
PRINT "sin", x, 90
SHOWSCREEN
WEND
KEYWAIT
GOTO remake
Great stuff !
Yep, very interesting! :D
Anyone have this code? I want to compare it to my solution.
OK, I rewrote it quickly. Sorry, the lots of text for that tutorial is gone, but I think you get the idea.
Thanks Gernot!
Good stuff
Another two:
//bouncing
IF pos < 0.363636
x= (x_end) * (7.5625 * pos * pos ) + x_start
ELSEIF pos < 0.727273
pos = pos - 0.545455
x= (x_end) * (7.5625 *pos * pos + .75) + x_start
ELSEIF pos < 0.909091
pos = pos - 0.818182
x= (x_end) * (7.5625 * pos *pos + .9375) + x_start
ELSE
pos = pos - 0.954545
x= (x_end) * (7.5625 * pos * pos + .984375) +x_start
ENDIF
PRINT "bounce", x, 120
// elastic
IF pos*duration = 0
x = x_start + x_end -x_start
ELSE
p = duration * 0.3
s = p / 4
tt = -10 * (pos)
pp = (((pos * duration - s) * (2 * 3.14159) / p ) * 180.0) / 3.14159
x = (x_end) * (POW(2,tt)) * SIN( pp ) + x_start + x_end-x_start
ENDIF
PRINT "elastic", x, 150
I found that in a freebasic forum. Sadly I lost the link. There was more movement smoothing math.