# Bubbles transform to black rectangles

**URL:** <https://discourse.processing.org/t/bubbles-transform-to-black-rectangles/20258>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [April 29, 2020, 11:17am UTC](https://discourse.processing.org/t/bubbles-transform-to-black-rectangles/20258 "2020-04-29T11:17:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gurki](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@gurki](https://discourse.processing.org/u/gurki)\
**Post date:** [April 29, 2020, 11:17am UTC](https://discourse.processing.org/t/bubbles-transform-to-black-rectangles/20258/1 "2020-04-29T11:17:38Z")

</div>

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](http://Deppl.com) to english:

```auto
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](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/4/482f94b4840d092bd3c2966729a7d2df6c338120.png)

* * *

Now this is my Code. First the class Code:

```auto
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)

```auto
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.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 29, 2020, 2:49pm UTC](https://discourse.processing.org/t/bubbles-transform-to-black-rectangles/20258/2 "2020-04-29T14:49:48Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 29, 2020, 2:51pm UTC](https://discourse.processing.org/t/bubbles-transform-to-black-rectangles/20258/3 "2020-04-29T14:51:22Z")

</div>

> [@Chrisir](#):
>
> tip: use the ground feature for this

what is this please?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 29, 2020, 2:53pm UTC](https://discourse.processing.org/t/bubbles-transform-to-black-rectangles/20258/4 "2020-04-29T14:53:28Z")

</div>

> [@gurki](#):
>
> if (y \< height-d && amBoden == true) {  
> amBoden = !amBoden;  
> }

```auto

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**

> [@Chrisir](#):
>
> draw() draws a circle at the appropriate position  
> move() moves the circle from top to bottom.

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

Chrisir

---

<div class="post-metadata">

**Author:** ![gurki](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@gurki](https://discourse.processing.org/u/gurki)\
**Post date:** [April 30, 2020, 8:43am UTC](https://discourse.processing.org/t/bubbles-transform-to-black-rectangles/20258/5 "2020-04-30T08:43:52Z")

</div>

Hey Chris,

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

Gürcan

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 30, 2020, 10:04am UTC](https://discourse.processing.org/t/bubbles-transform-to-black-rectangles/20258/6 "2020-04-30T10:04:41Z")

</div>

Can you please post your current entire version

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 30, 2020, 11:18am UTC](https://discourse.processing.org/t/bubbles-transform-to-black-rectangles/20258/7 "2020-04-30T11:18:04Z")

</div>

> [@Chrisir](#):
>
> > [@Chrisir](#):
> >
> > tip: use the ground feature for this
> 
> what is this please?

You haven’t answered this please  
Thank you!
