Kevin Song
I'm a student at UT (that's the one in Austin) who studies things.
Calls in Processing that allow us to move the coordinate system around---changes the interpretation of positions.
Useful transformations:
translate
rotate
shearX
shearY
scale
Sometimes we might want to save the current transformation: can do with with pushMatrix()
The most recent transformation saved with pushMatrix()
can be restored by calling popMatrix()
We should generally try to make sure every pushMatrix()
is matched with a popMatrix()
Do we need to have fixed shapes in the background for P3?
No. If your animation is helped by such things you can include them, but you can also have an animation which gives the illusion of movement by animating the background (e.g. plane flying through infinite clouds).
Can we use code from the Processing website for P3?
Yes. But make sure you attribute it.
Processing website is licensed under BSD0 so no issues with copyright.
Two levels of transformation is not the same thing as applying two transformations to an object!
Two transformations:
Two levels of animation:
Will we use (Maya/Illustrator/AutoCAD) in this class?
No, but if you already know how to use these programs and want to learn how to import assets into Processing, feel free to ask!
Instead of loading PShapes, can you just load drawings?
Yes, but regular image rules will apply: can't scale up arbitrarily, must be rectangular, rotations may create artifacts, etc.
How do spatial hierarchies work in 3D? Do they use camera depth?
Spatial hierarcy: things that move together are grouped together.
If things away from the camera tend to move more/less, you can group them by depth, but usually not.
Is the entire scene always rendering or just the place the camera is looking at?
Depends on implementation. Efficient ones don't render things the camera can't see, but this is harder than it sounds.
So far, we've focused on how to construct static images. Static images are so 15,000 B.C.E. Let's make moving pictures!
One way to make an animation would be to define a sequence of static images that form the final animation.
Static images constructed with 15,000 B.C.E. technology.
Chu and Lee, 2009
Where should the ball be at \(t = 50\)? What about \(t = 10\)?
Key configurations: \(t = 0\) and \(t = 100\)
Given a starting and ending target, we can change a value by a fixed amount each timestep. This way, the change happens at a linear rate (i.e. if we wait twice as long, the change is twice as large).
This is linear interpolation, sometimes nicknamed "lerp".
We know the draw() function is called every 16.66ms (for 60FPS) or 33.33ms (for 30FPS).
Can update shape position in draw loop!
float x = 0.0;
float y = 250.0;
float dx = 3.0;
void setup () {
frameRate(30);
size(500, 500);
}
void draw() {
background(210); // Why?
ellipse(x, y, 30, 30);
if (x < 250) {
x += dx; // wheee!
}
}
float x = 0.0;
float y = 250.0;
float dx = 3.0;
void setup () {
size(500, 500);
}
void draw() {
background(210);
ellipse(x, y, 30, 30);
if (x < 250) {
x += dx;
}
simulateLag(); // Ouch.
}
void simulateLag(){
int delayAmt = 0;
if (random(1) < 0.1){
delayAmt = int(random(500));
} else {
delayAmt = int(random(75));
}
delay(delayAmt);
}
Locking things to your framerate is basically guaranteed to come back and bite you someday!
Processing has a function called lerp()
Usage: lerp(v1, v2, t)
where t is between 0 and 1
Does not actually apply the lerp over time---you need to do that yourself! This just tells you what the result should be.
float xBegin = 0.0;
float yBegin = 0.0;
float xEnd = 500.0;
float yEnd = 300.0;
float time = 0.0;
float timeEnd = 100.0;
float x = xBegin;
float y = yBegin;
void setup(){
size(500, 500);
}
void draw(){
time++;
if(time > 100){
noLoop();
return;
}
ellipse(x, y, 50, 50);
// How do we get the new x and y?
}
Michael Guerzhoy, UToronto, https://www.cs.toronto.edu/~guerzhoy/320/lec/upsampling.pdf
Linear Interpolation can have sharp discontinuities at each point. Cosine interpolation can smooth these out without requiring more data points.
paulbourke.net
time
which runs from 0.0 to 1.0 in increments of 0.01. Increment time at the end of your draw()
loop (and roll it back over to 0.0 if it exceeds 1.0).lerp()
to move a shape between two points of your choosing in your draw()
loop. Use the global time you set up in step 2 to do the interpolation.lerpColor()
to make the shape change color smoothly as well.0.5 * (sin(time)+ 1)
as your lerp argument (since it is always in the range [0.0, 1.0])Is this smooth?
Is this smooth?
Is this smooth?
We can define smoothness by which derivatives are continuous at all points!
Not smooth at all!
\(C^0\) smooth
\(C^1\) smooth
\(C^\infty\) smooth
Higher-order continuity is useful in many applications including animation and geometric modeling. (Looks smooth, smooth behavior gives nice guarantees).
Requires some extra parameters to meet the overheads of smoothness.
Splines are piecewise polynomials with high continuity.
Spline
Control Point
(Duck)
A set of control points
A smoothness constraint, usually specified as a \(C^k\) smoothness
A curve which is controlled by the control points and satisfies the smoothness constraint.
There are many ways to construct a spline, and there are lots of spline techniques as a result.
Given three control points \(P_0, P_1, P_2\), the Bézier curve expressed by the three points is
We can glue together multiple Bézier curves to get a basis spline.
https://en.wikipedia.org/wiki/B-spline
We can extend the principles of splines into higher dimensions!
Still give a set of control points and a smoothness constraint, but now ask for a surface that satisfies those constraints instead.
Very popular in 3D modeling and animation where smooth surfaces are important.
Sine (and cosine) equations model a periodic relationship between the input and output.
\(y\) is the output and \(\theta\) is the input.
Other letters provide control handles for the wave:
small \(a\)
large \(a\)
small \(w\)
large \(w\)
zero \(p\)
nonzero \(p\)
float time = 0.0;
void setup(){
size(600, 600);
}
void draw(){
background(255);
fill(0);
time += 1.0;
// What's going wrong with this line?
float x = 600 * sin(0.02 * time);
ellipseMode(CENTER);
ellipse(x, x, 50, 50);
}
Sometimes you want some pop!
Sometimes you want something more subdued.
Sometimes you want something more subdued.
Or you want your shape to spend as little time in the middle as possible....
Apply a function to the position to create nonlinear motion.
float x = 0.0;
float easing = 0.05;
float targetX = 400;
void setup() {size(500, 500);}
void draw() {
x += (targetX - x) * easing;
ellipse(x, 250, 50, 50);
}
We try a bunch and see what looks good...or let someone else do that work and then use their results! E.g. https://gizma.com/easing/
Make the ball for each of these a different color. They should all animate on screen at the same time (the last one needs to only animate once)
By Kevin Song
I'm a student at UT (that's the one in Austin) who studies things.