Use all of your p5js coding abilities write a p5js code animation generative all…
- User
Use all of your p5js coding abilities write a p5js code animation generative all changing artwork with seemless animated transitions of colors, all beautifully coded and layers of changing loop and complexity of petterns shapes and organized psychedelic geometric p5js algorithmic art animation even more geometric algorithmic layers and organized variables of psychedelic art, algorthmic symmetrical fractal animation loops visuals like a music visual visualizer but just with plain p5js now i need a lot of organized step by step moving of shapes and in algorithmic pattern following grid like movement, more psychedelic pattern and shapes, kalaedoscopic visualizer, mirror effect shiny light art, colorfull colors and 2d geometric aglorithmic shapes and visualizer randoms
- Assistant
Certainly! Below is a p5.js code that creates a psychedelic, kaleidoscopic, geometric, algorithmic art animation with seamless color transitions and patterns. The animation features symmetrical fractal loops, mirror effects, and dynamically changing shapes and colors. I've included comments to explain the code step by step.
function setup() { createCanvas(windowWidth, windowHeight); angleMode(DEGREES); // Use degrees for angles noStroke(); // Remove stroke for shapes } function draw() { background(0, 20); // Semi-transparent background for trail effect translate(width / 2, height / 2); // Move origin to canvas center let time = frameCount * 0.02; // Time variable for animation speed let numSymmetry = 12; // Number of symmetrical segments let layers = 10; // Number of layers/depth of shapes for (let i = 0; i < layers; i++) { push(); rotate(time * (i + 1)); // Rotate each layer differently let size = map(sin(time + i * 10), -1, 1, 50, 200); // Dynamic size let sides = floor(map(cos(time / 2 + i * 5), -1, 1, 3, 8)); // Dynamic number of sides // Dynamic color based on time and layer fill( map(sin(time + i), -1, 1, 0, 255), map(cos(time * 1.5 + i), -1, 1, 0, 255), map(sin(time * 2 + i), -1, 1, 0, 255), 150 ); for (let j = 0; j < numSymmetry; j++) { push(); rotate((360 / numSymmetry) * j); // Rotate to create symmetry polygon(0, 0, size, sides); // Draw the polygon pop(); } pop(); } } // Function to draw a regular polygon function polygon(x, y, radius, npoints) { let angle = 360 / npoints; beginShape(); for (let a = 0; a <= 360; a += angle) { let sx = x + cos(a) * radius; let sy = y + sin(a) * radius; vertex(sx, sy); } endShape(CLOSE); }Explanation of the Code:
-
Setup Function:
createCanvas(windowWidth, windowHeight);sets the canvas size to the full window size.angleMode(DEGREES);changes the angle mode to degrees for easier handling of rotations.noStroke();removes the outline stroke from the shapes to focus on fills.
-
Draw Function:
background(0, 20);sets a black background with low opacity to create a fading trail effect.translate(width / 2, height / 2);moves the origin to the center of the canvas.- Variables
numSymmetryandlayerscontrol the complexity and depth of the pattern. - The loop over
layerscreates multiple layers of shapes, each with its own rotation, size, and number of sides. - Inside the layers loop, another loop over
numSymmetrycreates symmetrical repetitions of the shapes by rotating them around the center. - The
fill()function uses sine and cosine functions to create smoothly transitioning RGB color values over time. - The
polygon()function draws regular polygons based on the given number of sides.
-
Polygon Function:
- Draws a regular polygon centered at
(x, y)with a givenradiusandnpoints(number of sides). - Calculates the angle between vertices and uses trigonometry to find each vertex position.
- Draws a regular polygon centered at
How to Run the Code:
- Go to the p5.js online editor.
- Create a new sketch or open an existing one.
- Copy and paste the entire code into the editor.
- Click the play button to run the animation.
- For the best experience, view in full-screen mode.
Customization:
-
Adjusting Complexity:
- Increase
numSymmetryfor more symmetrical segments. - Increase
layersfor more depth and complexity.
- Increase
-
Changing Colors:
- Modify the sine and cosine functions inside the
fill()function to experiment with different color transitions.
- Modify the sine and cosine functions inside the
-
Experiment with Shapes:
- Change the mapping ranges for
sidesto include higher numbers for polygons. - Modify the
sizecalculations for different scaling effects.
- Change the mapping ranges for
Enjoy the mesmerizing, ever-changing psychedelic visuals! 🌀🎨
-