gabecolors
YaBB Newbies
Offline
Posts: 12
Re: raining circles (blended circles)
Reply #7 - Feb 10th , 2010, 3:42am
any suggestions on how to create an area of the screen that when mouseover increases the balls by a count of one and a separate area of the screen that when mouseover decreases the balls by a count of one? Spot foo[] = new Spot[20]; // Since you'll want more than one spot create an array to store multiple spots float r1 = 170; float g1 = 211; float b1 = 126; float r2 = 91; float g2 = 105; float b2 = 176; int a = 150; int backc = 255; int maxRadius; float interfaceW; float interfaceH; float barwidth; float barheight; float topbarW; float topbarH; float speed; void setup(){ size(900,700); barwidth = 0.04; barheight = 0.5; interfaceW = barwidth*width; interfaceH = barheight*height; topbarW = barheight*width; topbarH = barwidth*height; maxRadius = 30; speed = 0.5; // from 0-1, 0 is slowest // fill(255,0,0); // rect(0,0,0.02*width, interfaceH); // Whenever you want to do something to all your spots you need to iterate through the array: for(int i=0;i<foo.length;i++) { // create a random colour. By limiting r and g and setting a minimum for b we should get a selection of blues // while I adjusted color for the circles later, i couldn't delete this area without losing it all int r = (int) random(100); int g = (int) random(100); int b = 155 + (int) random(100); color colour = color(r,g,b); // create the Spot objects: foo[i] = new Spot(random(width),0,10+random(maxRadius), colour); } smooth(); } void draw(){ background(backc); //begin "if mouse gets near edges do controls of inner and outer circles if(mousePressed){ r1 = 170; g1 = 211; b1 = 126; r2 = 91; g2 = 105; b2 = 176; a = 150; backc = 255; } if (mouseY > (0.97*height)) { backc = ((255*mouseX)/width); //change background shade fill(255-backc); rect(0,height*0.97,width,height); //black bar on bottom stroke(255-backc); line(mouseX,0.96*height, mouseX, height); } //left OUTER circle if (mouseX > 1 && mouseX < interfaceW && mouseY < (interfaceH)) { //outer circle, red control r1 = ((255*mouseY)/(interfaceH)); //red noStroke(); fill(r1,100,100); //red box on left to gauge red value rect(0,0,interfaceW, interfaceH); //line to guage red value stroke(255-backc); line(0,(r1*interfaceH)/255,interfaceW,(r1*interfaceH)/255); } if (mouseX > 1 && mouseX < interfaceW && mouseY > (interfaceH)) { g1 = ((255*mouseY)/(interfaceH)-255); //green noStroke(); fill(100,g1,100); //green box on left to gauge green value rect(0,interfaceH,interfaceW, interfaceH); stroke(255-backc); line(0,(g1*interfaceH)/255+(interfaceH),interfaceW,(g1*interfaceH)/255+(interfac eH)); //line to tell green value } //right INNER circle if (mouseX > width-interfaceW && mouseY < (interfaceH)) { r2 = ((255*mouseY)/(interfaceH)); //red fill(r2+50,50,50); //red box on RIGHT to gauge red value of inner circle noStroke(); rect(width-interfaceW,0,interfaceW, interfaceH); //line to guage red value of inner circle stroke(255-backc); line(width-interfaceW,(r2*interfaceH)/255,width,(r2*interfaceH)/255); } if (mouseX > width-interfaceW && mouseY > (interfaceH)) { g2 = ((255*mouseY)/(interfaceH)-255); noStroke(); fill(100,g2,100); //green box on RIGHT to gauge green value of inner circle rect(width-interfaceW,interfaceH,interfaceW, interfaceH); stroke(255-backc); line(width-interfaceW,(g2*interfaceH)/255+(interfaceH),width,(g2*interfaceH)/255 +(interfaceH)); //line to tell green value } //blue TOP if (mouseX > 1 && mouseX < topbarW && mouseY < topbarH) { //outer circle, blue control b1 = ((255*mouseX)/(topbarW)); noStroke(); fill(100,100,b1); //blue box on top L to gauge blue value rect(0,0,topbarW, topbarH); //line to guage blue value stroke(255-b1); line(b1*topbarW/255,0,b1*topbarW/255,topbarH); } if (mouseX > 1 && mouseX > topbarW && mouseY < topbarH) { b2 = ((255*mouseX)/(topbarW)-255); noStroke(); fill(100,100,b2); //blue box on top R to gauge blue value rect(topbarW, 0, width, topbarH); stroke(255-backc); line((b2*topbarW)/255+topbarW, 0, (b2*topbarW)/255+topbarW,topbarH); //line to tell blue value } // display the spots: for(int i=0;i<foo.length;i++) { foo[i].display(); } } class Spot { float x, y, radius; float vx,vy; // to store velocities color colour; Spot(float xpos, float ypos, float r, color c) { x = xpos; y = ypos; vx = random(-1,1); // create small random horizontal velocity vy = 1 + random(3); // set a vertical velocity radius = r; colour = c; } void display() { color from = color(r1,g1,b1,a); color to = color(r2,g2,b2,a); color interA = lerpColor(from, to, .25); color interB = lerpColor(from, to, .5); color interC = lerpColor(from, to, .75); noStroke(); fill(from); ellipse(x, y, radius*5, radius*5); fill(interA); ellipse(x, y, radius*4, radius*4); fill(interB); ellipse(x, y, radius*3, radius*3); fill(interC); ellipse(x, y, radius*2, radius*2); fill(to); ellipse(x, y, radius, radius); x += vx*speed; y += vy*speed; // if mouseX = x and mouseY = y{ // x = mouseX; // y = mouseY; // } // else if x <> mouseX and y <> mouseY; { // } // If they go beyond the bottom of the screen one option is to simply place them back at the top: if(y > height + (maxRadius * 5)) { // by resetting all these it will look like a different ball int r = (int) random(100); int g = (int) random(100); int b = 155 + (int) random(100); colour = color(r,g