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?
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 theradians(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 andpopMatrixto restore it afterwards instead of rotating back. Rotating often gives you small rounding errors that can quickly accumulate.