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 › Polygon Generator
Page Index Toggle Pages: 1
Polygon Generator (Read 1812 times)
Polygon Generator
Oct 28th, 2009, 12:21pm
 
Hi,
I would like to build a program but since I am new to Processing, I am not really sure how difficult it will be. Could you help me find some builidng concepts, or a link to someone who has already done this before?

Maybe there is a link somwhere on the forum that I have missed....

I know I am asking for a lot, but I feel really lost here....... I don't know where to start.... !!!!!!!!!!


THE PROJECT:
I want to be able to type in a word or a sentence. Then depending on the word I have typed in, I want the program to generate a different polygon each time.

How will it work?
1. every word will be broken up into separate characters
2. every character translated in its numeric value
3.  every pair of values will determine the coordinates of one vertex point.


That's not all I want my generator to do, but It would give me a good kickstart ...

Thank you for any help ...... !!!
Kim
Re: Polygon Generator
Reply #1 - Oct 28th, 2009, 1:46pm
 
Typing: keyTyped() (or use a GUI like controlP5)
Breaking words: see HELP..breaking down words into single char
Translate chars to number: well, I wasn't sure so I made a micro-sketch:
Code:
char[] ca = "AFooBar".toCharArray();
for (int i = 0; i < ca.length; i++)
{
println(Character.codePointAt(ca, i));
}

Of course, the range is a bit limited...
Re: Polygon Generator
Reply #2 - Oct 28th, 2009, 2:02pm
 
Sounds a bit like this...
http://www.esono.com/boris/projects/poetry04/

http://www.esono.com/boris/projects/poetry04/visualpoetry04/index.html
Re: Polygon Generator
Reply #3 - Oct 28th, 2009, 4:24pm
 
Thanks a lot for answering so quickly! It's getting late over here in Paris. I'll check it out tomorrow !
Re: Polygon Generator
Reply #4 - Oct 31st, 2009, 7:34am
 
I've been workin on it for a couple days now... Still not working ...
I havn't been able to implement your micro-sketch PhiLho....
Processing returns a bug in my code "cannot convert from String[] to String" on the line: Code:
String broken = myTextfield.getText().split("");"  


I've been playing around with the code but can't get it to work .....

Code:

import controlP5.*;

ControlP5 controlP5;

public int myColorBackground = 100;

void draw() {
 background(myColorBackground);
}

Textfield myTextfield;

void setup() {
 size(400,400);
 frameRate(25);
 controlP5 = new ControlP5(this);
 myTextfield = controlP5.addTextfield("text1",100,290,100,20);
}


void controlEvent(ControlEvent theEvent) {
 String broken = myTextfield.getText().split("");
 char[] ca = broken.toCharArray();
 for (int i = 0; i < ca.length; i++)
   {
   println(Character.codePointAt(ca, i));
   }
}



Cedric: Thanks for the link, it is indeed very similar to what I want to do, only once I finish my sketch I want it to generate shapes automatically from words in a RSS feed... Too bad your link is in flash, it would have made my life much easier... !!!!!!

THANK YOU FOR THE HELP !
Re: Polygon Generator
Reply #5 - Oct 31st, 2009, 8:52am
 
Well, that's not what I gave... Smiley
In your case, that would be something like:
String input = myTextfield.getText();
String[] broken = input.split(""); // Defines and gets an array of strings

but you have to choose between this solution and the toCharArray!

Let's take the latter, easier to convert to numbers.
Here is a possible way to using input:
Code:
import controlP5.*;

ControlP5 controlP5;

int myColorBackground = 100;
int boxSize = 20;
char[] broken;

void draw() {
 background(myColorBackground);
 if (broken != null)
 {
   int cc;
   for (int i = 0; i < broken.length; i++)
   {
cc = Character.codePointAt(broken, i) - 32;
if (cc < 30)
{
 cc = (int) map(cc, 0, 30, 0, 255);
 fill(100, cc, 255 - cc);
}
else if (cc < 60)
{
 cc = (int) map(cc, 30, 60, 0, 255);
 fill(cc, 100, 255 - cc);
}
else if (cc < 120)
{
 cc = (int) map(cc, 60, 120, 0, 255);
 fill(cc, 255 - cc, 100);
}
else
{
 cc = (int) map(cc, 120, 255, 0, 255);
 fill(cc, 255 - cc, cc / 2);
}

rect(10 + i * boxSize, 10, boxSize, boxSize);
   }
 }
}

Textfield myTextfield;

void setup() {
 size(800, 400);
 frameRate(25);
 controlP5 = new ControlP5(this);
 myTextfield = controlP5.addTextfield("text1", 100, 290, 100, 20);
 myTextfield.setFocus(true);
}


void controlEvent(ControlEvent theEvent) {
 String input = myTextfield.getText();
 broken = input.toCharArray();
}

Ugly, but it might give you some ideas... (use upper and lower case, symbols, accented chars, etc.).
Re: Polygon Generator
Reply #6 - Nov 4th, 2009, 8:13am
 
Thanks for the inspiration, it's really helping.... Almost finished !
Page Index Toggle Pages: 1