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 › String Difficulties...
Page Index Toggle Pages: 1
String Difficulties... (Read 317 times)
String Difficulties...
Mar 26th, 2008, 1:20am
 
Hello,

I am trying to make an image of the bible, as someone with Letter-Color Synaesthesia would see it (kind of - I have not mapped the correct colors yet).  I have made a huge text file of the entire bible (and removed line breaks) and want to read this in with the program below.

I have tried two ways and have had trouble with both.

First I just pasted the whole text of the bible in as a string (str1).  This caused the program to crash because it was too long.

Then I wanted to read from a file, but I am not sure how to go about doing that as once I read from a file the "char letter = str1.charAt(z);" is no longer working.

The code (it is rough) is below.  Any help would be greatly appreciated.

Daniel

Quote:


String str1 = "aaasdf";
String str2[] = loadStrings("test.txt");

int numChars = 26;
color[] colors = new color[numChars];

int x=0;
int y=0;

void setup()
{
 size(1000, 1000);
 noStroke();
 colorMode(RGB, numChars);
 background(numChars/2);
 // Set a gray value for each key
 for(int i=0; i<numChars; i++) {
   colors[i] = color(0, 0, i);    
 }
}

void draw() {
for(int z=0; z<str1.length(); z++) {

char letter = str1.charAt(z);
if ( letter >= 'A' && letter <= 'z') {
 if (letter <= 'Z') {
   fill(colors[letter - 'A']);
 } else {
   fill(colors[letter - 'a']);
 }
 rect(x,y, 5,5);

   x+=5;

   if (x > width-5) {
     y+=5;
     x=0;
     }
   }
 }
}



Re: How to deal with long string...
Reply #1 - Mar 26th, 2008, 2:54am
 
you probably need this

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1205630251
Re: String Difficulties...
Reply #2 - Mar 26th, 2008, 6:46am
 
I am not sure I understand what is going on in that example.  Basically, I think what I want to do is simple:

1. Open text file
2. Read each letter (all 1 million of them or so) sequentially and use the ascii value to determine the color value of the pixel drawn on the screen.

Any simple way to do this?  why does str2.charAt(z) not work?

Thanks!

Daniel
Re: String Difficulties...
Reply #3 - Mar 26th, 2008, 10:48am
 
Dude i really think that example is the simplest way to do it. Because from what you've said, just loading up all the strings is causing java to crash.

Just read through that bit about how to random access files and you've got it.


Page Index Toggle Pages: 1