Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
35
Task/Animate-a-pendulum/OoRexx/animate-a-pendulum.rexx
Normal file
35
Task/Animate-a-pendulum/OoRexx/animate-a-pendulum.rexx
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
pendulum = .pendulum~new(10, 30)
|
||||
|
||||
before = .datetime~new
|
||||
do 100 -- somewhat arbitrary loop count
|
||||
call syssleep .2
|
||||
now = .datetime~new
|
||||
pendulum~update(now - before)
|
||||
before = now
|
||||
say " X:" pendulum~x " Y:" pendulum~y
|
||||
end
|
||||
|
||||
::class pendulum
|
||||
::method init
|
||||
expose length theta x y velocity
|
||||
use arg length, theta
|
||||
x = rxcalcsin(theta) * length
|
||||
y = rxcalccos(theta) * length
|
||||
velocity = 0
|
||||
|
||||
::attribute x GET
|
||||
::attribute y GET
|
||||
|
||||
::constant g -9.81 -- acceleration due to gravity
|
||||
|
||||
::method update
|
||||
expose length theta x y velocity
|
||||
use arg duration
|
||||
acceleration = self~g / length * rxcalcsin(theta)
|
||||
durationSeconds = duration~microseconds / 1000000
|
||||
x = rxcalcsin(theta, length)
|
||||
y = rxcalccos(theta, length)
|
||||
velocity = velocity + acceleration * durationSeconds
|
||||
theta = theta + velocity * durationSeconds
|
||||
|
||||
::requires rxmath library
|
||||
Loading…
Add table
Add a link
Reference in a new issue