Question
Hi everybody, I am new to processing language programming (Processing 3), I have an example of bouncing the ball and when executing the program the
Hi everybody, I am new to processing language programming (Processing 3), I have an example of bouncing the ball and when executing the program the system gave me (sometimes) wrong directions as output: Ex. if xmove = 1and ymove =1the default direction = south_East , I want to add a statement to check x_move and y_move to print the directions correctly. Thanks
the code :
// initial position for our circle
float circle_x = 300;
float circle_y = 20;
// how much to move the circle on each frame float move_x = 2;
float move_y = -2;
void setup() {
size(400, 200);
stroke(#D60DFF);
strokeWeight(7);
}
void draw() {
background(#21EA73);
ellipse(circle_x, circle_y, 40, 40);
circle_x = circle_x + move_x;
circle_y = circle_y + move_y;
if(circle_x > width) {
circle_x = width;
move_x = -move_x;
println(" north_east");
}
if(circle_y > height) {
circle_y = height;
move_y = -move_y;
println(" south_west");
}
if(circle_x < 0) {
circle_x = 0;
move_x = -move_x;
println(" north_west");
}
if(circle_y < 0) {
circle_y = 0;
move_y = -move_y;
println(" south_east");
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started