In this tutorial, you will learn how to create a dynamic and colorful geometric animation using p5.js. This animation symbolizes the idea that "the world is full of fabulous and incredible people doing wonderful things." The shapes will move randomly across the canvas, changing colors and creating a visually captivating effect.
Download p5.js:
Create a New Project:
Let’s start by setting up the basic structure of our p5.js sketch. This includes defining the setup() and draw() functions.
function setup() { createCanvas(windowWidth, windowHeight); noStroke(); // Disable stroke for the shapes } function draw() { background(30, 30, 60, 25); // Dark background with transparency }
Explanation:
createCanvas(windowWidth, windowHeight);: This sets the canvas size to match your browser window.
noStroke();: This removes the border from the shapes we will create.
background(30, 30, 60, 25);: This sets the background color to a dark blue with some transparency, creating a trailing effect for the shapes.
Now, let’s add the code to create random shapes with varying colors, positions, and sizes.
function draw() { background(30, 30, 60, 25); // Dark background with transparency for (let i = 0; iExplanation:
Randomized Variables:
Shape Types:
To make sure the canvas resizes with the window, add the following function:
function windowResized() { resizeCanvas(windowWidth, windowHeight); }
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3