object
in
Programming Questions
•
11 months ago
I can't figure out the speed for this, how to make it move?
Balloon balloon1;
Balloon balloon2;
void setup()
{
size(300, 300);
balloon1 = new Balloon(50, 60, 20, 30, color(255, 0, 0));
balloon2 = new Balloon(70, 100, 30, 40, color(0, 255, 255));
}
void draw()
{
background(255);
balloon1.move();
balloon1.display();
balloon2.move();
balloon2.display();
}
class Balloon
{
float x;
float y;
float w;
float h;
color c;
float xSpeed;
float ySpeed;
Balloon(float bx, float by, float bw, float bh, color bc)
{
x = bx;
y = by;
w = bw;
h = bh;
c = bc;
xSpeed = 1;
ySpeed = 2;
}
void display()
{
fill(c);
ellipse(x, y, w, h);
}
void move()
{
// do stuff here
}
}
-
move()
- This function moves the balloon as specified in the x and y speed instance variables. If the balloon would move off the screen, it reverses direction. The balloon may not leave the window; the string may.
Balloon balloon1;
Balloon balloon2;
void setup()
{
size(300, 300);
balloon1 = new Balloon(50, 60, 20, 30, color(255, 0, 0));
balloon2 = new Balloon(70, 100, 30, 40, color(0, 255, 255));
}
void draw()
{
background(255);
balloon1.move();
balloon1.display();
balloon2.move();
balloon2.display();
}
class Balloon
{
float x;
float y;
float w;
float h;
color c;
float xSpeed;
float ySpeed;
Balloon(float bx, float by, float bw, float bh, color bc)
{
x = bx;
y = by;
w = bw;
h = bh;
c = bc;
xSpeed = 1;
ySpeed = 2;
}
void display()
{
fill(c);
ellipse(x, y, w, h);
}
void move()
{
// do stuff here
}
}
1