Balloon string
in
Programming Questions
•
11 months ago
How do I create a balloon string, I have the rest of the work done.
I also tried using this,
line(x, y + h/3, x, y + h/3 + 20);
Here is a hint that I tried to follow but confused still;
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, 150);
ellipse(x, y, w, h);
line(x, y + h/3, x, y + h/3 + 20);
}
void move()
{
x += xSpeed;
y += ySpeed;
if (x < w/2 || x > width-w/2) xSpeed = -xSpeed;
if (y < h/2 || y > height-h/2) ySpeed = -ySpeed;
}
}
I also tried using this,
line(x, y + h/3, x, y + h/3 + 20);
Here is a hint that I tried to follow but confused still;
-
display()
-
This function draws the balloon at its current position. It will also draw a a string at the bottom of the balloon (using a black
line()
). The string starts at the center of the balloon at the bottom, and extends to the right one-third the width of the balloon and the line’s height is one-third the height of the balloon. The string is outside the balloon’s bounding box.
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, 150);
ellipse(x, y, w, h);
line(x, y + h/3, x, y + h/3 + 20);
}
void move()
{
x += xSpeed;
y += ySpeed;
if (x < w/2 || x > width-w/2) xSpeed = -xSpeed;
if (y < h/2 || y > height-h/2) ySpeed = -ySpeed;
}
}
1