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.
IndexProgramming Questions & HelpPrograms › Noob code needs "pimping" please help!
Page Index Toggle Pages: 1
Noob code needs "pimping" please help! (Read 576 times)
Noob code needs "pimping" please help!
Sep 25th, 2007, 11:06am
 
Hi I've been struggling with this code and have finally got it to work.

It reads a txt file and displays two different coloured square depending on the character in the string (either 0 or 1).

It works but it looks dire...
i been looking at the code for PushPop Cubes and would like to use this to display the information with maybe different lighting to show the difference. I've tried unsuccessfully for  two days with no joy.

could anyone please help

here is the simple code pre-pimped


void setup () {

fill (255,255,255);
size(800, 600);
background (255, 255, 255);

frameRate(1);



}




void draw (){


float x = random (0,0);
float y = random (0,0);
float z = random (0,770);
float a = random (0,570);
color black = color(0,0,0);
color green = color(0,255,0);
color red = color(255, 0, 0);
color normal = color(0, 0, 255);
color outside = color(255, 255, 255);

String lines[] = loadStrings("list.txt");
// for each line..
for (int i = 0; i < lines.length; i++) {
 // for each character in the line
 for (int j = 0; j < lines[i].length(); j++) {
   char c = lines[i].charAt(j);  
   if (c == '0') { delay (50);
fill (green);
rect(x + random (780), y+ random (570), 30, 30); // They are equal so this line will print

 ; } else {
fill (red);
rect(x + random (780), y+ random (570), 30, 30); // They are equal so this line will print

   }
 }
}
loop();



}

ManyThanks

Bosscock
Re: Noob code needs "pimping" please hel
Reply #1 - Sep 25th, 2007, 12:30pm
 
Here is a cleaned up version of your code. I got rid of all the variables that you aren't using and moved the load of the txt file into setup. If you load during draw you'll be doing a load each frame.

Just a thought, if you are drawing the rect in a random spot do you need to use the list.txt file at all? would you get a similar result by just getting a random(1) and testing to see if it was above or below 0.5. and then using that to switch the color?

hope this helps out.


Quote:


String lines[];
color green = color(0,255,0);
color red = color(255, 0, 0);
float w = 30;

void setup () {
 size(800, 600);
 background (255, 255, 255);
 lines = loadStrings("list.txt");  
 frameRate(5);
}


void draw (){
 // for each line..  
 for (int i = 0; i < lines.length; i++) {  
   // for each character in the line  
   for (int j = 0; j < lines[i].length(); j++) {
     char c = lines[i].charAt(j);  
     if (c == '0') {  
       fill (green);
     }
     else {  
       fill (red);
     }
     rect(random (width - w), random (height - w), w, w); // They are equal so this line will print  
   }  
 }
}
Re: Noob code needs "pimping" please hel
Reply #2 - Sep 25th, 2007, 1:11pm
 
Thanks for cleaning up the code, the list.txt refers to search engine keywords this  has been converted to a series of 0 and 1.  As you can see its very  basic and hence this post.
thanks again.
Bosscock
Page Index Toggle Pages: 1