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 › how to draw text vertically
Page Index Toggle Pages: 1
how to draw text vertically (Read 362 times)
how to draw text vertically
Aug 20th, 2008, 11:20pm
 
hey,
 i was wondering if it is possible to draw text vertically using processing (like along the Y-Axis of a graph)?  Note that I don't mean one letter on top of the next, but rather a line of text that is rotated 90 degrees.

Thanks,
-d
Re: how to draw text vertically
Reply #1 - Aug 21st, 2008, 1:30am
 
Something like this?

Quote:
PFont myFont;

void setup()
{
  size(400,400);
  smooth();
 
  fill(0);
  myFont = createFont("sans-serif",32);
}

void draw()
{
  background(255);
  textFont(myFont);
  
  int x = 10;     // Location of start of text.
  int y = 100;
  
  pushMatrix();
  translate(x,y);
  rotate(HALF_PI);
  translate(-x,-y);
  text("Some text here", x,y);
  popMatrix();
}


The key is to translate the text to the origin before rotating it (specified in radians), then translate back. Encasing the transformation in a push/pop matrix ensures that the transformation does not interfere with any drawing in the sketch.
Re: how to draw text vertically
Reply #2 - Aug 21st, 2008, 5:08am
 
This can be simplified by skipping translating back.  You can just draw the text at (0,0) once you've translated:

Code:

pushMatrix();
translate(x,y);
rotate(HALF_PI);
text("Some text here",0,0);
popMatrix();


Also, you may want to use textAlign(CENTER) if you want the text to rotate around the center (as opposed to the beginning of the text.)
Page Index Toggle Pages: 1