我尝试在我的draw()
函数中使用此代码在Processing中创建的图形程序中写入垂直文本。
// 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.);
但是,此代码不会垂直旋转文本。实际上,写入的文本既不垂直也不水平倾斜。
发生了什么事?
答案 0 :(得分:2)
您必须以弧度指定角度。请尝试使用rotate(PI/2.0*3)
。如果您不喜欢使用弧度,可以使用radians(x)
函数进行转换。最终结果如下所示:rotate(radians(270))
。
哦,一般情况下,最好使用pushMatrix()
来保存当前的平移/旋转/状态,然后使用popMatrix
将其恢复,而不是向后旋转。旋转通常会给您带来很小的舍入误差,可以快速累积。