xxxxxxxxxx
75
class Wave {
constructor(period, phase, amplitude) {
this.period = period;
this.phase = phase;
this.phaseA = 0.0000001;
this.phaseV = 0.0001;
this.amplitude = amplitude;
this.positions = [];
this.r = 5;
this.total = floor(width / (this.r * 2));
for (let i = 0; i < this.total; i++) {
this.positions[i] = map(i, 0, this.total, 0, width);
}
}
display() {
translate(0, 300);
stroke(255);
fill(252, 0, 200);
for (let x of this.positions) {
let y = sin(((TWO_PI*x)/this.period)+this.phase) * this.amplitude;
circle(x, y, this.r * 2);
line(x, 0, x, y);
this.phase += this.phaseV;
}
}
}
class Circle {
constructor() {
this.dots = [];
this.r = 200;
for (let theta=0; theta<=TWO_PI; theta+=TWO_PI/60) {
let x = cos(theta) * this.r;
let y = sin(theta) * this.r;
this.dots.push(createVector(x, y));
}
}
display() {
stroke(255);
noFill();
for (let dot of this.dots) {
circle(dot.x, dot.y, 10);
}
}
}
let wave;
let mainCircle;
function setup() {
createCanvas(600, 600);
mainCircle = new Circle();
// wave = new Wave(300, 0, 200);
}
function draw() {
background(0);
translate(width/2, height/2);
mainCircle.display();
// wave.display();
}