color problem
in
Programming Questions
•
1 month ago
I am using an array with color, I want my color to be different for each ball. I keep getting all the same color for the balls. here is my code
- class SplashScreen
- {
- PImage button;
- PVector Ilocation, Ivelocity;
- Ball [] ball;
- color [] colour;
- public SplashScreen()
- {
- Ilocation = new PVector(width/2, -160);
- Ivelocity = new PVector(0, 20);
- button = loadImage("play_Button.gif");
- ball = new Ball[50];
- colour = new color[50];
- for (int i = 0; i<ball.length; i++) {
- ball[i] = new Ball(int(random(150, 200)),
- int(random(150, 200)), int(random(50, 100)));
- }
- for (int x = 0; x<colour.length; x++) {
- colour[x] = color(random(255), random(255), random(255));
- }
- }
- void update()
- {
- Ilocation.add(Ivelocity);
- }
- void draw()
- {
- for (int i = 0; i <ball.length; i++)
- {
- for (int x=0; x<colour.length; x++) {
- fill(colour[x]);
- }
- ball[i].draw();
- }
- update();
- imageMode(CENTER);
- image(button, Ilocation.x, Ilocation.y, button.width, button.height);
- check();
- }
- void check()
- {
- if (Ilocation.y == height/2)
- Ivelocity.y=0;
- }
- }
1