1

I tried to write vertical text on my graphical program created in Processing with this code in my draw() function.

  // Translate to where I want text to be.
  translate(20., 30.);

  // Center align text
  textAlign(CENTER);

  // Rotate text-to-be written by 270 degrees to make it vertical.
  rotate(270.);

  // Write vertical text.
  text("Some Vertical Text", 0, 0);

  // Undo rotation and translation.
  rotate(-270.);
  translate(-20., -30.);

However, this code does not rotate the text vertically. In fact, the text that is written is slanted neither vertically nor horizontally.

What is going on?

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206

1 Answers1

2

You have to specify the angle in radians. Try rotate(PI/2.0*3) instead. If you don't like using radians you can convert them with the radians(x) function. The end result looks like this: rotate(radians(270)).

Oh, and in general it's a better idea to use pushMatrix() to save the current translation/rotation/state and popMatrix to restore it afterwards instead of rotating back. Rotating often gives you small rounding errors that can quickly accumulate.

Simon
  • 1,814
  • 20
  • 37
  • Thanks! `rotate(3*PI/2)` rotated the text correctly. Also, thanks a lot for the advice on using a matrix stack. That will save me a lot of labor from now on in graphics programming (and is more accurate). – dangerChihuahua007 Feb 27 '12 at 00:52