How can I put these 2 codes together?
in
Programming Questions
•
2 years ago
So basically I want a ball that bounces around, but when the mouse is on top, I want the ball to become bigger. The 2 codes are bellow, how can I put them together? Thanks for any advise
Code for ball becoming bigger.
void setup() {
size(400,400);
smooth();
}
void draw() {
background(0);
float d = dist(width/2, height/2, mouseX, mouseY);
ellipse(width/2, height/2, d*2, d*2);
}
Code for ball bouncing
Code for ball becoming bigger.
void setup() {
size(400,400);
smooth();
}
void draw() {
background(0);
float d = dist(width/2, height/2, mouseX, mouseY);
ellipse(width/2, height/2, d*2, d*2);
}
Code for ball bouncing
int x = 300;
int y = 300;
int xspeed = -3;
int yspeed = -3;
void setup(){
size(600,400);
}
void draw(){
background(0);
ellipse(x, y, 20, 30);
x = x + xspeed;
if ( x == 0){
xspeed = 3;
}
if ( x > width){
xspeed = -3;
}
y = y + yspeed;
if ( y < 0){
yspeed = 3;
}
if ( y > height){
yspeed = -3;
}
}
1