How to resolve the algorithm Animate a pendulum step by step in the VBScript programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Animate a pendulum step by step in the VBScript programming language
Table of Contents
Problem Statement
One good way of making an animation is by simulating a physical system and illustrating the variables in that system using a dynamically changing graphical display. The classic such physical system is a simple gravity pendulum.
Create a simple physical model of a pendulum and animate it.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Animate a pendulum step by step in the VBScript programming language
Source code in the vbscript programming language
option explicit
const dt = 0.15
const length=23
dim ans0:ans0=chr(27)&"["
dim Veloc,Accel,angle,olr,olc,r,c
const r0=1
const c0=40
cls
angle=0.7
while 1
wscript.sleep(50)
Accel = -.9 * sin(Angle)
Veloc = Veloc + Accel * dt
Angle = Angle + Veloc * dt
r = r0 + int(cos(Angle) * Length)
c = c0+ int(2*sin(Angle) * Length)
cls
draw_line r,c,r0,c0
toxy r,c,"O"
olr=r :olc=c
wend
sub cls() wscript.StdOut.Write ans0 &"2J"&ans0 &"?25l":end sub
sub toxy(r,c,s) wscript.StdOut.Write ans0 & r & ";" & c & "f" & s :end sub
Sub draw_line(r1,c1, r2,c2) 'Bresenham's line drawing
Dim x,y,xf,yf,dx,dy,sx,sy,err,err2
x =r1 : y =c1
xf=r2 : yf=c2
dx=Abs(xf-x) : dy=Abs(yf-y)
If x
If y
err=dx-dy
Do
toxy x,y,"."
If x=xf And y=yf Then Exit Do
err2=err+err
If err2>-dy Then err=err-dy: x=x+sx
If err2< dx Then err=err+dx: y=y+sy
Loop
End Sub 'draw_line
You may also check:How to resolve the algorithm Short-circuit evaluation step by step in the Logo programming language
You may also check:How to resolve the algorithm Dijkstra's algorithm step by step in the CafeOBJ programming language
You may also check:How to resolve the algorithm Special variables step by step in the Phix programming language
You may also check:How to resolve the algorithm Set right-adjacent bits step by step in the 11l programming language
You may also check:How to resolve the algorithm Numerical integration/Gauss-Legendre Quadrature step by step in the D programming language