June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
29
Task/Animate-a-pendulum/BASIC/animate-a-pendulum-1.basic
Normal file
29
Task/Animate-a-pendulum/BASIC/animate-a-pendulum-1.basic
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
MODE 8
|
||||
*FLOAT 64
|
||||
VDU 23,23,4;0;0;0; : REM Set line thickness
|
||||
|
||||
theta = RAD(40) : REM initial displacement
|
||||
g = 9.81 : REM acceleration due to gravity
|
||||
l = 0.50 : REM length of pendulum in metres
|
||||
|
||||
REPEAT
|
||||
PROCpendulum(theta, l)
|
||||
WAIT 1
|
||||
PROCpendulum(theta, l)
|
||||
accel = - g * SIN(theta) / l / 100
|
||||
speed += accel / 100
|
||||
theta += speed
|
||||
UNTIL FALSE
|
||||
END
|
||||
|
||||
DEF PROCpendulum(a, l)
|
||||
LOCAL pivotX, pivotY, bobX, bobY
|
||||
pivotX = 640
|
||||
pivotY = 800
|
||||
bobX = pivotX + l * 1000 * SIN(a)
|
||||
bobY = pivotY - l * 1000 * COS(a)
|
||||
GCOL 3,6
|
||||
LINE pivotX, pivotY, bobX, bobY
|
||||
GCOL 3,11
|
||||
CIRCLE FILL bobX + 24 * SIN(a), bobY - 24 * COS(a), 24
|
||||
ENDPROC
|
||||
24
Task/Animate-a-pendulum/BASIC/animate-a-pendulum-2.basic
Normal file
24
Task/Animate-a-pendulum/BASIC/animate-a-pendulum-2.basic
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
10 GOSUB 1000
|
||||
20 THETA = π/2
|
||||
30 G = 9.81
|
||||
40 L = 0.5
|
||||
50 SPEED = 0
|
||||
60 PX = 20
|
||||
70 PY = 1
|
||||
80 BX = PX+L*20*SIN(THETA)
|
||||
90 BY = PY-L*20*COS(THETA)
|
||||
100 PRINT CHR$(147);
|
||||
110 FOR X=PX TO BX STEP (BX-PX)/10
|
||||
120 Y=PY+(X-PX)*(BY-PY)/(BX-PX)
|
||||
130 PRINT CHR$(19);LEFT$(X$,X);LEFT$(Y$,Y);"."
|
||||
140 NEXT
|
||||
150 PRINT CHR$(19);LEFT$(X$,BX);LEFT$(Y$,BY);CHR$(113)
|
||||
160 ACCEL=G*SIN(THETA)/L/50
|
||||
170 SPEED=SPEED+ACCEL/10
|
||||
180 THETA=THETA+SPEED
|
||||
190 GOTO 80
|
||||
980 REM ** SETUP STRINGS TO BE USED **
|
||||
990 REM ** FOR CURSOR POSITIONING **
|
||||
1000 FOR I=0 TO 39: X$ = X$+CHR$(29): NEXT
|
||||
1010 FOR I=0 TO 24: Y$ = Y$+CHR$(17): NEXT
|
||||
1020 RETURN
|
||||
22
Task/Animate-a-pendulum/BASIC/animate-a-pendulum-3.basic
Normal file
22
Task/Animate-a-pendulum/BASIC/animate-a-pendulum-3.basic
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
Const PI = 3.141592920
|
||||
Dim As Double theta, g, l, accel, speed, px, py, bx, by
|
||||
theta = PI/2
|
||||
g = 9.81
|
||||
l = 1
|
||||
speed = 0
|
||||
px = 320
|
||||
py = 10
|
||||
Screen 17 '640x400 graphic
|
||||
Do
|
||||
bx=px+l*300*Sin(theta)
|
||||
by=py-l*300*Cos(theta)
|
||||
Cls
|
||||
Line (px,py)-(bx,by)
|
||||
Circle (bx,by),5,,,,,F
|
||||
accel=g*Sin(theta)/l/100
|
||||
speed=speed+accel/100
|
||||
theta=theta+speed
|
||||
Draw String (0,370), "Pendulum"
|
||||
Draw String (0,385), "Press any key to quit"
|
||||
Sleep 10
|
||||
Loop Until Inkey()<>""
|
||||
|
|
@ -17,9 +17,9 @@
|
|||
in_angle.value = 0;
|
||||
var cx = 150, cy = 50;
|
||||
var radius = 100; // cm
|
||||
var g = 981; // cm/s^2
|
||||
var g = 9.81; // m/s^2
|
||||
var angle = 0; // radians
|
||||
var vel = 0; // cm/s
|
||||
var vel = 0; // m/s
|
||||
var dx = 0.02; // s
|
||||
var acc, vel, penx, peny;
|
||||
var timerFunction = null;
|
||||
|
|
@ -33,9 +33,9 @@
|
|||
if(!timerFunction) timerFunction = setInterval(swing, dx * 1000);
|
||||
}
|
||||
function swing(){
|
||||
acc = g * Math.cos(angle) * dx;
|
||||
vel += acc * dx;
|
||||
angle += vel * dx;
|
||||
acc = g * Math.cos(angle);
|
||||
vel += acc * dx;//Convert m/s/s to m/s
|
||||
angle += vel/(radius/100) * dx; //convert m/s into rad/s and then into rad
|
||||
setPenPos();
|
||||
}
|
||||
function setPenPos(){
|
||||
|
|
|
|||
46
Task/Animate-a-pendulum/Julia/animate-a-pendulum.julia
Normal file
46
Task/Animate-a-pendulum/Julia/animate-a-pendulum.julia
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using Luxor
|
||||
using Colors
|
||||
using BoundaryValueDiffEq
|
||||
|
||||
# constants for differential equations and movie
|
||||
const g = 9.81
|
||||
const L = 1.0 # pendulum length in meters
|
||||
const bobd = 0.10 # pendulum bob diameter in meters
|
||||
const framerate = 50.0 # intended frame rate/sec
|
||||
const t0 = 0.0 # start time (s)
|
||||
const tf = 2.3 # end simulation time (s)
|
||||
const dtframe = 1.0/framerate # time increment per frame
|
||||
const tspan = linspace(t0, tf, Int(floor(tf*framerate))) # array of time points in animation
|
||||
|
||||
const bgcolor = "black" # gif background
|
||||
const leaderhue = (0.80, 0.70, 0.20) # gif swing arm hue light gold
|
||||
const hslcolors = [HSL(col) for col in (distinguishable_colors(
|
||||
Int(floor(tf*framerate)+3),[RGB(1,1,1)])[2:end])]
|
||||
const giffilename = "pendulum.gif" # output file
|
||||
|
||||
# differential equations
|
||||
simplependulum(t,u,du) = (θ=u[1]; dθ=u[2]; du[1]=dθ; du[2]=-(g/L)*sin(θ))
|
||||
bc2(residual, ua, ub) = (residual[1] = ua[1] + pi/2; residual[2] = ub[1] + pi/2)
|
||||
bvp2 = TwoPointBVProblem(simplependulum, bc2, [pi/2,pi/2], (tspan[1],tspan[end]))
|
||||
sol2 = solve(bvp2, MIRK4(), dt=dtframe) # use the MIRK4 solver for TwoPointBVProblem
|
||||
|
||||
# movie making background
|
||||
backdrop(scene, framenumber) = background(bgcolor)
|
||||
|
||||
function frame(scene, framenumber)
|
||||
u1, u2 = sol2.u[framenumber]
|
||||
y, x = L*cos(u1), L*sin(u1)
|
||||
sethue(leaderhue)
|
||||
poly([Point(-4.0, 0.0), Point(4.0, 0.0),
|
||||
Point(160.0x,160.0y)], :fill)
|
||||
sethue(Colors.HSV(framenumber*4.0, 1, 1))
|
||||
circle(Point(160.0x,160.0y), 160bobd, :fill)
|
||||
text(string("frame $framenumber of $(scene.framerange.stop)"),
|
||||
Point(0.0, -190.0),
|
||||
halign=:center)
|
||||
end
|
||||
|
||||
muv = Movie(400, 400, "Pendulum Demo", 1:length(tspan))
|
||||
animate(muv, [Scene(muv, backdrop),
|
||||
Scene(muv, frame, easingfunction=easeinoutcubic)],
|
||||
creategif=true, pathname=giffilename)
|
||||
43
Task/Animate-a-pendulum/Lingo/animate-a-pendulum.lingo
Normal file
43
Task/Animate-a-pendulum/Lingo/animate-a-pendulum.lingo
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
global RODLEN, GRAVITY, DT
|
||||
global velocity, acceleration, angle, posX, posY
|
||||
|
||||
on startMovie
|
||||
|
||||
-- window properties
|
||||
_movie.stage.title = "Pendulum"
|
||||
_movie.stage.titlebarOptions.visible = TRUE
|
||||
_movie.stage.rect = rect(0, 0, 400, 400)
|
||||
_movie.centerStage = TRUE
|
||||
_movie.puppetTempo(30)
|
||||
|
||||
RODLEN = 180
|
||||
GRAVITY = -9.8
|
||||
DT = 0.03
|
||||
|
||||
velocity = 0.0
|
||||
acceleration = 0.0
|
||||
angle = PI/3
|
||||
posX = 200 - sin(angle) * RODLEN
|
||||
posY = 100 + cos(angle) * RODLEN
|
||||
paint()
|
||||
|
||||
-- show the window
|
||||
_movie.stage.visible = TRUE
|
||||
end
|
||||
|
||||
on enterFrame
|
||||
acceleration = GRAVITY * sin(angle)
|
||||
velocity = velocity + acceleration * DT
|
||||
angle = angle + velocity * DT
|
||||
posX = 200 - sin(angle) * rodLen
|
||||
posY = 100 + cos(angle) * rodLen
|
||||
paint()
|
||||
end
|
||||
|
||||
on paint
|
||||
img = _movie.stage.image
|
||||
img.fill(img.rect, rgb(255,255,255))
|
||||
img.fill(point(200-5, 100-5), point(200+5, 100+5), [#shapeType:#oval,#color:rgb(0,0,0)])
|
||||
img.draw(point(200, 100), point(posX, posY), [#color:rgb(0,0,0)])
|
||||
img.fill(point(posX-20, posY-20), point(posX+20, posY+20), [#shapeType:#oval,#lineSize:1,#bgColor:rgb(0,0,0),#color:rgb(255,255,0)])
|
||||
end
|
||||
82
Task/Animate-a-pendulum/Ring/animate-a-pendulum.ring
Normal file
82
Task/Animate-a-pendulum/Ring/animate-a-pendulum.ring
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
# Project : Animate a pendulum
|
||||
# Date : 2018/04/09
|
||||
# Author : Gal Zsolt (~ CalmoSoft ~)
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
load "guilib.ring"
|
||||
load "stdlib.ring"
|
||||
|
||||
CounterMan = 1
|
||||
paint = null
|
||||
pi = 22/7
|
||||
theta = pi/180*40
|
||||
g = 9.81
|
||||
l = 0.50
|
||||
speed = 0
|
||||
|
||||
new qapp
|
||||
{
|
||||
win1 = new qwidget() {
|
||||
setwindowtitle("Animate a pendulum")
|
||||
setgeometry(100,100,800,600)
|
||||
label1 = new qlabel(win1) {
|
||||
setgeometry(10,10,800,600)
|
||||
settext("")
|
||||
}
|
||||
new qpushbutton(win1) {
|
||||
setgeometry(150,500,100,30)
|
||||
settext("draw")
|
||||
setclickevent("draw()")
|
||||
}
|
||||
TimerMan = new qtimer(win1)
|
||||
{
|
||||
setinterval(1000)
|
||||
settimeoutevent("draw()")
|
||||
start()
|
||||
}
|
||||
show()
|
||||
}
|
||||
exec()
|
||||
}
|
||||
|
||||
func draw
|
||||
p1 = new qpicture()
|
||||
color = new qcolor() {
|
||||
setrgb(0,0,255,255)
|
||||
}
|
||||
pen = new qpen() {
|
||||
setcolor(color)
|
||||
setwidth(1)
|
||||
}
|
||||
paint = new qpainter() {
|
||||
begin(p1)
|
||||
setpen(pen)
|
||||
ptime()
|
||||
endpaint()
|
||||
}
|
||||
label1 { setpicture(p1) show() }
|
||||
return
|
||||
|
||||
func ptime()
|
||||
TimerMan.start()
|
||||
pPlaySleep()
|
||||
sleep(0.1)
|
||||
CounterMan++
|
||||
if CounterMan = 20
|
||||
TimerMan.stop()
|
||||
ok
|
||||
|
||||
func pPlaySleep()
|
||||
pendulum(theta, l)
|
||||
pendulum(theta, l)
|
||||
accel = - g * sin(theta) / l / 100
|
||||
speed = speed + accel / 100
|
||||
theta = theta + speed
|
||||
|
||||
func pendulum(a, l)
|
||||
pivotx = 640
|
||||
pivoty = 800
|
||||
bobx = pivotx + l * 1000 * sin(a)
|
||||
boby = pivoty - l * 1000 * cos(a)
|
||||
paint.drawline(pivotx, pivoty, bobx, boby)
|
||||
paint.drawellipse(bobx + 24 * sin(a), boby - 24 * cos(a), 24, 24)
|
||||
Loading…
Add table
Add a link
Reference in a new issue