Hello,
I am using the Geomerative library to draw some text. I manage to split it into chars and then set their size
according to their distance with mouseX, but the space between char is acting strangely. I’d like it to be the same and the text in the same order… Now the space is very large and the letters one on the other!!
Can someone help me to solve this problem please?
Thanks a lot in advance.
best,
L
import processing.pdf.*;
import geomerative.*;
int x, y;
String message="music is like a mountain path";
float [] fontSizes= new float[message.length()];
color textColor=0;
RFont f;
RShape gShape;
RPoint[][] points;
float fontSize=50;
int splitGlyph = 100;
void setup() {
size(1920, 1000);
RG.init(this);
for (int i=0; i<message.length(); i++) {
fontSizes[i]= fontSize;
}
points=new RPoint [message.length()][splitGlyph];
}
void draw() {
background(255);
smooth();
translate(100, 500);
for (int i=0; i<message.length(); i++) {
fontSizes[i]=fontSize;
f = new RFont("FreeSans.ttf", int(fontSize), LEFT);
}
//get grouped lettershapes from RFont
RShape gShape = f.toShape(message);
//get the PShape[] containing all the single letters as RShapes. Each letter = children
RShape[] letterShapes = gShape.children;
//Number of childrens --> number of letters
int tChildCount = letterShapes.length;
for (int i = 0; i < tChildCount; i++) {
RShape tShape = letterShapes[i];
// Calculate distance between mouseX position and the center of each character
float d= dist(mouseX, 0, letterShapes[i].getCenter().x, 0);
println(d);
//Scale each character according to its distance with mouseX
if (d<200) {
float s= map(d, 0, 200, 2, 1);
letterShapes[i].scale(s);
}
for (int j=0; j<splitGlyph; j++) {
float frac=(1.0/splitGlyph);
points[i][j]=letterShapes[i].getPoint(j*frac);
//get the corner-points of the bounding box
RPoint topLeft = tShape.getTopLeft();
RPoint bottomRight = tShape.getBottomRight();
// drawing letters outlines
//tShape.draw();
//draw bounding box using the two cornerpoints
stroke(0);
noFill();
rect(topLeft.x, topLeft.y, bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
fill(255);
//Draw points along the letters shapes
pushStyle();
stroke(0, 200);
strokeWeight(2);
point( points[i][j].x, points[i][j].y);
popStyle();
}
}
}