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 › Newbie Question About Radial Convergence
Page Index Toggle Pages: 1
Newbie Question About Radial Convergence (Read 615 times)
Newbie Question About Radial Convergence
Oct 24th, 2007, 5:02am
 
Hello,
I am interested in creating a radial convergence visualization  (circle with text nodes along the circumference) similar to Schemaball or Circos.  Is there a native way in processing to add these text nodes or is this something that has to be hand coded?  If so, does anyone know if there is an existing library for this?

Thanks for your patience
Re: Newbie Question About Radial Convergence
Reply #1 - Oct 24th, 2007, 7:43am
 
I haven't seen any native or external facility to do this, but it's not so hard to code, using 'translate' and 'rotate' methods :

Code:
size(200, 200);
PFont font = loadFont("ArialNarrow-12.vlw");
textFont(font, 12);

background(255);
fill(0);
translate(width/2, height/2);
for (float a = 0; a < TWO_PI; a+= PI/6) {
rotate(PI/6);
text("some text", 40, 0);
}
Re: Newbie Question About Radial Convergence
Reply #2 - Oct 24th, 2007, 10:05am
 
here is a 'drawText()' method you can reuse :

Code:
void drawText(String s, float x, float y, float radius, float angle, boolean invert) 


- 's' is the string to write,
- 'x' 'y' and 'radius' define the center + radius of the circle the text will be written around
- 'angle' is the position of the text around the circle
- 'invert' indicates whether the text has to be inverted or not (when angle is between PI/2 and 3*PI/2, you may want to use invert, so it's not written upside down)

Example :

Code:
void drawText(String s, float x, float y, float radius, float angle, boolean invert) {
pushMatrix();
if (invert) {
textAlign(RIGHT, CENTER);
translate(x, y);
rotate(angle);
translate (radius, 0);
pushMatrix(); rotate(PI); text(s, 0, 0); popMatrix();
} else {
textAlign(LEFT, CENTER);
translate(x, y);
rotate(angle);
translate(radius, 0);
text(s, 0, 0);
}
popMatrix();
}

void setup() {
size(200, 200);
PFont font = loadFont("ArialNarrow-12.vlw");
textFont(font, 12);
smooth();
noLoop();
}

void draw() {
background(255);
noFill();
ellipse(width/2, height/2, 40*2-5, 40*2-5);
fill(0);
int n = 12;
for (int i = 0; i < n; i++) {
float a = i*TWO_PI/n;
if (a >= PI/2 && a < 3*PI/2)
drawText("inside ->", width/2, height/2, 40, a, true);
else
drawText("outside ->", width/2, height/2, 40, a, false);
}
}
Re: Newbie Question About Radial Convergence
Reply #3 - Oct 25th, 2007, 1:17am
 
That worked great!

Thanks
Page Index Toggle Pages: 1