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