p5.disableFriendlyErrors = true;
grotesk = loadFont('grotesk.otf');
createCanvas(windowWidth, windowHeight);
speechRec = new p5.SpeechRec('en-US');
speechRec.continuous = true;
speechRec.interimResults = false;
speechRec.onResult = gotSpeech;
speechRec.onError = error
textArr = grotesk.textToPoints("Words in the wind", 50, height / 2, fontSize, {
flow = new Flowfield(15);
for (var i = 0; i < textArr.length; i++) {
var a = new Agent(textArr[i].x, textArr[i].y);
background(150, 30, 240, 15);
if (agents.length == 0) {
const msg = speechRec.resultString.split(" ")[0];
let cWidth = textWidth(msg);
textArr = grotesk.textToPoints(msg, (width - cWidth) / 4, height / 2, fontSize, {
for (var i = 0; i < textArr.length; i++) {
var a = new Agent(textArr[i].x, textArr[i].y);
background(250, 250, 255, 25);
for (var agent of agents) {
constructor(x = random(width), y = random(height)) {
this.position = createVector(x, y);
this.velocity = createVector(0, 0);
this.acceleration = createVector(0, 0);
randomizeColor(r = 255, g = 255, b = 255) {
this.r = constrain(random(this.r - 5, this.r + 5), 0, 255);
this.g = constrain(random(this.g - 5, this.g + 5), 0, 255);
this.b = constrain(random(this.b - 5, this.b + 5), 0, 255);
fill(this.r, this.g, this.b, this.life);
agents.splice(agents.indexOf(this), 1);
translate(this.position.x, this.position.y);
rotate(random(0, TWO_PI));
triangle(4, 0, -4, 0, 0, 4);
if (this.position.x < 0 || this.position.x > width || this.position.y < 0 || this.position.y > height) {
agents.splice(agents.indexOf(this), 1);
this.acceleration.add(force);
var desired = flow.lookup(this.position);
desired.mult(this.maxSpeed);
var steer = p5.Vector.sub(desired, this.velocity);
steer.limit(this.maxForce);
this.velocity.add(this.acceleration);
this.velocity.limit(this.maxspeed);
this.position.add(this.velocity);
this.acceleration.set(0, 0);
constructor(resolution = 10) {
this.resolution = resolution;
this.rows = height / this.resolution;
this.cols = width / this.resolution;
for (var i = 0; i < this.cols; i++) {
for (var j = 0; j < this.rows; j++) {
var theta = map(noise(xoff, yoff, this.zoff), 0, 1, 0, TWO_PI);
this.field[i][j] = createVector(cos(theta), sin(theta));
var col = Math.floor(constrain(v1.x / this.resolution, 0, this.cols - 1));
var row = Math.floor(constrain(v1.y / this.resolution, 0, this.rows - 1));
return this.field[col][row].copy();
for (var i = 0; i < this.cols; i++) {
for (var j = 0; j < this.rows; j++) {
var x = i * this.resolution + this.resolution / 2;
var y = j * this.resolution + this.resolution / 2;
rotate(this.field[i][j].heading());