I want to change my particles color according to a percentage value.
For instance
10 % white
60%Green
30%blue.
I am not sure how I can do that. Can someone bring me to the right direction ?
Thanks.
This is what i have so far.
int ballWhite = 10; int ballGreen = 75; int ballBlue = 15;
int ballSpawn; //counting variable for array int ballMax; ball[] balls; //array containing the balls boolean collision = false; //toggles edge collision of type 1 balls boolean maxBallsReached = false; float bounciness = 2.05; // edit for more or less bounce, default .35
//println(frameRate); if (ballSpawn > ballMax) { if (maxBallsReached == false) { maxBallsReached = true; } ballSpawn = 0; }
int c = int(random(0,3)); //Size int s = int(random(2,50)); //Velocity float mX = random(-250,250); float mY = random(-20,00)-3;
balls[ballSpawn+1] = new ball(1, s, c , 320, 0, mX, mY); ballSpawn++; // }
//this redraws the frame with all spawned balls. if (maxBallsReached == false){ background(0, 0, 0); for(int i=ballSpawn; i>0; i--){ balls[i].ballUpdate(); balls[i].ballMove(); } } else{ background(0, 0, 0); for(int i=ballMax; i>0; i--){ balls[i].ballUpdate(); balls[i].ballMove(); } } }
class ball {
float dim; //diameter float speedX = 0; //horizontal speed in px per second float speedY = 0; //vertical speed in px per second color col; //color float xpos; //horizontal position float ypos; //vertical position float age; //age in seconds int ttl; //for collision; times bounced int type; //for different types of ball, currently right or left click int fade = 255; //transparency float fadeSpeed = 0.05; //fade speed color[] myColors = {#ffffff, #009aff, #30ff00}; int colorID;
void ballMove() { // moves the ball according to new variables xpos += speedX/frameRate; ypos = ypos + (speedY/frameRate); age = age+(1/frameRate); }
void ballUpdate() { // calculates new variables (such as speed, size, etc.) // ----------------- TYPE 1
if(fade==0){} //increases performance of type 2 by ceasing calculation, but doesn't get rid of the balls themselves else if(ttl==0) {} //increases performance of type 1 balls when colliding by the same method else if(xpos + dim < 0 || xpos-dim > width || ypos-dim >height) {} // and the same for type non-colliding.
else if(type==1){ if(age <=4/30){ dim = dim+age*0.5; } else if(age <= 8/30 && age >= 5/30){ dim = dim+age*0.2; }
fill (myColors[colorID]); ellipse(xpos, ypos, dim, dim); speedY = speedY+5;