【text_to_path】two lines cannot reveal along the path

hi guys, i stuck in the situation that the tow text-line cannot reveal along the path. Following is the code …

import tracer.*;
import tracer.paths.*;

//style
int fgColor = #FFFFFF; //foreground color
int bgColor = #DC443A; //background color

//text
String text = "Experiment A...Experiment B...Experiment C ";
float startu; //1D position where text starts
float dstartu = 0.00005; //1D text speed per millisecondimport tracer.*;
import tracer.paths.*;

//path
//Lissajous path;

CubicBezier bezier1;
CubicBezier bezier2;
CubicBezier bezier3;
CubicBezier bezier4;
Composite path1;
Composite path2;
Composite path3;


float dphi = 0.0005; //change in phi per millisecond

int d;
int k;

//time
int prevt; //the previous time in milliseconds


void setup(){
 size(360, 360, P2D);
 
 bezier1 = new CubicBezier (100, 0, 360, 0, 100, 200, 460, 200);
 bezier2 = new CubicBezier (0, 100, 360, 100, 0, 300, 360, 300);
 bezier3 = new CubicBezier (-100, 200, 260, 200, -100, 200, 260, 200);
 bezier4 = new CubicBezier (-200, 300, 160, 300, -200, 300, 160, 300);
 path1 = new Composite (bezier1, bezier2);
 path2 = new Composite (bezier3, bezier4);
 path3 = new Composite (path1, path2);
 
 prevt = millis();
}

void draw() {
 int dt = millis() - prevt;
 prevt = millis();
 startu += dstartu * dt; 

 background(bgColor);
 noStroke();
 fill(fgColor);
 textSize(22);

 for (int k=0; k<1; k++){  
   String stringk = text;
   embedText(path3, stringk);
 }
}

 void embedText (Path path3, String stringk) {
 Point a = new Point(0, 0);
 Point b = new Point(0, 0);

 float textWidthAcc = 0; 
 float textWidthTotal = textWidth(text); 
 
 for  (int i=0; i<stringk.length(); i++) {
 char c = stringk.charAt(i);
       textWidthAcc += 0.5 * textWidth(c);
       float u = (startu + map(textWidthAcc, 0, textWidthTotal, 0, 1 )) % 1;
       path3.trace(a, u);
       path3.trace(b, (u + 0.000001) % 1.0);

   float angleOfRotation = atan2(b.y - a.y, b.x - a.x);
   drawChar(stringk.charAt(i), a.x, b.y, angleOfRotation);
   textWidthAcc += 0.5 * textWidth(c);

   println(a);
 }    
}

void drawChar(char c, float x, float y, float angle) {
 textAlign(CENTER, CENTER);
 pushMatrix();
 translate(x, y);
 rotate(angle);
 text(c, 0, 0);
 popMatrix();
}

it ends up becoming …

I am so curious why the two lines below cannot reveal along the path … looking forward to your reply!

Shang

1 Like

@shang – sorry about missing this question. were you able to resolve your problem?

The problem has been solved, thank you :slight_smile:

1 Like