# 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:** 20\
**Page:** 1

<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 18, 2020, 1:53pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/1 "2020-02-18T13:53:11Z")

</div>

please help me why can’t i color this bubble ?

```auto
Bubble b1;
Bubble b2;

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

void draw() {
  background(255);

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

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

class Bubble {
  float x;
  float y;
  float diameter;
  float c1;

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

```

---

<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 18, 2020, 2:28pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/2 "2020-02-18T14:28:11Z")

</div>

Hello,

I have error checking on in the Processing preferences; it helps with obvious warnings and errors.

Look carefully at your constructor (see the red line under c ):

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

Color is a datatype:  
[https://www.processing.org/reference/color\_datatype.html](https://www.processing.org/reference/color_datatype.html)

`:)`

---

<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 18, 2020, 5:34pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/3 "2020-02-18T17:34:03Z")

</div>

Yeah, check the parameters of the constructor. What goes in?

---

<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, 3:26pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/4 "2020-02-24T15:26:42Z")

</div>

so what should i do to color this bubble ?

---

<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, 3:43pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/5 "2020-02-24T15:43:06Z")

</div>

Additional references:

[https://processing.org/reference/color\_.html](https://processing.org/reference/color_.html)  
[https://processing.org/tutorials/color/](https://processing.org/tutorials/color/)

`:)`

---

<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, 3:58pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/6 "2020-02-24T15:58:26Z")

</div>

> [@Rai](#):
>
> Bubble(float x1, float y1, float tempD, float c) {  
> x = x1;  
> y = y1;  
> c = c1;  
> diameter = tempD;  
> }

you mixed up c and c1 here I think

also not float but color in the first line

Thank you!

Chrisir

---

<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, 4:21pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/7 "2020-02-24T16:21:50Z")

</div>

i have try it before …  
use color but still black color and if i not use c=c1, c cannot resolve

---

<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, 4:26pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/8 "2020-02-24T16:26:10Z")

</div>

i know m code wrong but i still dont know what is correct 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, 4:32pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/9 "2020-02-24T16:32:06Z")

</div>

Hello,

Go through the resources provided.  
Several hints were already provided.  
Take a close look at your code and the answer will be forthcoming.

Can you provided an update (post code) on your progress?

`:)`

---

<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, 4:52pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/10 "2020-02-24T16:52:09Z")

</div>

```auto
Bubble b1;
Bubble b2;

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

void draw() {
  background(255);

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

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

class Bubble {
  float x;
  float y;
  float diameter;
  int c1;

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

```

i’m sorry i don’t know what do you mean ?  
but before i ask to forum i have tried this code and try with fill() but i want different color for each bubble

---

<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, 4:54pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/11 "2020-02-24T16:54:08Z")

</div>

> [@Rai](#):
>
> c=c1;

Take a close look at this.

---

<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, 4:59pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/12 "2020-02-24T16:59:34Z")

</div>

i know color c can’t read color(255,0,0), but why ?  
what must i do ?  
that’s my question

---

<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, 5:12pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/13 "2020-02-24T17:12:11Z")

</div>

```auto
Bubble b1;
Bubble b2;

void setup() {
  size(640, 360);
  b1 = new Bubble(200, 360, 60);
  b2 = new Bubble(400, 360, 60);
}

void draw() {
  background(255);

  b1.ascend();
  b1.display();
  b1.top();
  fill(255,0,0);

  b2.ascend();
  b2.display();
  b2.top();
  fill(0,255,0);
}

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

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

  }
  void top() {
    if (y < diameter/2) {
      y = diameter/2;
    }
  }
}

```

i just can use fill() for this problem but my question why i cant color bubble in b1 = new Bubble(200, 360, 60,color(255,0,0));

---

<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, 5:26pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/14 "2020-02-24T17:26:47Z")

</div>

[https://processing.org/reference/assign.html](https://processing.org/reference/assign.html)

---

<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, 5:27pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/15 "2020-02-24T17:27:07Z")

</div>

You are very close. You have 3 pointers in your class code that all refer to color. You also have 3 pointers for your other variables x, y and Diameter. What did you do differently when you wrote your pointers for 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, 5:41pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/16 "2020-02-24T17:41:09Z")

</div>

do you mean variabel name ?

---

<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, 5:45pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/17 "2020-02-24T17:45:30Z")

</div>

c’mon i know my problem before i ask, i know solution for coloring my bubble, what i don’t know is ?  
`Bubble(float x1, float y1, float tempD, float c)` why c cannot read in  
` b1 = new Bubble(200, 360, 60, color(255, 100, 0));`?

---

<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, 5:56pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/18 "2020-02-24T17:56:28Z")

</div>

Sorry. I should rephrase that. Your code points to (or refers to) color 3 times in your class code. (And also 2 times in void display() ). Is the way you have written your color variables in the class consistent with the way you have written your variables for x, y and diameter… like I said before you are very close. Compare the way you wrote your variables that are working to the color variable that is not. This is a typing error not a concept error. And a good opportunity to practice proofreading skills with your code.

---

<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, 6:40pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/19 "2020-02-24T18:40:37Z")

</div>

i don’t think c = c1; is problem, problem is  
`Bubble(float x1, float y1, float tempD, float c)` float c can’t read color from `b1 = new Bubble(200, 360, 60, color(255, 100, 0));` i already use color c before but still doesn’t work try `println(c);` that’s will be 0 because can’t read color

---

<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, 6:49pm UTC](https://discourse.processing.org/t/why-cant-i-color-this-bubble/17915/20 "2020-02-24T18:49:17Z")

</div>

You are correct c = c1 is not the problem.

First look at:

> [@Rai](#):
>
> `Bubble(float x1, float y1, float tempD, float c)` float c can’t read color from `b1 `

What is **x1, y1, tempD**?  
They are temporary variables.  
What about **c**?  
Is **c** a temporary variable?

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