Following ball as it moves around?
in
Programming Questions
•
1 year ago
Hi, I'm new to Processing, so sorry if this question is insanely easy. I'm making a ball move only left and right, but I want to follow it as it moves past halfway of the screen. Then I'll be able to see the numbers that follow. Eventually, I want to follow it as it moves up and down past the display screen's y axis halfway point. How would I do this? I heard that you're supposed to use translate and push/pop matrixes, but I can't wrap my head around it. Thanks!
Code:
PFont f;
int xpos, ypos;
void setup() {
f = loadFont("Algerian-48.vlw");
textFont(f, 48);
size(800, 600);
}
void draw() {
background(204);
fill(0);
text(1, 500, 300);
text(2, 1000, 300);
text(3, 1500, 300);
text(4, 2000, 300);
text(5, 2500, 300);
ellipse(xpos, ypos, 100, 100);
}
void keyPressed() {
if (key == 'd' || key == 'D')
xpos = xpos + 5;
if (key == 'a' || key == 'A')
xpos = xpos - 5;
}
Code:
PFont f;
int xpos, ypos;
void setup() {
f = loadFont("Algerian-48.vlw");
textFont(f, 48);
size(800, 600);
}
void draw() {
background(204);
fill(0);
text(1, 500, 300);
text(2, 1000, 300);
text(3, 1500, 300);
text(4, 2000, 300);
text(5, 2500, 300);
ellipse(xpos, ypos, 100, 100);
}
void keyPressed() {
if (key == 'd' || key == 'D')
xpos = xpos + 5;
if (key == 'a' || key == 'A')
xpos = xpos - 5;
}
1