News:

Function Finder  Find all the functions within source code files

Main Menu

Sinus Object Movement

Started by kevin, March 26, 2020, 08:35:58 PM

Previous topic - Next topic

kevin

  PlayBASIC Source Code -  Sinus Object Movement (27 March 2020)

      This code moves an object from one location to another in 2D space, but rather than linearly steeping from one point to the other we apply some sinus to the steps, which gives the motion the appearance that it's  accelerating off the mark and decelerating when approaching the target.


    Used commands:

                       GetDistance2d()
                       Sin()




Video:


 



Music:  Creeping_Spiders by Nat Keefe & BeatMower


 
PlayBASIC Code: [Select]
setfps 30

x1=100
y1=x1

x2=500
y2=500

do

For Angle#=0 to 90
cls

// max distance from point 1 to point 2
Dist#=GetDistance2d(x1,y1,x2,y2)

// Compute Radius
Radius#=sin(Angle#)*Dist#

// normal from point 1 to point 2
nx#=(x2-x1)/Dist#
ny#=(y2-y1)/Dist#

// compute new point along the line from p1 to 2
// at this radius
x#=x1+nx#*RAdius#
y#=y1+ny#*RAdius#

// draw start & end points
circlec x1,y1,10,true,$ff00
circlec x2,y2,10,true,$ff00

// plot moving object
circle x#,y#,5 ,true

sync
next


x1=x2
y1=y2

x2=rnd(800)
y2=rnd(600)

loop







Related Examples: