Hello! I am a beginner, and I’m very new to processing!
I have a project in mind that I have no idea how to execute. I want to create something from the bouncing ball example. Supposedly, the code will draw a line from the center of the ball to track where the ball has been.
So far, I created a dot in the middle of the circle.
PVector location; // Location of shape
PVector velocity; // Velocity of shape
PVector gravity; // Gravity acts at the shape's acceleration
void setup() {
size(640,360);
location = new PVector(100,100);
velocity = new PVector(1.5,2.1);
gravity = new PVector(0,0.2);
}
void draw() {
background(0);
location.add(velocity);
// Add gravity to velocity
velocity.add(gravity);
// Bounce off edges
if ((location.x > width) || (location.x < 0)) {
velocity.x = velocity.x * -1;
}
if (location.y > height) {
velocity.y = velocity.y * -1;
location.y = height;
}
stroke(255);
strokeWeight(2);
fill(127);
ellipse(location.x,location.y, 48, 48);
line(location.x, location.y, location.x, location.y);
}
This creates a dot, but leaves no trail. I assume it’s because I have no idea how to obtain the location of the center of the ball of the previous frame.
Thank you for reading!