Animation in Processing
Table of Contents
What are Animations
What are Animations
The setup function
The setup Function
void setup()
{
size(800, 500);
background(0, 0, 0);
stroke(225);
frameRate(60);
}
Width of window
Height of window
RGB values of the background color
Color of your draw commands
Number of times your frame refreshes per second (or how many times draw(); is called per second)
The draw function
The draw function
void draw ()
{
//call other functions or use draw commands (and increment variables used //in animation)
}
How to Draw Animations
How to Draw Animations
Example 1: drawing inside the draw function
//all your global variables (usually use in drawing commands)
int x =0;
void setup()
{
size(800, 500);
background (0,0,0);
stroke(225);
frameRate(60);
}
Defaults at 60 (not sure if you’re allowed to use it yet)
How to Draw Animations
void draw ()
{
background (0,0,0);
drawLine(x, 0, x, 20);
x = x+1;
}
How to Draw Animations
Example 2: drawing outside the draw function
//all your global variables (usually use in drawing commands)
int x =0;
void setup()
{
size(800, 500);
background (0,0,0);
stroke(225);
frameRate(60);
}
How to Draw Animations
void moveLine ()
{
x = x +2;
}
void drawTheLine ()
{
background (0,0,0);
stroke(225);
drawLine(x, 0, x, 20);
}
How to Draw Animations
void draw ()
{
moveLine();
drawTheLine();
}
Tips and Tricks
Tips and Tricks
Tips and Tricks
double speed = 16;
int x =0;
void setup()
{
size(800, 500);
background (0,0,0);
stroke(225);
frameRate(10);
}
Tips and Tricks
void speedChange ()
{
speed = speed/1.1;
}
void draw()
{
background (0,0,0);
stroke(225);
line(x, 0, x, 20);
x = x+speed;
speedChange();
}
Credits go to Andy for thinking of these cool animation tips