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 › Rotating single letters
Page Index Toggle Pages: 1
Rotating single letters (Read 574 times)
Rotating single letters
Dec 28th, 2007, 3:26pm
 
Hello! After solving yesterday's problem of water ripples, a new one occured: I want the letters of a String to rotate and behave like a nice alphabet soup ;)
I tried different ways. I've split the String with a CharAt command and played around with some rotate() and scale(), but the results are very bad. I found some interesting libaries, like traer.physics or NextText. But i was wondering if i can handle this problem without using any complicated libary?!

Here's how i done it so far. Problem is that the letters are not flying away as a circle, but as kind of a helix. Heres the code:

import processing.opengl.*;

PFont fontRegular;


String buchstaben[] = new String[500];
float count = 1;
String flashWord;


float [] myPosX = new float[500];
float [] myPosY = new float[500];

void setup() {  
 size(1024,786,OPENGL);  
 fontRegular = createFont("Monaco", 16);
 textFont(fontRegular);
 smooth();
flashWord = "Dietmar Bartsch hat einen Preis gewonnen!";
flashWord = flashWord.toUpperCase();
  for(int i=0; i < flashWord.length(); i++) {
   buchstaben[i] = flashWord.substring(i,i+1);
 }
}  

void draw() {
 background(#364d76);

 for(int i=0; i < flashWord.length(); i++) {
 
   noStroke();
   fill(0);
   textAlign(CENTER);
 
//  text(buchstaben[i], width/2-150+i*10, height/2);
   
   myPosX[i] = count*cos(TWO_PI/flashWord.length()*i) + width/2-250+i*10;
   myPosY[i] = count*sin(TWO_PI/flashWord.length()*i) + height/2;
   
   if(i < 50) {
   pushMatrix();
   translate(myPosX[i], myPosY[i]);
   fill(#b8bddd, random(30,100));
   textAlign(CENTER);
   text(buchstaben[i], random(0,2), random(0,2));
   popMatrix(); }
   
   if(i > 50 && i < 100) {
   pushMatrix();
   translate(myPosX[i]-500, myPosY[i]+16);
   fill(#b8bddd, random(30,100));
   textAlign(CENTER);
   text(buchstaben[i], random(0,2), random(0,2));
   popMatrix(); }
   
   
   
   }
 
 count = count + 0.25f;
 if (count >= 600) {
   count = 1;
 }
}




I'm thankful for any advice or hint,

greets
Re: Rotating single letters
Reply #1 - Dec 28th, 2007, 8:05pm
 
Quote:
myPosX[i] = count*cos(TWO_PI/flashWord.length()*i) + width/2-250+i*10;

what is that expression " -250+i*10 " supposed to do?

removing it gives a perfect circle.
Re: Rotating single letters
Reply #2 - Dec 28th, 2007, 8:13pm
 
Yeah, this is beause in the beginning there's a readable sentence "Dietmar Bartsch hat einen Preis gewonnen!" written like a normal text() command. After this the letters should begin to arrange in a circle which gets bigger and bigger.

The X position width/2-250+i*10 arranges them exactly as the text(), because i used monospaced type (10 px for every letter).

Any suggestion? Wink
Re: Rotating single letters
Reply #3 - Dec 29th, 2007, 7:41pm
 
oh ok, I got it : you want to start with inline text, and then move every letter to end with a circle. I've made something similar with thumbnails images and traer.physics library was definitly helpful. check this :

http://n.clavaud.free.fr/processing/photos/
Page Index Toggle Pages: 1