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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10682
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Code: GLBasic [Select]

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
 
« Last Edit: 2010-Feb-11 by Kitty Hello »

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5006
  • O Rly?
    • View Profile
(Softly) Moving from Point A to Point B
« Reply #1 on: 2008-Jan-08 »
Great stuff !
I <3 DGArray's :D

PC:
AMD RYzen 7 1700 @3.9Ghz, 16GB HyperX Fury 2666Mhz Ram, ASUS ROG GTX 1060 STRIX 6GB, Windows 10 Pro 64Bit, MSi Tomahawk B350 Mainboard

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2580
    • View Profile
(Softly) Moving from Point A to Point B
« Reply #2 on: 2008-Jan-08 »
Yep, very interesting! :D
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)

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
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.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10682
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
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.

Offline FutureCow

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

Offline Wampus

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

Offline monono

  • Mr. Polyvector
  • ***
  • Posts: 213
    • View Profile
    • Sockel Lernmedien
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 »