xxxxxxxxxx
270
let letters = [];
let possibleChars;
let targInd;
let doneInd;
let doneTimer;
let doneTimerInit;
let doneTimerSpeed;
let doneLinesToClear;
let xPos, yPos;
let howManyX, howManyY;
function preload() {
done = false;
xPos = 0;
yPos = 0;
possibleChars = [
".",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z",
"!",
"#",
"@",
"$",
"%",
"^",
"&",
"*",
"_",
"+",
"+",
"-",
"~",
"/",
"?",
">",
"<",
".",
";",
":",
"'",
"`",
"ß",
"ē",
","
]
}
function setup() {
createCanvas(windowWidth, windowHeight);
howManyX = width / 30;
howManyY = height / 30;
xPos = -20;
yPos = -20;
for (let i = 0; i < floor(howManyY); i++) {
yPos += (height / howManyY);
// print(yPos);
for (let j = 0; j < howManyX; j++) {
xPos += (windowWidth / howManyX);
letters.push(new letter(xPos, yPos));
}
xPos = -20;
}
textAlign(CENTER, CENTER)
noStroke();
targInd = 5;
//doneTimerSpeed = 200;
dontTimerInit = false;
doneInd = 0;
doneLinesToClear = 1;
}
function draw() {
background(20);
fill(235);
for (let index = 0; index < letters.length; index++) {
letters[index].update();
letters[index].display();
}
for (let index = 0; index < letters.length; index++) {
if (letters[index].distFromTarg != 0) {
done = false;
break;
}
done = true;
}
if (done) {
if (!doneTimerInit) {
doneTimer = millis();
doneTimerInit = true;
}
//if (millis() > doneTimer) {
doneTimer += doneTimerSpeed;
//doneTimer += 100;
for (let index = 0; index < doneLinesToClear; index++) {
if (doneInd < letters.length - 1) {
letters[doneInd].ch = " ";
doneInd++;
}
}
letters[doneInd].ch = "-";
doneInd++;
if (frameCount % 10 == 0) {
doneLinesToClear++;
}
//}
if (doneInd > letters.length - 1) {
reset();
}
}
textSize(12);
}
function reset() {
done = false;
if (random(10) < 5) {
doneLinesToClear = 4;
}
targInd = floor(random(possibleChars.length));
if (random(10) < 3.5) {
targInd = 0;
}
for (let index = 0; index < letters.length; index++) {
letters[index].index = floor(random(possibleChars.length));
}
doneInd = 0;
doneTimer = 0;
doneTimerSpeed = 1000;
doneTimerInit = false;
}
class letter {
constructor(tx, ty) {
this.x = tx;
this.y = ty;
// this.ch = random(possibleChars);
this.index = floor(random(possibleChars.length));
this.ch = possibleChars[this.index];
this.timer;
this.speed;
this.distFromMouse;
//this.timer = map(this.distFromTarg, 0, possibleChars.length - 1, 800, 10);
this.timer = 500;
}
update() {
// let p = createVector(this.x, this.y);
// let m = createVector(mouseX, mouseY);
if (millis() > this.timer) {
//let xDist = abs(mouseX, this.x);
//let yDist = abs(mouseY, this.y);
//this.distFromMouse = (xDist + yDist) / 2;
// this.distFromMouse = dist(p, m);
this.distFromTarg = abs(targInd - this.index);
//this.timer += map(this.distFromMouse, 0, 500, 5, 1500);
//this.timer += map(this.distFromTarg, 10, 0, 100, 250);
this.timer += random(200);
if (this.distFromTarg != 0) {
this.index++;
}
if (this.index > possibleChars.length - 1) {
this.index = 0;
}
if (!done) {
this.ch = possibleChars[this.index];
}
}
}
display() {
if (this.distFromTarg == 0) {
fill(150);
} else {
fill(250);
}
text(this.ch, this.x, this.y);
}
}