Dear all,
I face an issue I can’t solve for days despite the great help I received in this forum from @kll who helped me a lot. Unfortunately we didn’t find a way out. In the code below I deform+enlarge a text letter by letter according to mouse position. I find a way to keep each letter at different sizes but not the deformation. Once the mouse is more than 100px away from the letter, the text takes back its original form! How to keep it deformed?! I hope someone can help. Thanks a lot in advance.
L
import geomerative.*;
import ddf.minim.analysis.*;
import ddf.minim.*;
String soundNameFR = "FR_01";
Minim minim;
AudioPlayer soundsFR;
FFT fftFR;
float bandHeightFR;
int x, y;
String [] message={"music is like a mountain path"};
color textColor=0;
RFont f;
RShape [] gShape = new RShape[message.length];
float fontSize=110;
int splitGlyph = 120;
RPoint[][] pointsP;
float r = random(5, 20);
WordAttractor attractorW;
int tChildCount;
characterSpec characters;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
size(1920, 1080);
RG.init(this);
f = new RFont("SFNSText.ttf", int( fontSize), LEFT);
minim=new Minim(this);
soundsFR=minim.loadFile("FR_01.wav", 512);
soundsFR.play();
fftFR= new FFT(soundsFR.bufferSize(), soundsFR.sampleRate());
for (int l =0; l<message.length; l++) {
characters = new characterSpec( gShape[l], message[l]);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void draw() {
background(0);
smooth();
soundFFTAnalyse();
//pushMatrix();
translate(200, height/2);
for (int l =0; l<message.length; l++) {
characters.update();
characters.display();
}
// popMatrix();
}
void soundFFTAnalyse() {
AudioPlayer fr = soundsFR;
fftFR.forward(fr.mix);
for (int i=0; i<fftFR.specSize(); i++) {
float bandDBFR = 10*log(fftFR.getBand(i)/fftFR.timeSize());
bandHeightFR = map(bandDBFR*4, 0, -220, 0, height);
constrain(bandHeightFR, 0, 1000);
noStroke();
fill(255, 0, 0);
ellipse(fr.position()/10, bandHeightFR/20, 5, 5);
}
}
class characterSpec {
RShape bShape;
String m;
RShape letterShapes;
float maxForce=2;
float radiousForce=100;
characterSpec(RShape _letterShapes, String _m) {
letterShapes=_letterShapes;
m = _m;
pointsP= new RPoint [m.length()][splitGlyph];
bShape = new RShape();
bShape = f.toShape(m);
RShape [] letterShapes = bShape.children;
letterShapes = bShape.children;
tChildCount = bShape.children.length;
}
void update() {
for (int k = 0; k < tChildCount; k++) {
//float posX=map(soundsFR.position(), 200, soundsFR.length(), 200, width-200);
//float posY=bandHeightFR/4;
float posX = mouseX;
float posY = mouseY;
float d= dist(posX, 0, bShape.children[k].getCenter().x, 0);
float sx= map(d, 0, 100, 1, 1.01);
//sx=abs(sx);
//float r= map(d, 0, 100, 0, -TWO_PI);
if (d<100) {
bShape.children[k].scale(sx, bShape.children[k].getCenter());
//bShape.children[k].rotate(r, bShape.children[k].getCenter());
}
for (int j=0; j<splitGlyph; j++) {
float frac=(1.0/splitGlyph);
pointsP[k][j]=bShape.children[k].getPoint(j*frac);
attractorW= new WordAttractor(posX-200, posY-500, pointsP[k][j]);
attractorW.attract();
}
}
}
void display() {
for (int k = 0; k < tChildCount; k++) {
for (int j=0; j<splitGlyph; j++) {
pushMatrix();
translate(pointsP[k][j].x, pointsP[k][j].y);
stroke(255);
beginShape();
noFill();
strokeWeight(0.2);
float angle = TWO_PI/18;
rotate(angle*j/4+noise(pointsP[k][j].x)/20);
bezier(-5*(noise(5)), 5, -10*(noise(2)), 5, -5*noise(10), -5, 5, -5);
endShape();
popMatrix();
}
}
}
}
class WordAttractor {
float force_radious = 100;
float maxForce = 50;
RPoint position;
RPoint points;
float pX;
float pY;
WordAttractor(float x, float y, RPoint p) {
points =p;
position = new RPoint(x, y);
}
void attract() {
float d= points.dist(position);
if (d < force_radious) {
RPoint desired = new RPoint(points);
desired.sub(position);
desired.normalize();
desired.scale(map(d, 0, force_radious, maxForce, 0));
points.add(desired);
}
}
}