xxxxxxxxxx
42
let font;
let particles = [];
const text = 'Slow';
const size = 150;
let bounds;
function preload() {
font = loadFont('sunshine.otf');
}
function setup() {
createCanvas(800, 400);
frameRate(50);
colorMode(HSB, 255);
textFont(font);
textAlign(CENTER, BASELINE);
var pts = font.textToPoints(text, 0, 0, size, {
sampleFactor: 0.3,
simplifyThreshold: 0
});
bounds = font.textBounds(text, 0, 0, size);
for (var pt of pts){
particles.push(new Particle(pt.x + width/2 - bounds.w/2, pt.y + height/2 + bounds.h/4));
}
}
function draw() {
background(255);
for(var particle of particles){
particle.show();
particle.update();
particle.seek();
particle.fear();
}
}
function mousePressed(){
for(var particle of particles){
particle.speed.x = random(-20, 20);
particle.speed.y = random(-20, 20);
}
}