Movement Of Particles
This is the project which i have not shared with my YouTube Community so let's start and see how to build it..This is a VIP Project
1. Open P5.js Editor
STEP 1- Go to google.com and search p5.js and click on the first option.
STEP 2-Inside that option click on Home.
STEP 3-Then Click Start creating with p5 editor.
2. Create a New Project
Code:
let bugs = []; // array of Jitter objects
function setup() { createCanvas(710, 400); // Create objects for (let i = 0; i < 50; i++) { bugs.push(new Jitter()); }}
function draw() { background(50, 89, 100); for (let i = 0; i < bugs.length; i++) { fill("purple"); bugs[i].move(); bugs[i].display(); }}
// Jitter classclass Jitter { constructor() { this.x = random(width); this.y = random(height); this.diameter = random(10, 30); this.speed = 1; }
move() { this.x += random(-this.speed, this.speed); this.y += random(-this.speed, this.speed); }
display() { ellipse(this.x, this.y, this.diameter, this.diameter); }}
let bugs = []; // array of Jitter objects
function setup() {
createCanvas(710, 400);
// Create objects
for (let i = 0; i < 50; i++) {
bugs.push(new Jitter());
}
}
function draw() {
background(50, 89, 100);
for (let i = 0; i < bugs.length; i++) {
fill("purple");
bugs[i].move();
bugs[i].display();
}
}
// Jitter class
class Jitter {
constructor() {
this.x = random(width);
this.y = random(height);
this.diameter = random(10, 30);
this.speed = 1;
}
move() {
this.x += random(-this.speed, this.speed);
this.y += random(-this.speed, this.speed);
}
display() {
ellipse(this.x, this.y, this.diameter, this.diameter);
}
}
0 Comments