/* * Code by Luke Loeffler * based on example code by Daniel Schiffman (learningprocessing.com) which draws text along a circle. */ String message = "text on a curve"; PFont f; ArrayList al = new ArrayList(); class P2 { float x; float y; public P2(float x, float y) { this.x=x; this.y=y; } } // The radius of a circle float r = 100; void setup() { size(800,600); f = createFont("Georgia",40,true); textFont(f); textAlign(LEFT); smooth(); } float curveLength(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { int steps = 50; // estimation steps more=more accurate float sum = 0; for(int i=0; i= 4) { for(int i=0; i<=al.size()-4; i++) { P2 p0 = (P2)al.get(i); P2 p1 = (P2)al.get(i+1); P2 p2 = (P2)al.get(i+2); P2 p3 = (P2)al.get(i+3); noFill(); strokeWeight(2.0); stroke(0,100); curve(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); } P2 p0 = (P2)al.get(0); P2 p1 = (P2)al.get(1); P2 p2 = (P2)al.get(2); P2 p3 = (P2)al.get(3); float t=0; float curvelength = curveLength(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); float textLength = textWidth(message); float textlensum = 0; for(int ch=0; ch < message.length(); ch++ ) { char curCh = message.charAt(ch); float chW = textWidth(curCh); textlensum += chW; float x = curvePoint(p0.x, p1.x, p2.x, p3.x, t); float y = curvePoint(p0.y, p1.y, p2.y, p3.y, t); float tx = curveTangent(p0.x, p1.x, p2.x, p3.x, t); float ty = curveTangent(p0.y, p1.y, p2.y, p3.y, t); float a = atan2(ty, tx); //a -= PI/2.0; pushMatrix(); translate(x,y); rotate(a); strokeWeight(1.0); stroke(0); //line(0,0,0,30); //line(0,0, cos(a)*30, sin(a)*30); //line(x,y,tx,ty); //ellipse(tx,ty, 5,5); fill(0,100); text(curCh,0,0); popMatrix(); t += (chW/curvelength); //1.0 / message.length(); } //println("curve length is about: " + curvelength + " and text length is: " + textLength + " calculate len: " + textlensum); } } void mouseClicked() { al.add(new P2(mouseX, mouseY)); println(al.size()); print ("x=" + mouseX + " y=" + mouseY); }