Hi dnganeko,
I suspect that creating your background with HTML and CSS, or with an SVG editor, would be an easier way to do it… Even p5.js may be preferable to Java-based Processing.
There’s more than one way to create a curve and then calculate a point on that curve from a percentage (a step
value in the range 0.0
to 1.0
). For Bezier curves, two functions in the Processing API that you may find helpful are bezierPoint (in p5.js) and bezierTangent (in p5.js); for Catmull-Rom curves, curvePoint (in p5.js) and curveTangent (in p5.js).
String message = "Lorem ipsum dolor sit amet,"
+ "consectetur adipiscing elit.";
char[] messageAsChars = message.toCharArray();
int charCount = messageAsChars.length;
float charCountToStep = 1.0 / float(charCount);
float ap0x, ap0y,
cp0x, cp0y,
cp1x, cp1y,
ap1x, ap1y;
void setup() {
size(1024, 512);
smooth(8);
randomizePoints();
textSize(32);
textAlign(CENTER, CENTER);
textMode(MODEL);
}
void draw() {
background(255);
noFill();
stroke(0xff007fff);
bezier(ap0x, ap0y,
cp0x, cp0y,
cp1x, cp1y,
ap1x, ap1y);
noStroke();
fill(0xff000000);
float step0 = frameCount * 0.01;
for (int i = 0; i < charCount; ++i) {
float step1 = i * charCountToStep;
float step2 = (step0 + step1) % 1.0;
float x = bezierPoint(ap0x, cp0x, cp1x, ap1x, step2);
float y = bezierPoint(ap0y, cp0y, cp1y, ap1y, step2);
float tanx = bezierTangent(ap0x, cp0x, cp1x, ap1x, step2);
float tany = bezierTangent(ap0y, cp0y, cp1y, ap1y, step2);
float angle = atan2(tany, tanx);
pushMatrix();
translate(x, y);
rotate(angle);
text(messageAsChars[i], 0.0, 0.0);
popMatrix();
}
}
void mouseReleased() {
randomizePoints();
}
void randomizePoints() {
float halfw = width * 0.5;
float halfh = height * 0.5;
ap0x = random(0.0, halfw);
cp0x = random(0.0, width);
cp1x = random(0.0, width);
ap1x = random(halfw, width);
ap0y = random(0.0, halfh);
cp0y = random(0.0, height);
cp1y = random(0.0, height);
ap1y = random(halfh, height);
}
From bezierTangent
or curveTangent
, you can use atan2 (in p5.js) to find the angle of rotation for a point along the curve. This is simply one curve, not multiple curves connected together, where the last anchor point of the first curve is the first anchor point of the next. Even though the step
s provided to bezierPoint
are evenly distributed, the resulting points can crowd along the curve.
There are resources here and there which may help with the maths once you know the key words to search for. I’ve found the following helpful: