xxxxxxxxxx
54
class FlowText {
constructor() {
this.v_up = 1.0;
this.life = false;
this.y = 0.0;
this.x = 0.0;
}
draw() {
if (this.life == true) {
text(this.message, this.x, this.y);
}
this.y = this.y - this.v_up;
if (this.y < 0) {
this.y = mouseY;
this.life = false;
}
}
setText(_message) {
this.message = _message;
}
activate() {
this.life = true;
this.y = mouseY;
this.x = mouseX;
}
}
var flowtext = [];
function setup() {
createCanvas(400, 400);
for (var i = 0; i < 50; i++) {
flowtext[i] = new FlowText();
}
}
function draw() {
background(220);
for (var i = 0; i < flowtext.length; i++) {
flowtext[i].draw();
}
}
function keyPressed() {
if (key == " ") {
for (var i = 0; i < flowtext.length; i++) {
if (flowtext[i].life == false) {
flowtext[i].setText("Hello");
flowtext[i].activate();
i = flowtext.length;
}
}
}
}