Learn p5.Js - Animation Cheatsheet - Codecademy
Learn p5.Js - Animation Cheatsheet - Codecademy
Animation
Incrementing Values
x++;
or
x += 1;
https://www.codecademy.com/learn/learn-p5js/modules/p5js-animation/cheatsheet 1/5
08/11/2024, 14:16 Learn p5.js: Animation Cheatsheet | Codecademy
circle(randomX, height / 2,
randomSize);
}
FPS
https://www.codecademy.com/learn/learn-p5js/modules/p5js-animation/cheatsheet 2/5
08/11/2024, 14:16 Learn p5.js: Animation Cheatsheet | Codecademy
p5.js will automatically run your code at 60 frames per function setup() {
second. However, you can manipulate the FPS value by
createCanvas(400, 400);
using the frameRate() function, which will change the
number of frames shown per second. The maximum // Set frame rate to 24 FPS, which will
number of frames that can be drawn is 60 FPS. make the sketch run at a slower rate than
the default 60 FPS
frameRate(24);
}
Decrementing Values
x--;
or
x -= 1;
https://www.codecademy.com/learn/learn-p5js/modules/p5js-animation/cheatsheet 3/5
08/11/2024, 14:16 Learn p5.js: Animation Cheatsheet | Codecademy
User-defined Functions
function draw() {
// Call display() custom function
inside draw()
display();
}
function display() {
fill(255);
ellipse(x, y, 50, 50);
}
https://www.codecademy.com/learn/learn-p5js/modules/p5js-animation/cheatsheet 4/5
08/11/2024, 14:16 Learn p5.js: Animation Cheatsheet | Codecademy
Function Parameters
Print Share
https://www.codecademy.com/learn/learn-p5js/modules/p5js-animation/cheatsheet 5/5