Hello all, new to the world of Processing and have a quick question which I am hoping will have just as quick of an answer.
So…
Working with PVector objects, trying to get a understanding of motion within the Processing environment.
Now, let’s make the simplest of motion examples with a ball that starts in the centre-top of the screen at rest and falls and travels to the right at a 5:1 ratio, gaining speed until reaching its predefined maximum fall speed and stays at that speed, it also wraps around the screen when in reaches the edges…
Ball b;
void setup(){
size(400,400);
b = new Ball();
}
void draw(){
background(255);
b.update();
b.checkEdges();
b.display();
}
class Ball{
PVector loc;
PVector vel;
PVector acc;
float maxSpeed;
Ball(){
loc = new PVector(width/2, 5);
vel = new PVector(0,0);
acc = new PVector(0.001, 0.005);
maxSpeed = 15;
}
void update(){
vel.add(acc);
vel.limit(maxSpeed);
loc.add(vel);
}
void checkEdges(){
if(loc.x > width){
loc.x = 0;
}else if(loc.x < 0){
loc.x = width;
}
if(loc.y > height){
loc.y = 0;
}else if(loc.y < 0){
loc.y = height;
}
}
void display(){
fill(175);
ellipse(loc.x, loc.y, 10, 10);
}
}
Now, I understand what’s going on in the code here completely, and I understand the way vectors work… What I am slightly confused about though is the fact that the vectors we are using here are holding values to be used as co-ordinates based on an array of pixels and we are incrementing by fractions of a pixel. So, the values in loc.x and loc.y are floating point numbers with up to 5 point precision (from the values I’ve seen using a println() statement), and those values are being used as the centre of the ellipse being drawn each frame.
How can you have a fraction of a pixel? Or is the value truncated, or rounded, or floored, or modified in any other way (cast to an int?) before being used as a pixel location, and because the values are incrementing many times per second (based on frame rate) the intermediate values (the real numbers between the integers) are basically ignored?