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 & HelpSyntax Questions › noob loadstring question
Page Index Toggle Pages: 1
noob loadstring question (Read 490 times)
noob loadstring question
Apr 13th, 2006, 10:47am
 
HI everyone, I’m new to Processing and have been fighting my way through my first attempts at coding and now need some help.  I don’t want anybody to post the code just yet (that would be too easy and spoil then fun), any pointers/explanation as to how I go about the following, please then if I can’t do it I’ll post again.

My project is to load a text file that contains a large string of “0” and “1” (at the moment not delimited but could be if needed).  I want processing to check the first char/ and if it’s a “0” then print a blue rect, if it’s a “1” then a red rect.


I can load the file ok using loadstring and I can write the code for displaying the rect.  But I can’t seem to find any information (also through lack of programming knowledge) on how processing would read the first char,  draw rect  then read the second char draw rect, read the third char, etc, etc.

The text/dat file ( advice as to which to use please) would contain thousands of chars (hopefully) and would be processed through a database first then fed into processing

Any help will be greatly appreciated,

Thank in advance


Neill
Re: noob loadstring question
Reply #1 - Apr 13th, 2006, 12:22pm
 
Re: noob loadstring question
Reply #2 - Apr 13th, 2006, 12:25pm
 
thanks for that ,could you elaborate abit more..please..I'm using loadstring but i unsure as to what "method" refers to ?

thanks
Re: noob loadstring question
Reply #3 - Apr 13th, 2006, 12:36pm
 
I've looked up the methods now on referencce section but i don't see anthing relevant to char...

sorry if i'm missing the oblivous, but my head already inploding from trying to right code

Neill
Re: noob loadstring question
Reply #4 - Apr 13th, 2006, 12:45pm
 
Code:

String lines[] = loadStrings("onesandzeros.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') {
drawBlueRect();
} else {
drawRedRect();
}
}
}
Re: noob loadstring question
Reply #5 - Apr 13th, 2006, 1:18pm
 
Thankyou very very much.........
Neill
Re: noob loadstring question
Reply #6 - Apr 13th, 2006, 1:24pm
 
It works and has opened so many new doors...thank you Mr Fry for taking the time... which is oblivously  such a simple code to you, but was stumbling block for me.
Page Index Toggle Pages: 1