Dear @Kevin,
Thanks for your reply.
Here is below a smaller example program. I tried to debugg and to narrow down the mistake. Lines 61-62 don’t work like expect. I’d like the WordAttractor to repell the bezier curves of each letterThe error is inside the class :“the constructor is undefined”. Where am I wrong ?
Thank you for your help!
Best,
L
import geomerative.*;
int x, y;
String [] message={"music is like a mountain path"};
color textColor=0;
RFont f;
RShape gShape;
float fontSize=110;
int splitGlyph = 120;
RPoint[][] pointsP;
float r = random(5, 20);
WordAttractor attractorW;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
size(1920, 1080);
RG.init(this);
f = new RFont("FreeSans.ttf", int( fontSize), LEFT);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void draw() {
background(0);
smooth();
pushMatrix();
for (int l=0; l<message.length; l++) {
translate(200, height/2);
pointsP= new RPoint [message[l].length()][splitGlyph];
RShape [] gShape = new RShape [message.length];
//get grouped lettershapes from RFont
gShape [l] = f.toShape(message[l]);
//get the PShape[] containing all the single letters as RShapes. Each letter = children
RShape[]letterShapes = gShape[l].children;
//Number of childrens --> number of letters
int tChildCount = gShape[l].children.length;
//int tChildrenCount = gShape[1].children.length;
for (int k = 0; k < tChildCount; k++) {
RShape tShape = letterShapes[k];
// Calculate distance between mouseX position and the center of each character
float dx= dist(mouseX, 0, gShape[l].children[k].getCenter().x, 0);
//Scale each character according to its distance with mouseX
float sx= map(dx, 0, 100, 3, 1);
float r= map(dx, 0, 100, 0, -TWO_PI);
if (dx<100 && mouseY > height/2-100 && mouseY<height/2+100 && l==0 ) {
gShape[l].children[k].scale(sx, gShape[l].children[k].getCenter());
gShape[l].children[k].rotate(r, gShape[l].children[k].getCenter());
}
for (int j=0; j<splitGlyph; j++) {
float frac=(1.0/splitGlyph);
pointsP[k][j]=gShape[l].children[k].getPoint(j*frac);
RPoint topLeft = tShape.getTopLeft();
RPoint bottomRight = tShape.getBottomRight();
bottomRight.x +=30;
attractorW= new WordAttractor(mouseX, mouseY,pointsP[k][j]);
attractorW.attract();
/*RPoint position = new RPoint(mouseX, -20);
float d=pointsP[k][j].dist(position);
RPoint desired = new RPoint (pointsP[k][j]);
desired.sub(position);
desired.normalize();
desired.scale(map(d, 0, 150, 50, 0));
pointsP[k][j].add(desired);*/
stroke(255);
pushMatrix();
translate( pointsP[k][j].x, pointsP[k][j].y);
beginShape();
noFill();
strokeWeight(1);
float angle = TWO_PI/18;
rotate(j/angle+mouseX/500*noise(pointsP[k][j].x));
bezier(-5*(noise(5)), 5, -10*(noise(2)), 5, -5*noise(10), -5, 5, -5);
endShape();
popMatrix();
}
}
}
popMatrix();
}
class WordAttractor {
float force_radious = 100;
float maxForce = 12;
RPoint position;
RPoint [][] points;
WordAttractor(float x, float y, RPoint [][]p ) {
points = p;
position = new RPoint(x, y);
}
void attract() {
for (int i =0; i<pointsP.length; i++) {
for (int j =0; j<pointsP[i].length; j++) {
float d= points[i][j].dist(position);
if (d < force_radious) {
RPoint desired = new RPoint(points[i][j]);
desired.sub(position);
desired.normalize();
desired.scale(map(d, 0, force_radious, maxForce, 0));
points[i][j].add(desired);
}
}
}
}
}