I'm totally new to anything that has to do with programming, but am trying to wrap my mind around Processing. I'm going through the book "Getting Started with Processing," and for the most part it makes sense and I'm really digging it. I came to a chapter on "easing," however and I'm a little bit confused. Keep in mind, I haven't yet even begun to think like a programmer yet, so bear with me.
In trying to reverse engineer the below that I pulled from the book, I have a question.
float x;
float y;
float px;
float py;
float easing = 0.05;
void setup() {
size(480, 120);
smooth();
stroke(0, 102);
}
void draw() {
float targetX = mouseX;
x += (targetX - x) * easing;
float targetY = mouseY;
y += (targetY - y) * easing;
float weight = dist(x, y, px, py);
strokeWeight(weight);
line(x, y, px, py);
py = y;
px = x;
}
I know that Processing is made to understand that px and py are the previous x and y coordinates from which to measure the distance to the current x and y coordinates, but I'm not sure how that is established in the code. It seems like something completely arbitrary, assigned no value until the very end when they are assigned the values of x and y.
Could someone please enlighten me on the flaws in my own thought process. I know it's really elementary for many of you, so I appreciate the help.