We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › Bouncing ball help wanted!
Page Index Toggle Pages: 1
Bouncing ball help wanted! (Read 2310 times)
Bouncing ball help wanted!
Jan 23rd, 2008, 7:52pm
 
Hi!

I have started a projectblog about my home made Arduino spectrophotometer and want some Processing input (You can see the blog at: http://fun-myprojects.blogspot.com/

And I have some question about individual colouring(fill) of multiple bouncing balls (Sketch found in Proccessing....Reas, Fry book)that im thinking of using for visualizing the recorded data.

Main question: How could I colour them individually?
(I`ve changed a few things myself from the original code)

Grateful for all kinds of input!!!

The code im thinking about is this:


Spot sp1; // Declare the object
Spot sp2;
Spot sp3;
Spot sp4;
Spot sp5;

void setup() {
 size(300, 250);
 smooth();
 noStroke();
 sp1 = new Spot(50, 100, 15, 0.5); // Construct the object
 sp2= new Spot(100,100,50,0.1);
 sp3= new Spot(150,100,40,5.0);
 sp4= new Spot(200,100,30,3.0);
 sp5= new Spot(250,100,20,1.2);
 
}

void draw() {
 fill(0, 15);
 rect(0, 0, width, height);
 fill(334,5,8);
 sp1.move();
 sp1.display();
 sp2.move();
 sp2.display();
 sp3.move();
 sp3.display();
 sp4.move();
 sp4.display();
 sp5.move();
 sp5.display();
 
 
 
}

class Spot {
 float x, y; // X-coordinate, y-coordinate
 float diameter; // Diameter of the circle
 float speed; // Distance moved each frame
 int direction = 1; // Direction of motion (1 is down, -1 is up)
 
 // Constructor
 Spot(float xpos, float ypos, float dia, float sp) {
   x = xpos;
   y = ypos;
   diameter = dia;
   speed = sp;
 }

 void move() {
   y += (speed * direction);
   if ((y > (height - diameter / 2)) || (y < diameter / 2)) {
     direction *= -1;
   }
 }

 void display() {
   ellipse(x, y, diameter, diameter);
 }
}
Re: Bouncing ball help wanted!
Reply #1 - Jan 23rd, 2008, 8:15pm
 
Additional information about the project

I will record resistance values from 5 LDR (collected light from beam passed through yeast suspension (growing cells) within 15 minute intervals on an Arduino. anolog values and I want to show the optical density(And Yes, the resistance values will be calibrated against an real spectrophotometer),growth rate(difference in OD values from t0 to tx, and calculate the change in growth rate (Do the cells speed up,divide faster, or down compared to t=before). These three parameters I want to visualise in Processing and save to ".csv" file so I could use it in Excel at later stage.

OD = radius of the bouncing ball
Growth rate= speed of the ball
Growth rate change = colour of the ball

Five balls, three parameters, 5 input channels,15 min between measurements, hours of working time(collection of data), one output channel(.csv file)...

and so fun to learn to program in Processing... and Arduino

inputs? Comments?

I need some new ideas...






Re: Bouncing ball help wanted!
Reply #2 - Jan 23rd, 2008, 8:16pm
 
add a 'color' variable to the Spot class (that you will pass or set in the constructor) :
Code:
class Spot {
color c;
...
}

and use it in the display() method just before you draw the ellipse :
Code:
void display() {
fill(c);
ellipse(x, y, diameter, diameter);
}
Re: Bouncing ball help wanted!
Reply #3 - Jan 23rd, 2008, 8:37pm
 
Seems to work fine!!!

Thanks!!!

Now I will start thinking of how to condition(Color green<X(yellow)>red )the whole thing...

Re: Bouncing ball help wanted!
Reply #4 - Jan 24th, 2008, 10:10pm
 
Hi again!

Now I´ve got the visual look of the program. In the white boxes the I will display the data from the Arduino and calculated values. And I would like to ba able to change the coloring of the balls(color not in gray scale...)

I thought I solved it yesterday but i didn´t...

How can I get it in HSB color? Where do I write the code? In draw or in constructor(I have tried several places but it didn´t work)

Here is the "visual" (interface) code...
Now the tricky bit starts...Smiley



Spot sp1; // Declare the object
Spot sp2;
Spot sp3;
Spot sp4;
Spot sp5;




void setup() {

 size(500, 250);
 smooth();
 noStroke();
 sp1 = new Spot(180,50, 100, 15, 0.5); // Construct the object
 sp2= new Spot(50,100,100,50,1.1);
 sp3= new Spot(180,150,100,40,5.0);
 sp4= new Spot(255,200,100,30,3.0);
 sp5= new Spot(180,250,100,20,1.2);
 
}

void draw() {
 
 fill(0, 15);
 rect(0, 0, width, height);
 fill(0);
 sp1.move();
 sp1.display();
 sp2.move();
 sp2.display();
 sp3.move();
 sp3.display();
 sp4.move();
 sp4.display();
 sp5.move();
 sp5.display();
 rect(300,0,200,250);
PFont font;
font = loadFont("Tahoma-Bold-12.vlw");
textFont(font);
fill(255);
text(" Description",310,25);
text("OD",5,220.5);
text("\u00B5",10,18.5);
text("\u2206\u00B5",5,35.5);
text("-TubeSpec\u2122-",115,240);
fill(0);
text("Speed=Growth rate",330,50);
text ( "Ball size = Optical density",330,68);  
text("Ball colour=",330,86);
text("White",330,110);
text("Increased Growth rate",330,122);
text("Gray",330,146);
text("Unchanged Growth rate",330,158);
text("Dark gray",330,182);
text("Decreased Growth rate",330,194);
fill(255);
rect(23,5,45,12.5);
rect(75,5,45,12.5);
rect(127,5,45,12.5);
rect(178,5,45,12.5);
rect(228,5,45,12.5);

rect(23,23.5,45,12.5);
rect(75,23.5,45,12.5);
rect(127,23.5,45,12.5);
rect(178,23.5,45,12.5);
rect(228,23.5,45,12.5);

rect(23,208.5,45,12.5);
rect(75,208.5,45,12.5);
rect(127,208.5,45,12.5);
rect(178,208.5,45,12.5);
rect(228,208.5,45,12.5);

}

class Spot {
 color c; // fill color
 float x, y; // X-coordinate, y-coordinate
 float diameter; // Diameter of the circle
 float speed; // Distance moved each frame
 int direction = 1; // Direction of motion (1 is down, -1 is up)
 
 // Constructor
 Spot(color colour,float xpos, float ypos, float dia, float sp) {
   
   c = colour;
   x = xpos;
   y = ypos;
   diameter = dia;
   speed = sp;
   
 }

 void move() {
   y += (speed * direction);
   if ((y > -50+(height - diameter / 2)) || (y < 50+ (diameter / 2))) {
     direction *= -1;
   }
 }

 void display() {
   fill(c);
   ellipse(x, y, diameter, diameter);
 }
}

Re: Bouncing ball help wanted!
Reply #5 - Jan 25th, 2008, 4:18pm
 
step 1. please have a look to the reference :
http://processing.org/reference/color_.html
and http://processing.org/reference/colorMode_.html

step 2. set the color mode to HSB, then pass a color(H, S, B) instead of a simple integer in your Spot constructor :
Code:
sp1 = new Spot(color(h, s, b), 50, 100, 15, 0.5); 



step 3. instead of using 5 different Spot variables, you could use an array :
Code:
// general:
Spot[] sp;

Code:
// in setup:
sp = new Spot[5];
sp[0] = ...
...
sp[4] = ...

Code:
// in draw:
for (int i = 0; i < sp.length; i++) {
sp[i].move();
sp[i].display();
}
Page Index Toggle Pages: 1