xxxxxxxxxx
87
// pi scribble by aeon martinez
/*
the vehicle, called the scribbler, will draw a path based on the digits of pi!
of course, i had to make this path rainbow colored. feel free to turn showGrid on
to see how it works. or change the path length for a different effect.
*/
friction = 0.03;
let littlePi;
let bigPi;
let piDigits = [];
let positions = [];
let showGrid = false;
let showScribbler = true;
let gridSize = 30;
let index = 0;
let pathLength = 1000;
function preload() {
//littlePi = loadStrings("pi one thousand.txt");
littlePi = loadStrings("pi one million.txt");
}
function setup() {
createCanvas(400, 400);
piDigits = int(littlePi[0].split(""));
piTarget = new Target(width / 2, height / 2);
scribbler = new Vehicle(0, 0, 8, 15, 0.3);
}
function draw() {
colorMode(HSB);
background(index % 360, 100, 25);
if (showGrid == true) {
noStroke(); fill(100);
textAlign(LEFT, CENTER);
text("targetting: " + piDigits[index] + ", " + piDigits[index + 1], 63, 355)
}
positions.push(scribbler.pos.copy());
translate(gridSize * 0.5 + 50, height - gridSize * 0.5 - 50);
scale(1, -1);
stroke(0, 100, 50, 25); strokeWeight(2); fill(25);
if (showGrid == true) {
for (j = 0; j < 10; j++) {
for (i = 0; i < 10; i++) {
point(i * gridSize, j * gridSize);
}
}
}
if (showGrid == true) {
stroke(50, 80, 100);
circle(piDigits[index] * gridSize, piDigits[index + 1] * gridSize, 8);
}
piTarget.reposition(
piDigits[index] * gridSize,
piDigits[index + 1] * gridSize
);
scribbler.move();
if (showScribbler == true) scribbler.show(color(255));
scribbler.applyForce(scribbler.beeline(piTarget.pos));
noFill(); stroke(index % 360, 75, 100); strokeWeight(2);
beginShape();
for (let pt of positions) {
vertex(pt.x, pt.y);
}
endShape();
if (scribbler.reached(piTarget)) {
index += 2;
}
if (index > piDigits.length) {
index = 0;
}
if (positions.length > pathLength) {
positions.splice(0, 1);
}
}