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 & HelpPrograms › How to rotate one PFont letter around it's center
Page Index Toggle Pages: 1
How to rotate one PFont letter around it's center? (Read 1607 times)
How to rotate one PFont letter around it's center?
Aug 25th, 2007, 2:31am
 
I'm trying to rotate a single font character (a dingbat) around it's actual center. The code below rotates it on the baseline (I think). How can I get it to rotate around the exact center of the character like an PImage would do?

import processing.opengl.*;

PFont f;
int r = 0;
void setup() {
 f = loadFont("Mato.vlw");
 size(500,500, OPENGL);
 textFont(f, 80);
 frameRate(30);
 smooth();
}

void draw() {
 background(200, 100, 200);
 fill(0);
 pushMatrix();  
 translate(100,100);
 rotate(r++);  
 text("W", 0,0);
 popMatrix();
}
Re: How to rotate one PFont letter around it's cen
Reply #1 - Aug 25th, 2007, 6:20am
 
import processing.opengl.*;

PFont f;
float r = 0;  
void setup() {
 f = createFont("engel.ttf",80);
 size(500,500, OPENGL);
 textFont(f, 80);
 frameRate(30);
 smooth();
}

void draw() {
 background(200, 100, 200);
 fill(0);
 pushMatrix();  
 translate(100,100);
 rotate(r+=5);  
 text("W", -textWidth("W")/2.0,40);
 popMatrix();
}
Re: How to rotate one PFont letter around it's cen
Reply #2 - Aug 26th, 2007, 1:59am
 
but put size() first! that code will load the ttf twice.
Re: How to rotate one PFont letter around it's cen
Reply #3 - Aug 26th, 2007, 2:29am
 
ah, ok, sorry ;)
Re: How to rotate one PFont letter around it's cen
Reply #4 - Sep 14th, 2007, 3:21am
 
Close, but it still doesnt take into account the font's blank areas, it doesnt QUITE rotate around the center. Close!
Re: How to rotate one PFont letter around it's cen
Reply #5 - Sep 14th, 2007, 12:37pm
 
use textAlign(CENTER, CENTER) before calling rotate.
Page Index Toggle Pages: 1