Displaying two different Strings of text in a curve - (noob alert)
in
Programming Questions
•
2 years ago
Hi, I'm trying to display two Strings of text along two different curves in a sketch.
I'm bringing tweets in from an excel sheet thats 100 rows in length, and I want the first 50 to display off/around one circle and the next fifty to display off/around a second circle. I can do the first fifty alright, but I can't get the second lot to display around the second ellipse that I've drawn.
The code I've included is a slimmed down version of the code that I'm working with (the code I'm working with is a bit messy and long) but if I get it working on a basic level I can transfer it over.
Any and all help will be greatly appreciated!
Martin
- // The message to be displayed
- String message = "text";
- String message2 = "aaaa";
- PFont f;
- // The radius of a circle
- float r = 100;
- float q = r*2;
- float r2 = 100;
- float q2 = r2*2;
- void setup() {
- size(800, 800);
- f = createFont("Georgia",40,true);
- textFont(f);
- // The text must be centered!
- textAlign(CENTER);
- smooth();
- }
- void draw() {
- background(255);
- // Start in the center and draw the circle
- translate(width / 2, height / 2);
- noFill();
- stroke(0);
- ellipse(00, 00, r*2, r*2);
- ellipse (100, 50, r2*2, r2*2);
- // We must keep track of our position along the curve
- float arclength = 0;
- float arclength2 = 0;
- // Instead of a constant width, we check the width of each character.
- //char currentChar = message.charAt(i);
- float w = textWidth(message);
- float w2 = textWidth(message2);
- // Each box is centered so we move half the width
- arclength += w/2;
- arclength += w2/2;
- // Angle in radians is the arclength divided by the radius
- // Starting on the left side of the circle by adding PI
- float theta = PI + arclength / r;
- float theta2 = PI + arclength2 / r2;
- pushMatrix();
- // Polar to cartesian coordinate conversion
- translate(r*cos(theta), r*sin(theta));
- translate(r2*cos(theta2), r2*sin(theta2));
- // Rotate the box
- rotate(theta+PI/1); // rotation is offset by 90 degrees
- rotate(theta2+PI/1);
- // Display the character
- fill(0);
- text(message,q,0);
- text(message2,q2,0);
- popMatrix();
- // Move halfway again
- arclength += w/2;
- arclength += w2/2;
- //}
- }
1