xxxxxxxxxx
241
let tileSize = 100; // Size of each tile
let colors;
let lastPattern = -1; // To avoid pattern repetition
function setup() {
createCanvas(800, 800);
background(0); // Set background to black
noLoop();
colors = [
color(230, 57, 0), // Dark Red
color(255, 132, 0), // Vibrant Orange
color(87, 167, 173), // Turquoise
color(249, 168, 37), // Bright Yellow/Gold
color(0, 51, 102), // Deep Blue
color(50, 25, 0), // Brown/Black
];
}
function draw() {
for (let y = 0; y < height; y += tileSize) {
let shouldBeHorizontal = random() < 0.3; // 30% chance for horizontal streaks
if (shouldBeHorizontal) {
let pattern = getRandomPattern();
let accent = random(colors);
drawHorizontalPattern(0, y, width, tileSize, pattern, accent);
} else {
for (let x = 0; x < width; x += tileSize) {
drawTile(x, y, tileSize);
}
}
}
}
// To avoid consecutive pattern repetition
function getRandomPattern() {
let newPattern = int(random(4));
while (newPattern === lastPattern) {
newPattern = int(random(4));
}
lastPattern = newPattern;
return newPattern;
}
// Draw a single tile at (x, y) with size tileSize
function drawTile(x, y, size) {
let chosenPattern = getRandomPattern(); // Ensure no repetition
let backgroundColor = random(colors); // Pick a random color for the background
let accent = random(colors); // Pick a random color for the line accents
// Randomly decide whether to give the tile a background color
let hasBackground = random() < 0.5; // 50% chance for a background
if (hasBackground) {
// Ensure background and pattern colors don't clash (different brightness levels)
let backgroundBrightness = brightness(backgroundColor);
let accentBrightness = brightness(accent);
// If they are too close in brightness, adjust the accent color
while (abs(backgroundBrightness - accentBrightness) < 20) {
accent = random(colors);
accentBrightness = brightness(accent);
}
fill(backgroundColor);
noStroke();
rect(x, y, size, size); // Draw a filled rectangle to serve as the tile background
}
noFill(); // Switch to no fill for the shape work
stroke(accent);
strokeWeight(2);
switch (chosenPattern) {
case 0:
drawSpiralTriangles(x, y, size, accent);
break;
case 1:
drawSwirlingCircles(x, y, size, accent);
break;
case 2:
drawNestedSquares(x, y, size, accent);
break;
case 3:
drawSwirl(x, y, size, accent);
break;
}
}
// Draw fractal spiral triangles pattern
function drawSpiralTriangles(x, y, size, accent) {
stroke(accent);
noFill();
recursiveTriangle(x, y, size, 5); // Calls the recursive function for triangle drawing
}
function recursiveTriangle(x, y, size, depth) {
if (depth == 0) return;
// Draw outer triangle
let half = size / 2;
triangle(x, y, x + size, y, x + half, y + size);
// Recursively draw smaller triangles inside
recursiveTriangle(x, y, size / 2, depth - 1); // Top-left
recursiveTriangle(x + half / 2, y + size / 2, size / 2, depth - 1); // Center
recursiveTriangle(x + half, y, size / 2, depth - 1); // Top-right
}
// Enhanced Circles with more swirls
function drawSwirlingCircles(x, y, size, accent) {
stroke(accent);
let half = size / 2;
let steps = 12; // More swirls
let radius = size / 2;
for (let i = 0; i < steps; i++) {
let angle = map(i, 0, steps, 0, TWO_PI);
let r = radius * (i / steps); // Increasing radius for swirls
let xPos = x + half + cos(angle) * r;
let yPos = y + half + sin(angle) * r;
ellipse(xPos, yPos, r * 2, r * 2); // Draw concentric swirling circles
}
}
// Enhanced nested squares pattern
function drawNestedSquares(x, y, size, accent) {
stroke(accent);
noFill();
let steps = 5; // Number of nested squares
let stepSize = size / steps;
for (let i = 0; i < steps; i++) {
rect(x + i * stepSize / 2, y + i * stepSize / 2, size - i * stepSize, size - i * stepSize);
}
}
// Horizontal Patterns
function drawHorizontalPattern(x, y, width, size, pattern, accent) {
let hasBackground = random() < 0.5; // Randomly decide if this horizontal pattern has a background
if (hasBackground) {
let backgroundColor = random(colors);
let backgroundBrightness = brightness(backgroundColor);
let accentBrightness = brightness(accent);
// Adjust the accent color if it's too close to the background color
while (abs(backgroundBrightness - accentBrightness) < 20) {
accent = random(colors);
accentBrightness = brightness(accent);
}
fill(backgroundColor);
noStroke();
rect(x, y, width, size); // Set background for horizontal pattern
}
noFill(); // No fill for shapes
stroke(accent);
strokeWeight(2);
switch (pattern) {
case 0:
drawHorizontalSpiralTriangles(x, y, width, size, accent);
break;
case 1:
drawHorizontalSwirlingCircles(x, y, width, size, accent);
break;
case 2:
drawHorizontalNestedSquares(x, y, width, size, accent);
break;
case 3:
drawHorizontalSwirl(x, y, width, size, accent);
break;
}
}
function drawHorizontalSpiralTriangles(x, y, width, size, accent) {
stroke(accent);
noFill();
let step = size;
for (let i = x; i < x + width; i += step) {
recursiveTriangle(i, y, step, 5); // Spiral triangles across the row
}
}
// Horizontal swirling circles
function drawHorizontalSwirlingCircles(x, y, width, size, accent) {
stroke(accent);
let step = size;
for (let i = x; i < x + width; i += step) {
drawSwirlingCircles(i, y, step, accent); // Reuse swirling circle function
}
}
// Horizontal nested squares
function drawHorizontalNestedSquares(x, y, width, size, accent) {
stroke(accent);
let step = size;
for (let i = x; i < x + width; i += step) {
drawNestedSquares(i, y, step, accent); // Reuse nested squares function
}
}
// Swirl (Harmonic Motion) in vertical and horizontal
function drawSwirl(x, y, size, accent) {
stroke(accent);
noFill();
strokeWeight(2);
let steps = 50;
let freq = 0.1;
let amplitude = size / 3;
beginShape();
for (let i = 0; i <= steps; i++) {
let angle = map(i, 0, steps, 0, TWO_PI * 2);
let xOffset = x + size / 2 + cos(angle) * i * 2;
let yOffset = y + size / 2 + sin(angle) * amplitude * sin(freq * i);
vertex(xOffset, yOffset);
}
endShape();
}
function drawHorizontalSwirl(x, y, width, size, accent) {
stroke(accent);
noFill();
strokeWeight(2);
let steps = 50;
let freq = 0.1;
let amplitude = size / 3;
beginShape();
for (let i = 0; i <= steps; i++) {
let angle = map(i, 0, steps, 0, TWO_PI * 2);
let xOffset = x + width / 2 + cos(angle) * i * 2;
let yOffset = y + size / 2 + sin(angle) * amplitude * sin(freq * i);
vertex(xOffset, yOffset);
}
endShape();
}