Why can't i color this bubble?

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

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;
    }
  }
1 Like

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 ):

Color is a datatype:
https://www.processing.org/reference/color_datatype.html

:)

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

1 Like

so what should i do to color this bubble ?

1 Like

Additional references:

https://processing.org/reference/color_.html
https://processing.org/tutorials/color/

:)

1 Like

you mixed up c and c1 here I think

also not float but color in the first line

Thank you!

Chrisir

1 Like

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

1 Like

i know m code wrong but i still dont know what is correct answer

1 Like

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?

:)

1 Like
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

1 Like

Take a close look at this.

1 Like

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

1 Like
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));

1 Like

https://processing.org/reference/assign.html

1 Like

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?

1 Like

do you mean variabel name ?

1 Like

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));?

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.

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

You are correct c = c1 is not the problem.

First look at:

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