Processing
電子アートを書くための言語。
code:hanabi.js
class Circle {
constructor(rad, x0, y0) {
this.t = 0;
this.x = 0; this.y = 0;
this.x0 = x0; this.y0 = y0;
this.v0 = 100;
this.v_x = this.v0 * Math.cos(rad);
this.v_y = this.v0 * Math.sin(rad);
}
render() {
this.t = this.t + 1 / 60;
this.x = this.x0 + this.v_x * this.t;
this.y = this.y0 - this.v_y * this.t + (1 / 2) * 9.8 * (this.t ** 2) * 100;
ellipse(this.x, this.y, 5, 5);
}
}
let circles = [];
function setup() {
createCanvas(400, 400);
}
function draw() {
background(0);
if (mouseIsPressed)
circles.map(circle => circle.render());
if (Math.floor(millis() / 100) % 10 === 0) {
circles = circles.filter(circle =>
circle.x > 0 &&
circle.x < width &&
circle.y > 0 &&
circle.y < height);
}
}