fullard
YaBB Newbies
Offline
Posts: 6
Re: turning text into a command
Reply #5 - Aug 5th , 2008, 6:11pm
O.k., i have followed the instructions offered by antiplastik and below is the code i have come up with. The problem i am having is that the void draw command is only reading the first and last set of drawing commands, i am aware the void draw() will only update after it has finished reading the block but i need it to update the visual for every character it meets, does any kind wise programmer have any suggestions for what i should do with the attached code to make the image refresh for every character it reads, i presume an alternative structure will be required but anything i have tried thus far has failed to improve it. Please and thanks. String s = "cab"; void setup(){ size (300, 300); // size of sketch s = s.toLowerCase(); // change string to lower case frameRate(0); // framerate } void draw(){ println(frameCount); // prints frame number at very start for (int i = 0; i < s.length(); i++) { // reads string and breaks it up into characters char ch = s.charAt(i); // position of each Character in the String switch(ch) { // acknowledge the character instead of the char function case 'a': println("-> a"); fill (240, 15, 15); // red rect (0,0, width, height); break; case 'b' : println("-> b"); fill (82, 193, 35); // blue rect (0,0, width, height); break; case 'c' : println("-> c"); fill (18, 59, 178); // green rect (0,0, width, height); break; } delay(2000); // slows programme here for two seconds frameCount ++; // starts next frame println(frameCount); // prints frame number between characters } noLoop(); println("--------------------> End"); }