# Why can't i color this bubble?

**URL:** <https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915>\
**Category:** Beginners\
**Created:** [February 18, 2020, 1:53pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915 "2020-02-18T13:53:11Z")\
**Posts on this page:** 17\
**Page:** 2

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [February 24, 2020, 7:01pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/21 "2020-02-24T19:01:55Z")

</div>

Also, look at your variables at the very beginning:

> [@Rai](#):
>
> class Bubble {  
> float x;  
> float y;  
> float diameter;  
> float c1;

Why is your temporary variable **c1** here? But your variables above are not temporary variables…

---

<div class="post-metadata">

**Author:** ![Rai](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@Rai](https://discourse.processing.org/u/Rai)\
**Post date:** [February 24, 2020, 7:12pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/22 "2020-02-24T19:12:58Z")

</div>

ok i give up, i try what i can do but still doesn’t work, give me corect answer

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [February 24, 2020, 7:15pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/23 "2020-02-24T19:15:23Z")

</div>

This is essentially what your code is doing:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/bdd923ff1e9e984e4ea8a12069b3932a8275ac7b.png)

You are mixing variable types and assignment statements are incorrect.

Take a good look at this and try to understand where you are making the errors.

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [February 24, 2020, 7:26pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/24 "2020-02-24T19:26:14Z")

</div>

> [@Rai](#):
>
> give me corect answer

Um @Rai  
This isn’t how it works, demanding the correct answer.  
Several people have given you very constructive advice.  
As I have stated, you are very close. And because you have set up your x, y, and diameter variables correctly, you seem to understand the purpose of the temporary variables in the constructor. This is where the problem is. Carefully proofreading all of your color variables in your class code will unlock the answer. Is your temporary color variable in its correct place? How many times have you indicated use of the temporary variable? Is that correct?

---

<div class="post-metadata">

**Author:** ![Rai](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@Rai](https://discourse.processing.org/u/Rai)\
**Post date:** [February 24, 2020, 7:38pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/25 "2020-02-24T19:38:03Z")

</div>

```auto
class Bubble {
  float x;
  float y;
  float diameter;

  Bubble(float x1, float y1, float tempD, color c) {
    x = x1;
    y = y1;
    diameter = tempD;
  }
  void ascend() {
    y--;
    x = x + random (-2, 2);
  }
  void display() {
    noStroke();
    fill(c);
    ellipse(x, y, diameter, diameter);
    println (c);
  }

```

do you mean like this ?

---

<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:** [February 24, 2020, 7:51pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/26 "2020-02-24T19:51:49Z")

</div>

Basically:

- Have you read the tutorial on objects? [https://www.processing.org/tutorials/objects/](https://www.processing.org/tutorials/objects/)
- The class is the cookie maker, the many objects are the cookies
- The constructor is the part where the cookies are made
- to do this, we pass parameters to the constructor: `
- Bubble(float x1, float y1, float tempD1, color c1) {`. These are temporary since when the constructor is done, the object forgets them
- To make the parameters permanent, we copy them into the classes /Objects own variables which are above the constructor.

```auto
  float x;
  float y;
  float diameter;
  color c; 

```

- The process of copying is done in the constructor and looks like this:

```auto
    x = x1;
    y = y1;
    diameter = tempD1;

```

- Now when we would forget to assign a variable in the class a value it stays 0. Or when we assign a value to a parameter, it gets lost after we leave the constructor. Bad.

But in your case it’s just a matter of proofreading.

- And be consistent in your naming please: When all parameters have …1 at the end, then all variables in the class should not.

Chrisir

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [February 24, 2020, 7:53pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/27 "2020-02-24T19:53:42Z")

</div>

> [@Rai](#):
>
> ```auto
> void display() { 
> noStroke(); 
> fill ( c ); /////////////// yes!!! this is correct 
> ellipse(x, y, diameter, diameter); 
> println ( c ); ///////////// yes! this is correct
> 
> ```

Now go back up to the top:

> [@Rai](#):
>
> ```auto
> class Bubble { 
> float x; 
> float y; 
> float diameter;
> /// you remove your color variable...why?
>  
> Bubble (float x1, float y1, float tempD, color c) { /// x1, y1, and tempD are all temporary variables. Is color c a temporary variable? Look at the way the variables for x = x1, y = y1, diameter = tempD are written. color = ...
> 
> x = x1; 
> y = y1; 
> diameter = tempD;
> /// and you need your color variable equals **tempColor** variable here
> 
> ```

---

<div class="post-metadata">

**Author:** ![Rai](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@Rai](https://discourse.processing.org/u/Rai)\
**Post date:** [February 24, 2020, 8:09pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/28 "2020-02-24T20:09:45Z")

</div>

Ok thank you…

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [February 24, 2020, 8:16pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/29 "2020-02-24T20:16:22Z")

</div>

So you figured it out and the bubbles now appear in color?

---

<div class="post-metadata">

**Author:** ![Rai](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@Rai](https://discourse.processing.org/u/Rai)\
**Post date:** [February 24, 2020, 8:25pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/30 "2020-02-24T20:25:50Z")

</div>

```auto
class Bubble {
  float x;
  float y;
  float diameter;
  int c1; /// use color/int

  Bubble(float x1, float y1, float tempD, color c) { /// use color/int
    x = x1;
    y = y1;
    c1 = c ;///reverse
    diameter = tempD;
  }
  void ascend() {
    y--;
    x = x + random (-2, 2);
  }
  void display() {
    noStroke();
    fill(c1);
    ellipse(x, y, diameter, diameter);
    println (c1);
  }

```

thank you…  
i thougt i’m never get answer

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [February 24, 2020, 8:49pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/31 "2020-02-24T20:49:44Z")

</div>

See comments below next to problem areas:

> [@Rai](#):
>
> ```auto
> void display() {
> noStroke();
> fill(c1); /// why did you change this back to (c1)? I told you (c) is correct.
> ellipse(x, y, diameter, diameter);
> println (c1); /// ditto here. I told you (c) is correct.
> 
> ```

> [@Rai](#):
>
> ```auto
> class Bubble {
> float x;
> float y;
> float diameter;
> int c1; /// Wrong. This is 1st problem area. 
> /// The datatype for color is color NOT int.
> 
> Bubble(float x1, float y1, float tempD, color c) { /// This is 2nd problem area. 
> /// color c is not a temporary variable. However c1 is.
> x = x1;
> y = y1;
> c1 = c ; /// Wrong. DO NOT reverse this. 
> /// Put it back to c = c1.
> diameter = tempD;
> }
> 
> ```

---

<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:** [February 24, 2020, 8:53pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/32 "2020-02-24T20:53:48Z")

</div>

That looks nice.

Congratulation!

You solved it!

Just a remark:

Your sketch is not wrong.

Please note though that the naming of the parameters is not _consistent_:

`Bubble(float x1, float y1, float tempD, color c) { /// `

could be

`Bubble(float x1, float y1, float d1, color c1) { /// all parameters end with 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!`

Also, your variables are

```auto
float x;
float y;
float diameter;
int c1; /// use color/int ---- here naming with a 1 !!! 

```

could be

```auto
  // class variables (or fields) - none of them ends with a 1 !!!!!!!!!!!!!!!!!!!
  float x;
  float y;
  float diameter;
  color c;  

```

and in the constructor accordingly

```auto
    x = x1; // parameters with 1 are on the right, variables on the left 
    y = y1;
    c = c1; /// nice 
    diameter = d1;

```

_That looks like a small thing, but being consistent let’s you spot errors faster that are otherwise hard to find._

Chrisir

**My full sketch**

```auto

Bubble b1;
Bubble b2;

void setup() {
  size(640, 360);
  b1 = new Bubble(200, 360, 60, color(random(255), 100, 0));
  b2 = new Bubble(400, 360, 60, color(0, 100, 200));
}//func 

void draw() {
  background(255);

  b1.ascend();
  b1.display();
  b1.top();

  b2.ascend();
  b2.display();
  b2.top();
}//func 

// ===================================================================================

class Bubble {
  // one Bubble

  // class variables (or fields) - none of them ends with 1 !!!!!!!!!!!!!!!!!!!
  float x;
  float y;
  float diameter;
  color c; /// use color/int

  // constructor 
  Bubble(float x1, float y1, /// all parameters end with 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!
    float d1, /// all parameters end with 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!
    color c1) { /// all parameters end with 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!
    x = x1;
    y = y1;
    diameter = d1;
    c = c1 ;///
  }// constructor 

  void ascend() {
    y--;
    x = x + random (-2, 2);
  }//method

  void display() {
    noStroke();
    fill(c);
    ellipse(x, y, 
      diameter, diameter);
    // println (c);
  }//method

  void top() {
    if (y < - diameter/2) {
      y = height + diameter/2;
    }
  }//method
  //
}//class
//

```

---

<div class="post-metadata">

**Author:** ![Rai](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@Rai](https://discourse.processing.org/u/Rai)\
**Post date:** [February 24, 2020, 9:02pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/33 "2020-02-24T21:02:29Z")

</div>

when i try `int c1;` or` color c1;` it’s look’s same output what i realize is `c1 = c ;` reverse  
i thougt ;`c1 = c ;` same with `c = c1;`

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [February 24, 2020, 9:10pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/34 "2020-02-24T21:10:25Z")

</div>

I think most important at this point is the code runs and you are seeing the result you want.  
Maybe look at this project again in a couple weeks after you’ve been coding some more and refer to the thread and you will see a slightly different way to write this that is more consistent with the other variables in your program.  
But, Congratulations!!! You worked it out!!!

---

<div class="post-metadata">

**Author:** ![Rai](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@Rai](https://discourse.processing.org/u/Rai)\
**Post date:** [February 24, 2020, 9:10pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/35 "2020-02-24T21:10:44Z")

</div>

thank you…

---

<div class="post-metadata">

**Author:** ![Rai](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@Rai](https://discourse.processing.org/u/Rai)\
**Post date:** [February 24, 2020, 9:11pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/36 "2020-02-24T21:11:53Z")

</div>

thank you glv…

---

<div class="post-metadata">

**Author:** ![Rai](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@Rai](https://discourse.processing.org/u/Rai)\
**Post date:** [February 24, 2020, 9:13pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/37 "2020-02-24T21:13:34Z")

</div>

thank you debxyz…

[Previous page](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915.md?page=1)
