Last active
April 18, 2019 16:07
-
-
Save wonderburg7/e8d368945729cc54fec3ab6232753e85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Example Characters along a curve | |
// The message to be displayed | |
String message = "Astro-Penelo Mining Corp - "; | |
PFont f; | |
// The radius of a circle | |
float r = 85; | |
int rotationCount = 0; | |
int fontSize= 40; | |
void setup() { | |
size(320, 320); | |
f = createFont("Arial Bold", fontSize,true); | |
textFont(f); | |
// The text must be centered! | |
textAlign(CENTER); | |
smooth(); | |
} | |
void draw() { | |
background(255); | |
pushMatrix(); | |
// Start in the center and draw the circle | |
translate(width / 2, height / 2); | |
rotate(radians(rotationCount)); | |
noFill(); | |
stroke(0); | |
// ellipse(0, 0, r*2, r*2); | |
// We must keep track of our position along the curve | |
float arclength = 0; | |
// For every box | |
for (int i = 0; i < message.length(); i++) | |
{ | |
// Instead of a constant width, we check the width of each character. | |
char currentChar = message.charAt(i); | |
float w = textWidth(currentChar); | |
// Each box is centered so we move half the width | |
arclength += w/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; | |
pushMatrix(); | |
// Polar to cartesian coordinate conversion | |
translate(r*cos(theta), r*sin(theta)); | |
// Rotate the box | |
rotate(theta+PI/2); // rotation is offset by 90 degrees | |
// Display the character | |
fill(0); | |
text(currentChar,0,0); | |
popMatrix(); | |
// Move halfway again | |
arclength += w/2; | |
} | |
popMatrix(); | |
rotationCount--; | |
//saveTransparentCanvas(BG, "img"); | |
if (rotationCount == 360){ | |
rotationCount = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment