A Pen by Monica.dev on CodePen.
Created
August 25, 2023 14:15
-
-
Save M0nica/c696bef7e4b9330956041ca8ee386e02 to your computer and use it in GitHub Desktop.
Abstract Confetti Pattern - Click to Regenerate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let xSize; | |
let ySize; | |
let noiseX = 0.1; | |
let noisePos = 0.1; | |
function setup() { | |
createCanvas(windowWidth, windowHeight); | |
strokeCap(ROUND); | |
xSize = windowWidth; | |
ySize = windowHeight; | |
} | |
const colors = [ | |
"#ffadad", | |
"#ffd6a5", | |
"#fdffb6", | |
"#caffbf", | |
"#9bf6ff", | |
"#a0c4ff", | |
"#bdb2ff", | |
"#ffc6ff" | |
]; | |
function drawShape(x, y, xOffset, yOffset) { | |
const currentColor = random(colors); | |
fill(currentColor); | |
stroke(currentColor); | |
const shape = random(["circle", "line", "arc"]); | |
const rand = random(10); | |
if (shape == "circle") { | |
rand > 5 ? circle(x, y, 15) : circle(x + xOffset, y + yOffset, 15); | |
} else if (shape === "line") { | |
rand > 5 | |
? line(x, y, x + xOffset, y + yOffset) | |
: line(x + xOffset, y + yOffset, x, y); | |
} else if (shape === "arc") { | |
noFill(); | |
rand > 5 | |
? arc(x, y - 10, 50, 50, 0, HALF_PI) | |
: arc(x - 10, y, 50, 50, 0, HALF_PI); | |
} | |
} | |
function drawGrid() { | |
let xMargin = xSize * 0.01; | |
let yMargin = ySize * 0.01; | |
let scale = 0.001 * windowWidth; | |
for (let x = xMargin * 2; x < xSize - xMargin; x += 70) { | |
for (let y = yMargin * 2; y < ySize - xMargin; y += 70) { | |
strokeWeight(map(y, 0, xSize - xMargin, 4 * scale, 9 * scale)); | |
const xOffset = map(noise(noisePos + x + y), 0, 1, -35, 35); | |
let yOffset = map(noise(noiseX), 0, 1, 10, 20); | |
drawShape(x, y, xOffset, yOffset); | |
/* changing noise value doesn't matter since this is set to noLoop(); | |
*/ | |
// noisePos += 0.00001; | |
} | |
/* changing noise value doesn't matter since this is set to noLoop();*/ | |
// noiseX += 0.001; | |
} | |
} | |
function draw() { | |
clear(); | |
noLoop(); | |
background("#2b2135"); | |
drawGrid(); | |
} | |
function mousePressed() { | |
//redraw on mouse press or touch | |
redraw(); | |
} | |
function keyPressed() { | |
const SPACEBAR = " "; | |
// redraw on spacebar press | |
if (key == SPACEBAR) { | |
redraw(); | |
} | |
// save image of canvas | |
if (key === "s") { | |
saveCanvas("canvas"); | |
} | |
} | |
function windowResized() { | |
xSize = windowWidth; | |
ySize = windowHeight; | |
resizeCanvas(windowWidth, windowHeight); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
canvas { | |
/* center canvas in middle of page */ | |
position: absolute; | |
left: 50%; | |
top: 50%; | |
transform: translate(-50%, -50%); | |
height: 50%; | |
text-align: center; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment