### Author Topic: (Softly) Moving from Point A to Point B  (Read 6146 times)

#### Kitty Hello

• code monkey
• Prof. Inline
• Posts: 10741
• here on my island the sea says 'hello'
##### (Softly) Moving from Point A to Point B
« on: 2008-Jan-08 »
Code: (glbasic) [Select]
`LIMITFPS -1LOCAL x_start  =0LOCAL x_end    = 400remake: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 SHOWSCREENWENDKEYWAITGOTO remake`
« Last Edit: 2010-Feb-11 by Kitty Hello »

#### Schranz0r

• Prof. Inline
• Posts: 5060
• O Rly?
##### (Softly) Moving from Point A to Point B
« Reply #1 on: 2008-Jan-08 »
Great stuff !
I DGArray's

PC:
AMD Ryzen 7 1700 @3.9GHz, 16GB HyperX Fury 3000MHz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

#### bigsofty

• Community Developer
• Prof. Inline
• Posts: 2668
##### (Softly) Moving from Point A to Point B
« Reply #2 on: 2008-Jan-08 »
Yep, very interesting!
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

#### FutureCow

• HelpEditor
• Prof. Inline
• Posts: 680
##### Re: (Softly) Moving from Point A to Point B
« Reply #3 on: 2010-Feb-11 »
Anyone have this code? I want to compare it to my solution.

#### Kitty Hello

• code monkey
• Prof. Inline
• Posts: 10741
• here on my island the sea says 'hello'
##### Re: (Softly) Moving from Point A to Point B
« Reply #4 on: 2010-Feb-11 »
OK, I rewrote it quickly. Sorry, the lots of text for that tutorial is gone, but I think you get the idea.

#### FutureCow

• HelpEditor
• Prof. Inline
• Posts: 680
##### Re: (Softly) Moving from Point A to Point B
« Reply #5 on: 2010-Feb-11 »
Thanks Gernot!

#### Wampus

• Prof. Inline
• Posts: 1004
##### Re: (Softly) Moving from Point A to Point B
« Reply #6 on: 2010-Mar-11 »
Good stuff

#### monono

• Mr. Polyvector
• Posts: 213
##### Re: (Softly) Moving from Point A to Point B
« Reply #7 on: 2010-Mar-20 »
Another two:
Code: (glbasic) [Select]
`     //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.
« Last Edit: 2010-Mar-20 by monono »