You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.2 KiB

2 years ago
class Manager {
pendulums: Pendulum[] = []
2 years ago
timescale = 1;
gravity = 9.81;
playing = false;
2 years ago
static Size = 20;
2 years ago
constructor() {
p.colorMode(p.HSB, 100);
let count = 100;
2 years ago
for (let i = 0; i < count; i++){
let rad = i / count / 1e3 + p.PI * 1.05;
let hue = i / count * 100;
let color = p.color(hue, 100, 100);
this.pendulums.push(
new Pendulum([1, 1, 1, 1, 1, 1, 1, 1], [50, 50, 50, 50, 50, 50, 50, 100 + i / count / 10000], color)
2 years ago
);
}
p.colorMode(p.RGB);
}
init(){
// @ts-ignore
const {createApp} = Vue;
createApp({
data() {
return {
gravity: manager.gravity,
timescale: manager.timescale,
playingBtn: "play"
};
},
watch: {
gravity(newGravity: number) {
manager.gravity = newGravity;
},
timescale(newScale: number){
manager.timescale = newScale;
}
},
methods: {
togglePlay(){
manager.playing = !manager.playing;
this.playingBtn = manager.playing ? "pause" : "play";
}
},
name: "Simulation"
}).mount("#simulation");
createApp({
data(){
return {
segmentCount: 1,
maxSegmentCount: 30,
masses: [],
lengths: [],
startAngle: 90,
color: "#ffffff",
rainbow: false,
multiple: false,
pendulumCount: 10,
changeProperty: "angle",
changeAmount: 0.05,
changeIndex: 0
}
},
methods: {
add() {
},
resetMasses(){
for (let i = 0; i < this.maxSegmentCount; i++)
this.masses[i] = 1;
},
resetLengths() {
for (let i = 0; i < this.maxSegmentCount; i++)
this.lengths[i] = 1;
},
normalize(){
let L: [number] = this.lengths;
let sum = L.slice(0, this.segmentCount).reduce((p, n) => p + n);
let maxLength = Manager.Size / 2;
let factor = maxLength / sum;
for (let i = 0; i < this.segmentCount; i++)
this.lengths[i] *= factor;
}
},
mounted() {
this.resetMasses();
this.resetLengths();
},
name: "Preparation"
}).mount("#preparation");
2 years ago
}
update(){
if (this.playing) {
const h = this.timescale / Math.max(p.frameRate(), 1);
this.pendulums.forEach(p => p.update(h));
}
2 years ago
}
draw(){
p.push()
p.translate(p.width / 2, p.height / 2);
this.pendulums.forEach(p => p.draw());
2 years ago
p.pop();
}
}