xxxxxxxxxx
var word = "SPLASH!";
var wordSize = 100;
var speedToTriggerDynState = 3;
var splitCount = 3;
var minHue = 115;
var maxHue = 150;
var currentHue = minHue;
var font;
var particles = [];
function preload() {
font = loadFont("AvenirNextLTPro-Demi.otf");
}
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 255);
reset();
}
function draw() {
background(0, 100);
for (let i = particles.length - 1; i > -1; i--) {
particles[i].move();
stroke(particles[i].color);
strokeWeight(particles[i].size);
point(particles[i].pos.x, particles[i].pos.y);
if (particles[i].pos.y > height || particles[i].pos.x < 0 || particles[i].pos.x > width) {
particles.splice(i, 1);
}
}
}
function mouseClicked() {
reset();
}
function reset() {
background(0);
particles = [];
let spawnPoints = font.textToPoints(word, width / 2, height / 2, wordSize, {sampleFactor: 0.6});
spawnPoints.sort((pnt1, pnt2) => (pnt1.x > pnt2.x) ? 1 : -1);
let firstPoint = spawnPoints[0];
let lastPoint = spawnPoints[spawnPoints.length - 1];
let wordHalfWidth = (lastPoint.x - firstPoint.x) / 2.0;
for (let i = 0; i < spawnPoints.length; i++) {
let x = spawnPoints[i].x - wordHalfWidth;
let y = spawnPoints[i].y;
let newParticle = new Particle(x, y, 1);
newParticle.setTarget(x, y);
particles.push(newParticle);
}
}