xxxxxxxxxx
let cols, rows;
let initialScl = 80; // Initial scale
let scl = initialScl; // Starting scale
let w, h;
let zoff = 0;
let flowfield;
let zCount = 0; // Counter for "z" key presses
let maxThickness = 1; // Maximum thickness of lines
let hueOffset = 0; // Hue offset for color variation
let interestingTexts = ["Zeynep", "World", "Amazing", "Art", "Generative", "Code", "Creative", "Design", "Colorful", "Abstract"];
let textIndex = 0;
let displayTexts = false; // Flag to control text display
function setup() {
createCanvas(800, 1000);
colorMode(HSB, 255);
w = width;
h = height;
updateFlowField();
}
function draw() {
background(255); // Clear the background each frame
let yoff = 0;
for (let y = 0; y < rows; y++) {
let xoff = 0;
for (let x = 0; x < cols; x++) {
let index = x + y * cols;
let angle = noise(xoff, yoff, zoff) * TWO_PI * 4;
let v = p5.Vector.fromAngle(angle);
v.setMag(0.5);
flowfield[index] = v;
xoff += 0.1;
// Update stroke to use darker colors
stroke((map(angle, 0, TWO_PI, 0, 255) + hueOffset) % 255, 200, 150, 100);
strokeWeight(map(zCount, 0, 18, 1, maxThickness)); // Increase thickness with z presses
push();
translate(x * scl, y * scl);
rotate(v.heading());
line(0, 0, scl, 0);
pop();
}
yoff += 0.1;
}
zoff += 0.01; // Increment zoff to animate
// Draw the interesting text if displayTexts is true
if (displayTexts && textIndex > 0) {
fill(255); // Set text color to white
textSize(32);
textAlign(CENTER, CENTER);
for (let i = 0; i < textIndex; i++) {
text(interestingTexts[i % interestingTexts.length], random(width), random(height));
}
}
}
function keyPressed() {
if (key == 's' || key == 'S') saveCanvas('flowfield', 'png');
if (key == 'z' || key == 'Z') {
zCount++;
if (zCount <= 18) {
scl = max(scl - 4, 2); // Decrease scl but not below 2
maxThickness += 1; // Increase maximum thickness
hueOffset += 14; // Change hue offset for color variation
updateFlowField();
} else {
// Reset all values to their initial state
zCount = 0;
scl = initialScl;
maxThickness = 1;
hueOffset = 0;
updateFlowField();
}
}
if (key == 'a' || key == 'A') {
textIndex++;
displayTexts = true; // Enable text display
}
if (key == 'x' || key == 'X') {
displayTexts = false; // Disable text display
}
}
function updateFlowField() {
cols = floor(w / scl);
rows = floor(h / scl);
flowfield = new Array(cols * rows);
}