Bubbles transform to black rectangles

Hello Guys,

I need help from an task where I am not quite sure where I am wrong.

The task is in German but I will translate it via Deppl.com to english:

Write the class Blubb with the four properties x, y, d (all float) and
at the bottom (boolean value, wrong at the beginning). The class has a constructor
without parameters, where x and y are set randomly, also d (diameter) should be set randomly between 10 and 40
The class has two methods:
draw() draws a circle at the appropriate position with the corresponding
Diameter
move() moves the circle from top to bottom. When the circle touches the ground,
it should turn into a rectangle (side length d, center at position x, y) and
stay on the ground (tip: use the ground feature for this).
In the main program you create an array of 20 blubb objects. Drop these objects down as described above. Of course the program should also
work with 5 or 150 objects.
Here you can see an exemplary program sequence:

This should be the solution as a picture:

lösung


Now this is my Code. First the class Code:

class Blubb
{
  float x;
  float y;
  float d;
  boolean amBoden;


  Blubb()
  {
    x = int(random(10, width));
    y = int(random(10, height));
    d = int(random(10, 40));
    amBoden = false;
  }

  void zeichne()
  {
    if (amBoden == false && y > height)
    { 
      rect(x, y, d, d);
    } else
    {
      ellipse(x, y, d, d);
    }
    y +=1;
  }


  void bewege()
  {

    if (y < height-d && amBoden == true)
    {
      amBoden = !amBoden;
    }
  }
}

Now the mainCode (I think here should be everthing right)

Blubb[] b = new Blubb[150];

void setup()
{
 for(int i=0; i <b.length; i++)
 {
   b[i] = new Blubb();
 }
  
  
}


void draw()
{
  background(255);
 for( int i=0; i < b.length; i++)
 {
   b[i].zeichne();
   b[i].bewege();
 }
  
  
}
  

I could not make the ellippse an the bottom to black rectangles.
Now I have a boolean variable. If the ellipse are on height then there must be black rectangle on the bottom.
But how.

Could someone say me where I should try and fix it.

I think I need to make an If cause but I am not sure how.
I tried it as you can see but it is wrong.

Thank you all for your help.

task

Write the class Blubb with the four properties x, y, d (all float) and
at the bottom (boolean value, wrong at the beginning). The class has a constructor
without parameters, where x and y are set randomly, also d (diameter) should be set randomly between 10 and 40
The class has two methods:
draw() draws a circle at the appropriate position with the corresponding
Diameter
move() moves the circle from top to bottom. When the circle touches the ground,
it should turn into a rectangle (side length d, center at position x, y) and
stay on the ground (tip: use the ground feature for this).
In the main program you create an array of 20 blubb objects. Drop these objects down as described above. Of course the program should also
work with 5 or 150 objects.
Here you can see an exemplary program sequence:

what is this please?


better 

if (y > height-d) {   // HIER MUSS > stehen 
    amBoden = true;
 }

Remark

the circle has to stop once amBoden == true.
Also, instead of circles draw ellipses then.

Remark

I don’t think you separated the functions correctly; zeichnen() does also do the movement.

Chrisir

Hey Chris,

unfortunately I tried everthing but I could not find a solution.
Could you give me please another hint?

Gürcan

Can you please post your current entire version

You haven’t answered this please
Thank you!