xxxxxxxxxx
let vars = { s1: Math.PI / 2,
t1: 0,
u1: Math.PI / 6,
v1: 0,
s2: Math.PI / 4,
t2: 0,
u2: Math.PI / 2,
v2: 0,
m1: 40,
m2: 20,
l1: 120,
l2: 240,
g: 9.8 * 2 }
let gui
let parameter = {
month: 1,
monthMin: 1,
monthMax: 12,
day: 1,
dayMin: 1,
dayMax: 31,
hour: 0,
hourMin: 0,
hourMax: 23,
minute: 0,
minuteMin: 0,
minuteMax: 59,
realtime: true
}
const h = 0.0001
csc = x => 1 / Math.sin(x)
cot = x => 1 / Math.tan(x)
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL)
frameRate(60)
colorMode(HSB)
p1 = new Particle(0, 0, 0)
p2 = new Particle(0, 0, 0)
gui = createGui('Parameter')
gui.addObject(parameter)
gui.addGlobals('realtime')
}
function draw() {
//orbitControl()
background(0)
translate(0, -height / 2, 0)
scale(1, -1)
rotateY(frameCount / 96)
if (parameter.realtime) {
parameter.month = month()
parameter.day = day()
parameter.hour = hour()
parameter.minute = minute()
}
vars.m1 = map(parameter.month, 1, 12, 30, 120)
vars.m2 = map(parameter.day, 1, 31, 8, 80)
vars.l1 = map(parameter.hour, 0, 23, 400, 600)
vars.l2 = map(parameter.minute, 0, 59, 500, 800)
/*
vars.m1 = 30
vars.m2 = 8
vars.l1 = 400
vars.l2 = 500
*/
/*
vars.m1 = 80
vars.m2 = 40
vars.l1 = 600
vars.l2 = 800
*/
//Declare xyz values for each of the pendulums
let x1 = (vars.l1 * Math.sin(vars.s1) * Math.cos(vars.u1))
let z1 = (vars.l1 * Math.sin(vars.s1) * Math.sin(vars.u1))
let y1 = (-vars.l1 * Math.cos(vars.s1))
let x2 = (x1 + vars.l2 * Math.sin(vars.s2) * Math.cos(vars.u2))
let z2 = (z1 + vars.l2 * Math.sin(vars.s2) * Math.sin(vars.u2))
let y2 = (y1 - vars.l2 * Math.cos(vars.s2))
pendulum(x1, y1, z1, x2, y2, z2)
p1.update(x1, y1, z1, vars.m1, frameCount + 90)
p2.update(x2, y2, z2, vars.m2, frameCount + 270)
p1.show(8)
p2.show(24)
for (let r = 0; r < 1200; r++) {
simul()
}
}
class Particle {
constructor(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
this.history = []
this.size = []
this.h = []
}
update(x, y, z, size, h) {
this.x = x;
this.y = y;
this.z = z;
// WIGGLY PARTICLES IF BALLS (LOOKS KINDA COOL)
// this.x = this.x + random(-size / 2, size / 2);
// this.y = this.y + random(-size / 2, size / 2);
// this.y = this.y + random(-size / 2, size / 2);
let v = createVector(this.x, this.y, this.z);
this.history.push(v);
// this.size.push(random(size / 10, size / 50))
this.h.push(h)
//console.log(this.history.length);
if (this.history.length > 600) {
this.history.splice(0, 1);
this.h.splice(0, 1)
// this.size.splice(0, 1)
}
}
show(w) {
push()
beginShape();
for (let i = 0; i < this.history.length; i++) {
let pos = this.history[i];
let cr = color(this.h[i] % 360, 100, 100)
noFill()
stroke(cr);
strokeWeight(w);
/*
push()
translate(pos.x, pos.y, pos.z);
sphere(this.size[i])
pop()
*/
vertex(pos.x, pos.y, pos.z)
}
endShape();
pop()
}
}