Animate a pendulum: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 1: Line 1:
[[Category:Animation]]
{{task|Temporal media}}
{{task|Temporal media}}
{{requires|Graphics}}
{{requires|Graphics}}
Line 18: Line 19:


pendulums.ads:
pendulums.ads:
<syntaxhighlight lang=Ada>generic
<syntaxhighlight lang="ada">generic
type Float_Type is digits <>;
type Float_Type is digits <>;
Gravitation : Float_Type;
Gravitation : Float_Type;
Line 39: Line 40:


pendulums.adb:
pendulums.adb:
<syntaxhighlight lang=Ada>with Ada.Numerics.Generic_Elementary_Functions;
<syntaxhighlight lang="ada">with Ada.Numerics.Generic_Elementary_Functions;
package body Pendulums is
package body Pendulums is
package Math is new Ada.Numerics.Generic_Elementary_Functions (Float_Type);
package Math is new Ada.Numerics.Generic_Elementary_Functions (Float_Type);
Line 79: Line 80:


example main.adb:
example main.adb:
<syntaxhighlight lang=Ada>with Ada.Text_IO;
<syntaxhighlight lang="ada">with Ada.Text_IO;
with Ada.Calendar;
with Ada.Calendar;
with Pendulums;
with Pendulums;
Line 142: Line 143:
=={{header|Amazing Hopper}}==
=={{header|Amazing Hopper}}==
{{Trans|FreeBASIC}}
{{Trans|FreeBASIC}}
<lang>
<syntaxhighlight lang="text">
#include <flow.h>
#include <flow.h>
#include <flow-term.h>
#include <flow-term.h>
Line 265: Line 266:
You can simulate a pseudo graphical mode in an Ubuntu Linux terminal by adding the following lines:
You can simulate a pseudo graphical mode in an Ubuntu Linux terminal by adding the following lines:
</pre>
</pre>
<syntaxhighlight lang=Amazing Hopper>
<syntaxhighlight lang="amazing hopper">
SYS("gsettings set org.gnome.Terminal.Legacy.Profile:/org/gnome/terminal/legacy/profiles:/:.../ font 'Ubuntu Mono 1'")
SYS("gsettings set org.gnome.Terminal.Legacy.Profile:/org/gnome/terminal/legacy/profiles:/:.../ font 'Ubuntu Mono 1'")


Line 279: Line 280:
And substituting the holding coordinates of the pendulum:
And substituting the holding coordinates of the pendulum:
</pre>
</pre>
<syntaxhighlight lang=Amazing Hopper>
<syntaxhighlight lang="amazing hopper">


// in "Animate a Pendulum"
// in "Animate a Pendulum"
Line 299: Line 300:
This version doesn't use an complex physics calculation - I found a faster way.
This version doesn't use an complex physics calculation - I found a faster way.
{{libheader|GDIP}}
{{libheader|GDIP}}
<syntaxhighlight lang=AutoHotkey>SetBatchlines,-1
<syntaxhighlight lang="autohotkey">SetBatchlines,-1
;settings
;settings
SizeGUI:={w:650,h:400} ;Guisize
SizeGUI:={w:650,h:400} ;Guisize
Line 343: Line 344:
{{trans|Commodore BASIC}}
{{trans|Commodore BASIC}}
Two shapes are used to draw and undraw the pendulum. Undrawing and drawing is done on the page that is not being displayed to make the animation flicker free. Animation code is compacted and hoisted to the beginning of the program. Variables are defined for all non-zero values.
Two shapes are used to draw and undraw the pendulum. Undrawing and drawing is done on the page that is not being displayed to make the animation flicker free. Animation code is compacted and hoisted to the beginning of the program. Variables are defined for all non-zero values.
<syntaxhighlight lang=gwbasic> 0 ON NOT T GOTO 9: FOR Q = 0 TO T STEP 0:BX = PX + L * S * SIN (F):BY = PY - L * S * COS (F): HCOLOR= 0: FOR I = 0 TO N(P): DRAW T + (I = N(P)) AT X(P,I),Y(P,I): NEXT I:N(P) = 0: HCOLOR= C
<syntaxhighlight lang="gwbasic"> 0 ON NOT T GOTO 9: FOR Q = 0 TO T STEP 0:BX = PX + L * S * SIN (F):BY = PY - L * S * COS (F): HCOLOR= 0: FOR I = 0 TO N(P): DRAW T + (I = N(P)) AT X(P,I),Y(P,I): NEXT I:N(P) = 0: HCOLOR= C
1 FOR X = PX TO BX STEP (BX - PX) / Z:Y = PY + (X - PX) * (BY - PY) / (BX - PX): DRAW T AT X,Y:X(P,N(P)) = X:Y(P,N(P)) = Y:N(P) = N(P) + 1: NEXT X
1 FOR X = PX TO BX STEP (BX - PX) / Z:Y = PY + (X - PX) * (BY - PY) / (BX - PX): DRAW T AT X,Y:X(P,N(P)) = X:Y(P,N(P)) = Y:N(P) = N(P) + 1: NEXT X
2 HCOLOR= T: DRAW B AT BX,BY:X(P,N(P)) = BX:Y(P,N(P)) = BY:A = PEEK (R + P):P = NOT P: POKE U,W + W * P:A = G * SIN (F) / L / H:V = V + A / Z:F = F + V: NEXT Q
2 HCOLOR= T: DRAW B AT BX,BY:X(P,N(P)) = BX:Y(P,N(P)) = BY:A = PEEK (R + P):P = NOT P: POKE U,W + W * P:A = G * SIN (F) / L / H:V = V + A / Z:F = F + V: NEXT Q
Line 366: Line 367:
==={{header|BBC BASIC}}===
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang=bbcbasic> MODE 8
<syntaxhighlight lang="bbcbasic"> MODE 8
*FLOAT 64
*FLOAT 64
VDU 23,23,4;0;0;0; : REM Set line thickness
VDU 23,23,4;0;0;0; : REM Set line thickness
Line 397: Line 398:


==={{header|Commodore BASIC}}===
==={{header|Commodore BASIC}}===
<syntaxhighlight lang=commodorebasic>10 GOSUB 1000
<syntaxhighlight lang="commodorebasic">10 GOSUB 1000
20 THETA = π/2
20 THETA = π/2
30 G = 9.81
30 G = 9.81
Line 423: Line 424:


==={{header|FreeBASIC}}===
==={{header|FreeBASIC}}===
<syntaxhighlight lang=freebasic>Const PI = 3.141592920
<syntaxhighlight lang="freebasic">Const PI = 3.141592920
Dim As Double theta, g, l, accel, speed, px, py, bx, by
Dim As Double theta, g, l, accel, speed, px, py, bx, by
theta = PI/2
theta = PI/2
Line 447: Line 448:


==={{header|IS-BASIC}}===
==={{header|IS-BASIC}}===
<syntaxhighlight lang=IS-BASIC>100 PROGRAM "Pendulum.bas"
<syntaxhighlight lang="is-basic">100 PROGRAM "Pendulum.bas"
110 LET THETA=RAD(50):LET G=9.81:LET L=.5
110 LET THETA=RAD(50):LET G=9.81:LET L=.5
120 CALL INIC
120 CALL INIC
Line 505: Line 506:
=={{header|C}}==
=={{header|C}}==
{{libheader|GLUT}}
{{libheader|GLUT}}
<syntaxhighlight lang=c>#include <stdlib.h>
<syntaxhighlight lang="c">#include <stdlib.h>
#include <math.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/glut.h>
Line 588: Line 589:
{{libheader|GDI (System.Drawing)}}
{{libheader|GDI (System.Drawing)}}


<syntaxhighlight lang=csharp>
<syntaxhighlight lang="csharp">
using System;
using System;
using System.Drawing;
using System.Drawing;
Line 648: Line 649:
{{libheader|wxWidgets}}
{{libheader|wxWidgets}}
File wxPendulumDlg.hpp
File wxPendulumDlg.hpp
<syntaxhighlight lang=cpp>
<syntaxhighlight lang="cpp">
#ifndef __wxPendulumDlg_h__
#ifndef __wxPendulumDlg_h__
#define __wxPendulumDlg_h__
#define __wxPendulumDlg_h__
Line 717: Line 718:
</syntaxhighlight>
</syntaxhighlight>
File wxPendulumDlg.cpp
File wxPendulumDlg.cpp
<syntaxhighlight lang=cpp>
<syntaxhighlight lang="cpp">
// ---------------------
// ---------------------
/// @author Martin Ettl
/// @author Martin Ettl
Line 840: Line 841:


{{libheader|Swing}} {{libheader|AWT}}
{{libheader|Swing}} {{libheader|AWT}}
<syntaxhighlight lang=clojure>
<syntaxhighlight lang="clojure">
(ns pendulum
(ns pendulum
(:import
(:import
Line 914: Line 915:
Pressing the spacebar adds a pendulum.
Pressing the spacebar adds a pendulum.


<syntaxhighlight lang=lisp>(defvar *frame-rate* 30)
<syntaxhighlight lang="lisp">(defvar *frame-rate* 30)
(defvar *damping* 0.99 "Deceleration factor.")
(defvar *damping* 0.99 "Deceleration factor.")


Line 964: Line 965:
{{libheader| Vcl.ExtCtrls}}
{{libheader| Vcl.ExtCtrls}}
{{Trans|C#}}
{{Trans|C#}}
<syntaxhighlight lang=Delphi>
<syntaxhighlight lang="delphi">
unit main;
unit main;


Line 1,068: Line 1,069:
(This logic is more general than necessary; it is designed to be suitable for a larger application as well.)
(This logic is more general than necessary; it is designed to be suitable for a larger application as well.)


<syntaxhighlight lang=e>#!/usr/bin/env rune
<syntaxhighlight lang="e">#!/usr/bin/env rune
pragma.syntax("0.9")
pragma.syntax("0.9")


Line 1,161: Line 1,162:
[https://easylang.online/apps/pendulum.html Run it]
[https://easylang.online/apps/pendulum.html Run it]


<lang>on animate
<syntaxhighlight lang="text">on animate
clear
clear
move 50 50
move 50 50
Line 1,175: Line 1,176:


=={{header|Elm}}==
=={{header|Elm}}==
<syntaxhighlight lang=elm>import Color exposing (..)
<syntaxhighlight lang="elm">import Color exposing (..)
import Collage exposing (..)
import Collage exposing (..)
import Element exposing (..)
import Element exposing (..)
Line 1,252: Line 1,253:


=={{header|ERRE}}==
=={{header|ERRE}}==
<syntaxhighlight lang=ERRE>
<syntaxhighlight lang="erre">
PROGRAM PENDULUM
PROGRAM PENDULUM


Line 1,324: Line 1,325:
===DOS32 version===
===DOS32 version===
{{works with|Euphoria|3.1.1}}
{{works with|Euphoria|3.1.1}}
<syntaxhighlight lang=euphoria>include graphics.e
<syntaxhighlight lang="euphoria">include graphics.e
include misc.e
include misc.e


Line 1,384: Line 1,385:
=={{header|F_Sharp|F#}}==
=={{header|F_Sharp|F#}}==
A nice application of F#'s support for units of measure.
A nice application of F#'s support for units of measure.
<syntaxhighlight lang=fsharp>open System
<syntaxhighlight lang="fsharp">open System
open System.Drawing
open System.Drawing
open System.Windows.Forms
open System.Windows.Forms
Line 1,469: Line 1,470:
=={{header|Factor}}==
=={{header|Factor}}==
Approximation of the pendulum for small swings : theta = theta0 * cos(omega0 * t)
Approximation of the pendulum for small swings : theta = theta0 * cos(omega0 * t)
<syntaxhighlight lang=factor>USING: accessors alarms arrays calendar colors.constants kernel
<syntaxhighlight lang="factor">USING: accessors alarms arrays calendar colors.constants kernel
locals math math.constants math.functions math.rectangles
locals math math.constants math.functions math.rectangles
math.vectors opengl sequences system ui ui.gadgets ui.render ;
math.vectors opengl sequences system ui ui.gadgets ui.render ;
Line 1,512: Line 1,513:


=={{header|FBSL}}==
=={{header|FBSL}}==
<syntaxhighlight lang=qbasic>#INCLUDE <Include\Windows.inc>
<syntaxhighlight lang="qbasic">#INCLUDE <Include\Windows.inc>


FBSLSETTEXT(ME, "Pendulum")
FBSLSETTEXT(ME, "Pendulum")
Line 1,574: Line 1,575:
=={{header|Fortran}}==
=={{header|Fortran}}==
Uses system commands (gfortran) to clear the screen. An initial starting angle is allowed between 90 (to the right) and -90 degrees (to the left). It checks for incorrect inputs.
Uses system commands (gfortran) to clear the screen. An initial starting angle is allowed between 90 (to the right) and -90 degrees (to the left). It checks for incorrect inputs.
<syntaxhighlight lang=fortran>
<syntaxhighlight lang="fortran">
!Implemented by Anant Dixit (October, 2014)
!Implemented by Anant Dixit (October, 2014)
program animated_pendulum
program animated_pendulum
Line 1,935: Line 1,936:
=={{header|Groovy}}==
=={{header|Groovy}}==
Straight translation of Java solution groovified by removing explicit definitions and converting casts to Groovy as style where needed.
Straight translation of Java solution groovified by removing explicit definitions and converting casts to Groovy as style where needed.
<syntaxhighlight lang=groovy>
<syntaxhighlight lang="groovy">
import java.awt.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.*;
Line 1,992: Line 1,993:
=={{header|Go}}==
=={{header|Go}}==
Using {{libheader|GXUI}} from [https://github.com/google/gxui Github]
Using {{libheader|GXUI}} from [https://github.com/google/gxui Github]
<syntaxhighlight lang=go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 2,111: Line 2,112:
=={{header|Haskell}}==
=={{header|Haskell}}==
{{libheader|HGL}}
{{libheader|HGL}}
<syntaxhighlight lang=haskell>import Graphics.HGL.Draw.Monad (Graphic, )
<syntaxhighlight lang="haskell">import Graphics.HGL.Draw.Monad (Graphic, )
import Graphics.HGL.Draw.Picture
import Graphics.HGL.Draw.Picture
import Graphics.HGL.Utils
import Graphics.HGL.Utils
Line 2,146: Line 2,147:
=== Alternative solution ===
=== Alternative solution ===
{{libheader|Gloss}}
{{libheader|Gloss}}
<syntaxhighlight lang=haskell>import Graphics.Gloss
<syntaxhighlight lang="haskell">import Graphics.Gloss


-- Initial conditions
-- Initial conditions
Line 2,201: Line 2,202:
[http://www.HicEst.com/DIFFEQ.htm DIFFEQ] and the callback procedure pendulum numerically integrate the pendulum equation.
[http://www.HicEst.com/DIFFEQ.htm DIFFEQ] and the callback procedure pendulum numerically integrate the pendulum equation.
The display window can be resized during the run, but for window width not equal to 2*height the pendulum rod becomes a rubber band instead:
The display window can be resized during the run, but for window width not equal to 2*height the pendulum rod becomes a rubber band instead:
<syntaxhighlight lang=HicEst>REAL :: msec=10, Lrod=1, dBob=0.03, g=9.81, Theta(2), dTheta(2)
<syntaxhighlight lang="hicest">REAL :: msec=10, Lrod=1, dBob=0.03, g=9.81, Theta(2), dTheta(2)
BobMargins = ALIAS(ls, rs, ts, bs) ! box margins to draw the bob
BobMargins = ALIAS(ls, rs, ts, bs) ! box margins to draw the bob


Line 2,241: Line 2,242:
{{trans|Scheme}}
{{trans|Scheme}}


<syntaxhighlight lang=Unicon>
<syntaxhighlight lang="unicon">
import gui
import gui
$include "guih.icn"
$include "guih.icn"
Line 2,339: Line 2,340:
=={{header|J}}==
=={{header|J}}==
Works for '''J6'''
Works for '''J6'''
<syntaxhighlight lang=j>require 'gl2 trig'
<syntaxhighlight lang="j">require 'gl2 trig'
coinsert 'jgl2'
coinsert 'jgl2'


Line 2,383: Line 2,384:
pend_run'' NB. run animation</syntaxhighlight>
pend_run'' NB. run animation</syntaxhighlight>
Updated for changes in '''J8'''
Updated for changes in '''J8'''
<syntaxhighlight lang=j>require 'gl2 trig'
<syntaxhighlight lang="j">require 'gl2 trig'
coinsert 'jgl2'
coinsert 'jgl2'
Line 2,440: Line 2,441:
=={{header|Java}}==
=={{header|Java}}==
{{libheader|Swing}} {{libheader|AWT}}
{{libheader|Swing}} {{libheader|AWT}}
<syntaxhighlight lang=java>import java.awt.*;
<syntaxhighlight lang="java">import java.awt.*;
import javax.swing.*;
import javax.swing.*;


Line 2,497: Line 2,498:
{{trans|E}} (plus gratuitous motion blur)
{{trans|E}} (plus gratuitous motion blur)


<syntaxhighlight lang=javascript><html><head>
<syntaxhighlight lang="javascript"><html><head>
<title>Pendulum</title>
<title>Pendulum</title>
</head><body style="background: gray;">
</head><body style="background: gray;">
Line 2,563: Line 2,564:
Also we'll use a dimensionless formulation of the problem (taking unit value for the mass, the length and so on).
Also we'll use a dimensionless formulation of the problem (taking unit value for the mass, the length and so on).


<syntaxhighlight lang=javascript><svg height="100%" width="100%" viewBox="-2 0 4 4" xmlns="http://www.w3.org/2000/svg">
<syntaxhighlight lang="javascript"><svg height="100%" width="100%" viewBox="-2 0 4 4" xmlns="http://www.w3.org/2000/svg">
<line id="string" x1="0" y1="0" x2="1" y2="0" stroke="grey" stroke-width="0.05" />
<line id="string" x1="0" y1="0" x2="1" y2="0" stroke="grey" stroke-width="0.05" />
<circle id="ball" cx="0" cy="0" r="0.1" fill="black" />
<circle id="ball" cx="0" cy="0" r="0.1" fill="black" />
Line 2,607: Line 2,608:


=={{header|Julia}}==
=={{header|Julia}}==
Differential equation based solution using the Luxor graphics library.<syntaxhighlight lang=julia>using Luxor
Differential equation based solution using the Luxor graphics library.<syntaxhighlight lang="julia">using Luxor
using Colors
using Colors
using BoundaryValueDiffEq
using BoundaryValueDiffEq
Line 2,657: Line 2,658:
=={{header|Kotlin}}==
=={{header|Kotlin}}==
Conversion of Java snippet.
Conversion of Java snippet.
<syntaxhighlight lang=scala>import java.awt.*
<syntaxhighlight lang="scala">import java.awt.*
import java.util.concurrent.*
import java.util.concurrent.*
import javax.swing.*
import javax.swing.*
Line 2,705: Line 2,706:


=={{header|Liberty BASIC}}==
=={{header|Liberty BASIC}}==
<syntaxhighlight lang=lb>nomainwin
<syntaxhighlight lang="lb">nomainwin
WindowWidth = 400
WindowWidth = 400
WindowHeight = 300
WindowHeight = 300
Line 2,749: Line 2,750:


=={{header|Lingo}}==
=={{header|Lingo}}==
<syntaxhighlight lang=Lingo>global RODLEN, GRAVITY, DT
<syntaxhighlight lang="lingo">global RODLEN, GRAVITY, DT
global velocity, acceleration, angle, posX, posY
global velocity, acceleration, angle, posX, posY
Line 2,795: Line 2,796:
=={{header|Logo}}==
=={{header|Logo}}==
{{works with|UCB Logo}}
{{works with|UCB Logo}}
<syntaxhighlight lang=logo>make "angle 45
<syntaxhighlight lang="logo">make "angle 45
make "L 1
make "L 1
make "bob 10
make "bob 10
Line 2,827: Line 2,828:
=={{header|Lua}}==
=={{header|Lua}}==
Needs L&Ouml;VE 2D Engine
Needs L&Ouml;VE 2D Engine
<syntaxhighlight lang=lua>
<syntaxhighlight lang="lua">
function degToRad( d )
function degToRad( d )
return d * 0.01745329251
return d * 0.01745329251
Line 2,859: Line 2,860:


=={{header|M2000 Interpreter}}==
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang=M2000 Interpreter>
<syntaxhighlight lang="m2000 interpreter">
Module Pendulum {
Module Pendulum {
back()
back()
Line 2,910: Line 2,911:


=={{header|Mathematica}} / {{header|Wolfram Language}}==
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang=Mathematica>freq = 8; length = freq^(-1/2);
<syntaxhighlight lang="mathematica">freq = 8; length = freq^(-1/2);
Animate[Graphics[
Animate[Graphics[
List[{Line[{{0, 0}, length {Sin[T], -Cos[T]}} /. {T -> (Pi/6) Cos[2 Pi freq t]}], PointSize[Large],
List[{Line[{{0, 0}, length {Sin[T], -Cos[T]}} /. {T -> (Pi/6) Cos[2 Pi freq t]}], PointSize[Large],
Line 2,919: Line 2,920:
=={{header|MATLAB}}==
=={{header|MATLAB}}==
pendulum.m
pendulum.m
<syntaxhighlight lang=MATLAB>%This is a numerical simulation of a pendulum with a massless pivot arm.
<syntaxhighlight lang="matlab">%This is a numerical simulation of a pendulum with a massless pivot arm.


%% User Defined Parameters
%% User Defined Parameters
Line 2,996: Line 2,997:


Conversion from C with some modifications: changing some variable names, adding a display function to make the program work with "freeGlut", choosing another initial angle, etc.
Conversion from C with some modifications: changing some variable names, adding a display function to make the program work with "freeGlut", choosing another initial angle, etc.
<syntaxhighlight lang=Nim># Pendulum simulation.
<syntaxhighlight lang="nim"># Pendulum simulation.


import math
import math
Line 3,109: Line 3,110:


This version uses the same equations but replace OpenGL by Gtk3 with the “gintro” bindings.
This version uses the same equations but replace OpenGL by Gtk3 with the “gintro” bindings.
<syntaxhighlight lang=Nim># Pendulum simulation.
<syntaxhighlight lang="nim"># Pendulum simulation.


import math
import math
Line 3,237: Line 3,238:
=={{header|ooRexx}}==
=={{header|ooRexx}}==
ooRexx does not have a portable GUI, but this version is similar to the Ada version and just prints out the coordinates of the end of the pendulum.
ooRexx does not have a portable GUI, but this version is similar to the Ada version and just prints out the coordinates of the end of the pendulum.
<syntaxhighlight lang=ooRexx>
<syntaxhighlight lang="oorexx">
pendulum = .pendulum~new(10, 30)
pendulum = .pendulum~new(10, 30)


Line 3,279: Line 3,280:
Inspired by the E and Ruby versions.
Inspired by the E and Ruby versions.


<syntaxhighlight lang=oz>declare
<syntaxhighlight lang="oz">declare
[QTk] = {Link ['x-oz://system/wp/QTk.ozf']}
[QTk] = {Link ['x-oz://system/wp/QTk.ozf']}


Line 3,370: Line 3,371:
This does not have the window resizing handling that Tcl does.
This does not have the window resizing handling that Tcl does.


<syntaxhighlight lang=perl>
<syntaxhighlight lang="perl">
use strict;
use strict;
use warnings;
use warnings;
Line 3,442: Line 3,443:
{{libheader|Phix/online}}
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/animate_pendulum2.htm here].
You can run this online [http://phix.x10.mx/p2js/animate_pendulum2.htm here].
<!--<syntaxhighlight lang=Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\animate_pendulum.exw
-- demo\rosetta\animate_pendulum.exw
Line 3,554: Line 3,555:
=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
A minimalist solution. The pendulum consists of the center point '+', and the swinging xterm cursor.
A minimalist solution. The pendulum consists of the center point '+', and the swinging xterm cursor.
<syntaxhighlight lang=PicoLisp>(load "@lib/math.l")
<syntaxhighlight lang="picolisp">(load "@lib/math.l")


(de pendulum (X Y Len)
(de pendulum (X Y Len)
Line 3,570: Line 3,571:
(+ X (*/ Len (sin Angle) 1.0)) ) ) ) )</syntaxhighlight>
(+ X (*/ Len (sin Angle) 1.0)) ) ) ) )</syntaxhighlight>
Test (hit any key to stop):
Test (hit any key to stop):
<syntaxhighlight lang=PicoLisp>(pendulum 40 1 36)</syntaxhighlight>
<syntaxhighlight lang="picolisp">(pendulum 40 1 36)</syntaxhighlight>


=={{header|Portugol}}==
=={{header|Portugol}}==
{{trans|FreeBASIC}}
{{trans|FreeBASIC}}
<syntaxhighlight lang=Portugol>
<syntaxhighlight lang="portugol">
programa {
programa {
inclua biblioteca Matematica --> math // math library
inclua biblioteca Matematica --> math // math library
Line 3,625: Line 3,626:
=={{header|Prolog}}==
=={{header|Prolog}}==
SWI-Prolog has a graphic interface XPCE.
SWI-Prolog has a graphic interface XPCE.
<syntaxhighlight lang=Prolog>:- use_module(library(pce)).
<syntaxhighlight lang="prolog">:- use_module(library(pce)).


pendulum :-
pendulum :-
Line 3,709: Line 3,710:
=={{header|PureBasic}}==
=={{header|PureBasic}}==
If the code was part of a larger application it could be improved by specifying constants for the locations of image elements.
If the code was part of a larger application it could be improved by specifying constants for the locations of image elements.
<syntaxhighlight lang=PureBasic>Procedure handleError(x, msg.s)
<syntaxhighlight lang="purebasic">Procedure handleError(x, msg.s)
If Not x
If Not x
MessageRequester("Error", msg)
MessageRequester("Error", msg)
Line 3,821: Line 3,822:


{{trans|C}}
{{trans|C}}
<syntaxhighlight lang=python>import pygame, sys
<syntaxhighlight lang="python">import pygame, sys
from pygame.locals import *
from pygame.locals import *
from math import sin, cos, radians
from math import sin, cos, radians
Line 3,905: Line 3,906:


===Python: using tkinter===
===Python: using tkinter===
<syntaxhighlight lang=python>
<syntaxhighlight lang="python">
''' Python 3.6.5 code using Tkinter graphical user interface.'''
''' Python 3.6.5 code using Tkinter graphical user interface.'''


Line 3,997: Line 3,998:


=={{header|QB64}}==
=={{header|QB64}}==
<syntaxhighlight lang=qbasic>'declare and initialize variables
<syntaxhighlight lang="qbasic">'declare and initialize variables
CONST PI = 3.141592
CONST PI = 3.141592


Line 4,096: Line 4,097:


=={{header|R}}==
=={{header|R}}==
<syntaxhighlight lang=R>library(DescTools)
<syntaxhighlight lang="r">library(DescTools)


pendulum<-function(length=5,radius=1,circle.color="white",bg.color="white"){
pendulum<-function(length=5,radius=1,circle.color="white",bg.color="white"){
Line 4,121: Line 4,122:


=={{header|Racket}}==
=={{header|Racket}}==
<syntaxhighlight lang=racket>
<syntaxhighlight lang="racket">
#lang racket
#lang racket


Line 4,148: Line 4,149:
Handles window resizing, modifies pendulum length and period as window height changes. May need to tweek $ppi scaling to get good looking animation.
Handles window resizing, modifies pendulum length and period as window height changes. May need to tweek $ppi scaling to get good looking animation.


<syntaxhighlight lang=perl6>use SDL2::Raw;
<syntaxhighlight lang="raku" line>use SDL2::Raw;
use Cairo;
use Cairo;


Line 4,245: Line 4,246:
this version is similar to the '''Ada''' version and just
this version is similar to the '''Ada''' version and just
<br>displays the coordinates of the end of the pendulum.
<br>displays the coordinates of the end of the pendulum.
<syntaxhighlight lang=rexx>/*REXX program displays the (x, y) coördinates (at the end of a swinging pendulum). */
<syntaxhighlight lang="rexx">/*REXX program displays the (x, y) coördinates (at the end of a swinging pendulum). */
parse arg cycles Plength theta . /*obtain optional argument from the CL.*/
parse arg cycles Plength theta . /*obtain optional argument from the CL.*/
if cycles=='' | cycles=="," then cycles= 60 /*Not specified? Then use the default.*/
if cycles=='' | cycles=="," then cycles= 60 /*Not specified? Then use the default.*/
Line 4,346: Line 4,347:


=={{header|Ring}}==
=={{header|Ring}}==
<syntaxhighlight lang=ring>
<syntaxhighlight lang="ring">
# Project : Animate a pendulum
# Project : Animate a pendulum


Line 4,458: Line 4,459:
The RLaB script that solves the problem is
The RLaB script that solves the problem is


<syntaxhighlight lang=RLaB>
<syntaxhighlight lang="rlab">
//
//
// example: solve ODE for pendulum
// example: solve ODE for pendulum
Line 4,532: Line 4,533:
the Tcl pendulum swings noticibly faster.
the Tcl pendulum swings noticibly faster.


<syntaxhighlight lang=ruby>require 'tk'
<syntaxhighlight lang="ruby">require 'tk'


$root = TkRoot.new("title" => "Pendulum Animation")
$root = TkRoot.new("title" => "Pendulum Animation")
Line 4,597: Line 4,598:


==={{libheader|Shoes}}===
==={{libheader|Shoes}}===
<syntaxhighlight lang=ruby>Shoes.app(:width => 320, :height => 200) do
<syntaxhighlight lang="ruby">Shoes.app(:width => 320, :height => 200) do
@centerX = 160
@centerX = 160
@centerY = 25
@centerY = 25
Line 4,656: Line 4,657:


==={{libheader|Ruby/Gosu}}===
==={{libheader|Ruby/Gosu}}===
<syntaxhighlight lang=ruby>#!/bin/ruby
<syntaxhighlight lang="ruby">#!/bin/ruby


begin; require 'rubygems'; rescue; end
begin; require 'rubygems'; rescue; end
Line 4,768: Line 4,769:


{{libheader|piston_window}}
{{libheader|piston_window}}
<syntaxhighlight lang=Rust>
<syntaxhighlight lang="rust">
// using version 0.107.0 of piston_window
// using version 0.107.0 of piston_window
use piston_window::{clear, ellipse, line_from_to, PistonWindow, WindowSettings};
use piston_window::{clear, ellipse, line_from_to, PistonWindow, WindowSettings};
Line 4,830: Line 4,831:
=={{header|Scala}}==
=={{header|Scala}}==
{{libheader|Scala}}
{{libheader|Scala}}
<syntaxhighlight lang=Scala>import java.awt.Color
<syntaxhighlight lang="scala">import java.awt.Color
import java.util.concurrent.{Executors, TimeUnit}
import java.util.concurrent.{Executors, TimeUnit}


Line 4,893: Line 4,894:
This is a direct translation of the Ruby/Tk example into Scheme + PS/Tk.
This is a direct translation of the Ruby/Tk example into Scheme + PS/Tk.


<syntaxhighlight lang=scheme>#!r6rs
<syntaxhighlight lang="scheme">#!r6rs


;;; R6RS implementation of Pendulum Animation
;;; R6RS implementation of Pendulum Animation
Line 4,968: Line 4,969:
=={{header|Scilab}}==
=={{header|Scilab}}==
The animation is displayed on a graphic window, and won't stop until it shows all positions calculated unless the user abort the execution on Scilab console.
The animation is displayed on a graphic window, and won't stop until it shows all positions calculated unless the user abort the execution on Scilab console.
<lang>//Input variables (Assumptions: massless pivot, no energy loss)
<syntaxhighlight lang="text">//Input variables (Assumptions: massless pivot, no energy loss)
bob_mass=10;
bob_mass=10;
g=-9.81;
g=-9.81;
Line 5,057: Line 5,058:
{{libheader|EaselSL}}
{{libheader|EaselSL}}
Using the [https://github.com/bethune-bryant/Easel Easel Engine for SequenceL] <br>
Using the [https://github.com/bethune-bryant/Easel Easel Engine for SequenceL] <br>
<syntaxhighlight lang=sequencel>import <Utilities/Sequence.sl>;
<syntaxhighlight lang="sequencel">import <Utilities/Sequence.sl>;
import <Utilities/Conversion.sl>;
import <Utilities/Conversion.sl>;
import <Utilities/Math.sl>;
import <Utilities/Math.sl>;
Line 5,131: Line 5,132:
=={{header|Sidef}}==
=={{header|Sidef}}==
{{trans|Perl}}
{{trans|Perl}}
<syntaxhighlight lang=ruby>require('Tk')
<syntaxhighlight lang="ruby">require('Tk')


var root = %s<MainWindow>.new('-title' => 'Pendulum Animation')
var root = %s<MainWindow>.new('-title' => 'Pendulum Animation')
Line 5,194: Line 5,195:


=={{header|smart BASIC}}==
=={{header|smart BASIC}}==
<syntaxhighlight lang=smart BASIC>'Pendulum
<syntaxhighlight lang="smart basic">'Pendulum
'By Dutchman
'By Dutchman
' --- constants
' --- constants
Line 5,237: Line 5,238:
{{works with|Tcl|8.5}}
{{works with|Tcl|8.5}}
==={{libheader|Tk}}===
==={{libheader|Tk}}===
<syntaxhighlight lang=tcl>package require Tcl 8.5
<syntaxhighlight lang="tcl">package require Tcl 8.5
package require Tk
package require Tk


Line 5,320: Line 5,321:
=={{header|VBScript}}==
=={{header|VBScript}}==
Well, VbScript does'nt have a graphics mode so this is a wobbly textmode pandulum. It should be called from cscript.
Well, VbScript does'nt have a graphics mode so this is a wobbly textmode pandulum. It should be called from cscript.
<syntaxhighlight lang=vb>
<syntaxhighlight lang="vb">
option explicit
option explicit


Line 5,371: Line 5,372:
{{libheader|DOME}}
{{libheader|DOME}}
{{libheader|Wren-dynamic}}
{{libheader|Wren-dynamic}}
<syntaxhighlight lang=ecmascript>import "graphics" for Canvas, Color
<syntaxhighlight lang="ecmascript">import "graphics" for Canvas, Color
import "dome" for Window
import "dome" for Window
import "math" for Math
import "math" for Math
Line 5,421: Line 5,422:


=={{header|XPL0}}==
=={{header|XPL0}}==
<syntaxhighlight lang=XPL0>include c:\cxpl\codes; \intrinsic 'code' declarations
<syntaxhighlight lang="xpl0">include c:\cxpl\codes; \intrinsic 'code' declarations


proc Ball(X0, Y0, R, C); \Draw a filled circle
proc Ball(X0, Y0, R, C); \Draw a filled circle
Line 5,459: Line 5,460:


=={{header|Yabasic}}==
=={{header|Yabasic}}==
<syntaxhighlight lang=Yabasic>clear screen
<syntaxhighlight lang="yabasic">clear screen
open window 400, 300
open window 400, 300
window origin "cc"
window origin "cc"
Line 5,490: Line 5,491:
{{trans|ERRE}}
{{trans|ERRE}}
In a real Spectrum it is too slow. Use the BasinC emulator/editor at maximum speed for realistic animation.
In a real Spectrum it is too slow. Use the BasinC emulator/editor at maximum speed for realistic animation.
<syntaxhighlight lang=zxbasic>10 OVER 1: CLS
<syntaxhighlight lang="zxbasic">10 OVER 1: CLS
20 LET theta=1
20 LET theta=1
30 LET g=9.81
30 LET g=9.81
Line 5,507: Line 5,508:
1010 CIRCLE bobx,boby,3
1010 CIRCLE bobx,boby,3
1020 RETURN</syntaxhighlight>
1020 RETURN</syntaxhighlight>



{{omit from|LFE}}
{{omit from|LFE}}
Line 5,513: Line 5,515:
{{omit from|PHP}}
{{omit from|PHP}}
{{omit from|SQL PL|It does not handle GUI}}
{{omit from|SQL PL|It does not handle GUI}}

[[Category:Animation]]