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 › Rotate type on a circle
Page Index Toggle Pages: 1
Rotate type on a circle (Read 289 times)
Rotate type on a circle
Jan 7th, 2009, 5:36pm
 
Hy forum,

I try to rotate type around a circle, like on
http://www.pitchinteractive.com/img/oscar_vis.jpg

I managed to place the type in a circle form, but the type itself is rotating in a strange way.

Does anyone know how to do that in the right way?

PFont font;
void setup()
{
 size(500, 500);
 smooth();
 ellipseMode(LEFT);
}

void draw()
{
 font = createFont("Arial",10);
 background(55);
 // Save defaults
 pushMatrix();
 // Move origin
 translate(width/2, height/2);
 // And draw
 type();
 popMatrix();

 noLoop();
}
void type()
{
 //Rotate the type 10 degrees in every step
 for (int i=0; i<36; i++){
   float degree = radians((360.0/36));  
   rotate(degree);
   fill(255);
   textFont(font);
   textAlign(LEFT);
   text(i,100,100);
 }
}
Re: Rotate type on a circle
Reply #1 - Jan 8th, 2009, 12:30am
 
I got good result by resetting the rotation each time...
Code:
PFont font;
int NB = 36; // Constants makes changes easier
void setup()
{
size(500, 500);
smooth();
// ? LEFT isn't an ellipseMode option
// ellipseMode(LEFT);
// Don't do that in draw()!
// (OK, it was done only once in your sketch, but I was afraid!) :-)
font = createFont("Arial", 10);
// Constant settings should be done once
textFont(font);
textAlign(LEFT);
background(55);
// Move origin
translate(width/2, height/2);
// And draw
type();

// If you use noLoop, no need for draw() routine
noLoop();
}

void type()
{
fill(255);
for (int i=0; i<NB; i++){
// angle moves from 0 to 2 PI (almost)
float ang = i*TWO_PI/NB;
// Save defaults
pushMatrix();
rotate(ang);
translate(0, -100);
text(i, 0, 0);
translate(0, 230); // Doing a translate(0, 130)
text(i, 0, 0);
// Restore default
popMatrix();
}
}
Re: Rotate type on a circle
Reply #2 - Jan 8th, 2009, 2:10pm
 
Thank you so much! It works perfect. Also thanx for the syntax hints - I have much to learn...
Page Index Toggle Pages: 1