We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I have an issue with Geomerative. I'd like to switch from text to text using this library according to a time schedule. It works but when switching to a shorter text I still see the previous text! How can I switch properly from a text to another?! Thanks a lot in advance for your help. Best, L
import geomerative.*;
// Liste de liste de points. La 1ère correspond au nombre de phrases, ici 4, la 2ème correspond au nom total de points par phrase
RPoint[][] myPoints = new RPoint[4][0];
RFont font;
String [] FR1 = {
"On me dit de te haïr et je m'y efforce",
"Je t'imagine cruel, violent, implacable",
"Mais à te voir je n'ai bientôt plus de force",
"Et de te blesser je suis bien incapable",
};
String [] FR2 = {
"Tous mes camarades combattent avec rage",
"Et pleurent la nuit au souvenir des supplices",
"Infligés à leurs frères qui sont du même âge",
"et rêvent comme eux de toucher une peau lisse"
};
String [] FR3 = {
"Et de pouvoir enfin caresser des obus",
"Autres que ceux produits par le pouvoir obtus",
"Je rêve de quitter ces boyaux infernaux"
};
String [] FR4 = {
"De laisser ces furieux des deux bords du Rhin",
"Et de pouvoir embrasser ta chute de rein",
"Et porter notre amour sur les fonts baptismaux"
};
final color textColor = color(245);
// TIME
int startTime;
//----------------SETUP---------------------------------
void setup() {
size(1920, 1080, JAVA2D);
smooth();
RG.init(this);
font = new RFont("FreeSans.ttf", 86, CENTER);
stroke(textColor);
strokeWeight(0.05);
//INIT
initAll();
changePhrases(0);
changePhrases(1);
changePhrases(2);
changePhrases(3);
// TIME
startTime=millis();
}
//----------------DRAW---------------------------------
void draw() {
background(255);
translate(width/2, height/1.5);
for (int i=0; i< myPoints.length; i++) {
for (int j=0; j< myPoints[i].length-1; j++) {
pushMatrix();
translate(myPoints[i][j].x, myPoints[i][j].y-420+i*180);
noFill();
stroke(0, 200);
strokeWeight(0.25);
float angle = TWO_PI*10;
rotate(j/angle);
bezier(-2*(noise(10)), 10, 25*(noise(10)), -5, 2*noise(5), -15, 10, -3);
//bezier(-10*(noise(20))+mouseX/15, 30+mouseY/10, -10*(noise(10))+mouseX/15, 20+mouseY/15, -20*noise(20)+mouseX/15, -20+mouseY/5, 10+mouseX/15, -10+mouseY/15);
popMatrix();
}
}
if (millis()-startTime > 0 && millis()-startTime < 3000) {
changePhrases(0);
}
if (millis()-startTime > 3000 && millis()-startTime < 6000) {
changePhrases(1);
}
if (millis()-startTime > 6000 && millis()-startTime < 9000) {
changePhrases(2);
}
if (millis()-startTime > 9000 && millis()-startTime < 12000) {
changePhrases(3);
}
}
//----------------INITIALIZE---------------------------------
void initAll() {
for (int j=0; j<FR1.length; j++) {
RGroup myGroup = font.toGroup(FR1[j]);
myGroup = myGroup.toPolygonGroup();
myPoints[j] = myGroup.getPoints();
}
}
//FUNCTION TO SWITCH PHRASES
void changePhrases(int state) {
switch(state) {
case 0:
for (int j=0; j<FR1.length; j++) {
RGroup myGroup = font.toGroup(FR1[j]);
myGroup = myGroup.toPolygonGroup();
myPoints[j] = myGroup.getPoints();
}
break;
case 1:
for (int j=0; j<FR2.length; j++) {
RGroup myGroup = font.toGroup(FR2[j]);
myGroup = myGroup.toPolygonGroup();
myPoints[j] = myGroup.getPoints();
}
break;
case 2:
for (int j=0; j<FR3.length; j++) {
RGroup myGroup = font.toGroup(FR3[j]);
myGroup = myGroup.toPolygonGroup();
myPoints[j] = myGroup.getPoints();
}
break;
case 3:
for (int j=0; j<FR4.length; j++) {
RGroup myGroup = font.toGroup(FR4[j]);
myGroup = myGroup.toPolygonGroup();
myPoints[j] = myGroup.getPoints();
}
break;
}
}
//////////////////////////////////////////////
Answers
Your array
myPoints
is [4][0]. In changePhrases, you loop over it and update each row of myPoints based on the length of FR1, or FR2, et cetera. But FR3 and FR4 are only three lines long, so the fourth row of myPoints is never overwritten.One way to fix this is to add a fourth, blank line to FR3 and FR4. Another way is to replace myPoints completely with e.g.
new RPoint[FR3.length][0]
rather than updating it -- now it will always be the correct length, with no extra lines.There are other things that could be cleaned up which would make your code easier to edit -- keeping an array of string arrays, changing the way that your timers work, making changePhrases accept a String[] array or an index (rather than a switch statement that is manually wired to different parts of a String[][] array).
Look at this cleaned up code for comparison. It is your sketch with minor changes: it uses a set of sets of strings rather than referring to them manually -- this means you can just add more sets of phrases without needing to update the code, and it will just work. Phrases can be any number of lines, 2 lines or 10. There are two functions -- a timer, and a drawing function that renders the phrase strings to RPoints.
Dear Jeremy, thank you so much for your great help. I'm not at home but asap I'll implement the complete code with the part of the code you wrote and will let you know. What if the variable 'duration' is not the same for each loop?! Thanks a lot, L
Dear Jeremy what if I'd like to have a variable changePhraseTimer function?! 3 seconds for the 1rst phrase 1second pause 2 seconds for the 2nd phrase 1 second pause
I tried in many ways, but I can't solve the problem... Thanks a lot in adavance. Best, L
then post one of your ways here
with pleasure, here it is :
It somehow works but not as I wish! Thanks for your answer.
L
Dear Chrisir, In fact my problem is linked to the attarctor in my main sketch. I switch from a phrase to the other and the attractor for the lines works too but no the attractor linked to the words !? Don't find why... I tried to debug, but don't succeed. Here is the code: Thanks for your help... best, L
@jeremydouglass
over to you
Thanks Chrisir! Actually I partly solved the problem, the attractor deform the text now, but the text is returning back immediatly to its initial state!! I certainly initiate the attractor in the wrong place... I hope @jeremydouglas will have some time to help me later on today!
Dear @jeremydouglas if you find some time to help me I'd be very glad! Thanks a lot. Best, L
Dear Chrisir and Jeremy, I still have the same problem in my sketch : the attractor deform the text, but the text is returning back immediatly to its initial state!! I certainly initiate the attractor in the wrong place... I've imlemented other parts of the sketch but now I'm stuck with this error. If you can help me I would really appreciate ! Thanks a lot. L
Please make sure you provide the latest code and some details or where the problem could be in the code. If you point out what section is not working properly, it could save some time to ppl that are trying to help you.
Kf
ok I will do so thanks a lot ;))
Hello @jeremydouglas, Pleasefind below a simple version of my latest code. I have two phraseTimer functions, one works well (phraseTimer()) the others doesn't work properly (phraseTimerALTER()), I don't find why ?! Could you please help me with this issue ? Thanks a lot in adavnce. Best wishes, L
Remember to hit ctrl-t in processing to get better indents automatically
Oups, thanks Chrisir, yes sorry I've corrected the indents and fix a bit the code :
Continued discussion here: https://discourse.processing.org/t/how-to-deform-a-text-generated-with-thegeomerative-library/1147
With pleasure, sorry but between time a friend and I we corrected most of the mistakes, but if I'm stuck today I'll tell you for sure ;)