Created
March 9, 2020 13:34
-
-
Save Nekodigi/5dd0f1a11d189df3ca97f22dfd1ccfdb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| float g = 9.8;//accelaration of gravity | |
| ArrayList<Pendulum> pendulums = new ArrayList<Pendulum>(); | |
| float Tmax = 2000; | |
| float k = 20; | |
| void setup(){ | |
| //fullScreen(); | |
| size(1000, 1000); | |
| colorMode(HSB, 360, 100, 100); | |
| strokeWeight(1); | |
| for(float n = 1; n < 50; n++){ | |
| pendulums.add(new Pendulum(g*pow(Tmax/TWO_PI/(k + n + 1), 2), HALF_PI/2)); | |
| } | |
| } | |
| void draw(){ | |
| background(360); | |
| translate(width/2, 0); | |
| float t = float(frameCount); | |
| float n = pendulums.size(); | |
| fill(0); | |
| for(float i = 0; i < n; i++){ | |
| Pendulum pendulum = pendulums.get((int)i); | |
| pendulum.show(t); | |
| } | |
| } | |
| class Pendulum{ | |
| float l; | |
| float maxTheta; | |
| Pendulum(float l, float maxTheta){ | |
| this.l = l; | |
| this.maxTheta = maxTheta; | |
| } | |
| void show(float t){ | |
| float theta = maxTheta*sin(sqrt(g/l)*t); | |
| float x = sin(theta)*l; | |
| float y = cos(theta)*l; | |
| line(0, 0, x, y); | |
| ellipse(x, y, 50, 50); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment