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 › make a shape when the char is detected
Page Index Toggle Pages: 1
make a shape when the char is detected (Read 323 times)
make a shape when the char is detected
Dec 17th, 2008, 6:29pm
 
I need help with this.

I got a file that detects something it displays text on println "I got C"

String lines[] = loadStrings("text3.txt");
for (int i=0; i < lines.length; i++) {
 println(lines[i]);
 if(lines[i].equals("C"))
 {
   println("I got C");
 }
}

And I made a file, when it detects the "C", it makes a rectangle.
The code is :

String lines[] = loadStrings("text3.txt");
for (int i=0; i < lines.length; i++) {
 println(lines[i]);
 if(lines[i].equals("C"))
 {
   rect (0,0,10,10);
 }
}

The problem is, there are many more "C", I need to make rectangle for each "C" but in DIFFERENT position, not all in the same position. How can I do that?
Re: make a shape when the char is detected
Reply #1 - Dec 17th, 2008, 6:33pm
 
also i need to break the line when when it goes to size 100, it needs to go back to (0,20) ----> then (0,30) etc.

thanks
Re: make a shape when the char is detected
Reply #2 - Dec 18th, 2008, 8:02pm
 
Code:
//String lines[] = loadStrings("text3.txt");
// Too lazy to create the file...
String lines[] = {
   "A", "S", "C", "T", "B", "S", "H", "B", "C", "H",
   "H", "T", "B", "A", "H", "C", "S", "T", "S", "T",
   "T", "B", "A"
};

void setup()
{
 size(400, 400);
 smooth();
 noLoop();
 ellipseMode(CORNER);
 rectMode(CORNER);

 int posX = 0, posY = 0;
 int shapeSize = 40; // Switch back to 10
 for (int i = 0; i < lines.length; i++)
 {
   println(lines[i]);
   if (lines[i].equals("A"))
   {
     fill(#000080);
     triangle(posX, posY + shapeSize,
         posX + shapeSize, posY + shapeSize,
         posX + shapeSize/2, posY);
   }
   else if (lines[i].equals("B"))
   {
     fill(#880000);
     ellipse(posX, posY, shapeSize, shapeSize);
   }
   else if (lines[i].equals("C"))
   {
     fill(#FF0000);
     arc(posX, posY, 2*shapeSize, shapeSize, PI - PI/3, PI + PI/3);
   }
   else if (lines[i].equals("H"))
   {
     fill(#008000);
     rect(posX, posY, shapeSize, shapeSize);
   }
   else if (lines[i].equals("S"))
   {
     fill(#0000FF);
     ellipse(posX, posY, shapeSize, shapeSize);
   }
   else if (lines[i].equals("T"))
   {
     fill(#00FF00);
     rect(posX, posY, shapeSize, shapeSize);
   }
   posX += shapeSize;
   if ((i + 1) % 10 == 0)
   {
     posX = 0; posY += shapeSize;
   }
 }
}
Page Index Toggle Pages: 1