TGC Codebase Backup



Spring oscillator by tornado

20th Mar 2005 4:52
Summary

Simple simulation of spring oscillator physics. On mouse click amplitude of oscillator raises up to maximum value, without click amplitude lowers to zero.



Description

Simple simulation of spring oscillator physics. On mouse click amplitude of oscillator raises up to maximum value, without click amplitude lowers to zero.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rem Same code I used in simulation of the car physics. 
rem You are free to use it anywhere :))

` Setup sync
sync on
sync rate 50


` make oscillator
make object sphere 1,20


position camera 0,0,0,-500

` Amp# is initial amplitude
Amp#=0


do

` controls of oscillator: without any influence oscillator
if mouseclick()=0 then dec Amp#
if Amp#<=0 then Amp#=0


if mouseclick()=1 then inc Amp#
if Amp#>=70 then Amp#=70 ` in this case maximum amplitude is 70
time=timer()

` oscillator formula
Y#=2*Amp#*sin(time/2)
` oscillator position
position object 1,0,Y#,0

sync
loop