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.

99 lines
2.5 KiB

2 years ago
class Manager {
pendulums: Pendulum[] = []
2 years ago
timescale = 1;
gravity = 9.81;
playing = false;
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,
masses: [],
lengths: [],
startAngle: 90,
color: "#ffffff",
rainbow: false,
multiple: false,
pendulumCount: 10,
changeProperty: "angle",
changeAmount: 0.05,
changeIndex: 0
}
},
methods: {
add() {
},
},
mounted() {
for (let i = 0; i < 20; i++){
this.masses.push(1);
this.lengths.push(1);
}
},
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();
}
}