Hello, in this sketch I declare a font size in my constructor (write) and would like to change it according to the length of the text in my main program. But it seems to be uneffective when I change the size of the fronts of the instances of my class write. Does someone know how to solve thie problem and help me. Thank you very much in advance. Best, laurent
import java.util.*; import ddf.minim.*; import oscP5.*; import netP5.*;
//PORT RESEAU, ADRESSE RESEAU OscP5 oscP5; NetAddress to_isadora;
color textCol= color(245); int Border = 20;
// variable de mode pour les particules int WORDS = 0; //int MOUSE = 1; int MOUSE = 2; //int FLOW = 2; int FLOW = 3; int VORTEX = 3;
int A = 0; int startTime; int duration = 1000;
float noiseScale = 300, noiseStrength = 10;
// comm reseau : variables qui recuperent les valeurs des blobs int NbBlob; int BActif0=0; float BX0; float BY0;
int BActif1=0; float BX1; float BY1;
int BActif2 = 0; float BX2; float BY2;
int BActif3 = 0; float BX3; float BY3;
int BActif4 = 0; float BX4; float BY4;
boolean test=false;
ArrayList phrasesNL, phrasesAR, phrasesEN, currentPhrases;
String [] wordsNL= { "hier\nzeggen ze weer\ndat ik van hier ben\nen dat ben ik ook", "van hier naar ginder\nen ginder ‘hier’ wass\nkwam ik ook daar mezelf niet tegen", "ze zeggen: hier of ginder,\ndat komt toch op hetzelfde neer\ndus waarom ginder neergekomen?", "je komt jezelf niet tegen waar je je niet bevindt\nen ik vind zoeken zonder vinden knap vermoeiend\nhet maakt niet uit of ik mezelf ooit vind", "als jij me maar weer op komt zoeken\njij die niet van hier of ginder\nmaar wel overal thuis bent\nverbindt, vervult mijn hart weer\nof geen weer" };
String [] wordsAR = { "هنا\nقيل لي مِن هناك\nوهناك\nقيل لي مِن هنا", "أنا مِن هنا وهناك على كل حال\nومضيت لأرى إن كنتُ هناك\nلكني ما عثرت على حالي", "قيل لي سيّان هنا أو هناك\nأنتَ أنتَ بحدّ ذاتك\nفلمَ البحث عن نفسي هاهنا؟", "أراني هنا واهنٌ\nمِن كوني هنا دون أن أكون\nوما همَّ لو عثرتُ على حالي\nأو وجدتك واقفًا أمامي", "أنت مَن ليس مِن هنا ولا هناك\nومِن كل مكان على كل حال\nأنت مَن يمسك روابط قلبي\nفي كل حال من الأحوال" }; ///////// String [] wordsEN = { "Here\nHere they told me I am from elsewhere\nelsewhere that I am from here\nI am from anywhere anyway", "I went there to check out if I was away\nbut I haven't find myself\nOne told me : here, there, it's the same", "so why should I look for myself ?\nI'm so tired it's insane\nbeing here without belonging", "Nevermind if I find who I am\nif you're not far from my arms\nyou, not from elsewhere nor from here\nwith you everywhere", "you who lash down my heart, dear\nnevermind the weather" };
People [] visitors = new People [5]; //int visitorsNb; ArrayList vortices; PImage fond; PFont [] fontList; // Sound SoundManager sm;
void setup () { frameRate(25); width =1080; height= 1920; size(1920, 1080, P2D); //fullScreen(); //noCursor(); //OSC //déclaration d'un port pr la réception depuis Isadora oscP5 = new OscP5(this, 12340); //déclarer une adresse pr l'envoi des messages : adresse IP + n° de port to_isadora = new NetAddress("127.0.0.1", 12000);
fond = loadImage("ICI_FOND.png");
// SOUND sm = new SoundManager(this);
// VORTICES (Case 3 : VORTEX) vortices = new ArrayList(); for (int j = 0; j < 20; j++) { vortices.add(new Vortex()); }
// HERE I TRY TO CHANGE THE SIZE OFTHE FONTS!!
// FONT LIST PFont fontNL = createFont ("Tubqal-Medium.ttf", 45); PFont fontAR = createFont ("Tubqal-Medium.ttf", 100); PFont fontEN = createFont ("DINBDA.TTF", 80);
// NEERLANDAIS phrasesNL = new ArrayList (); PVector offset = new PVector(Border/2, 220); Write v = new Write (wordsNL[0], offset, fontNL, sm); offset.add(0, (v.getNumLines())100); phrasesNL.add(v); for (int i=1; i< wordsNL.length; i++) { Write w = new Write (wordsNL[i], offset, fontNL, sm); offset.add(0, (w.getNumLines())115); phrasesNL.add(w); } //println ("phrasesFR completed:"); //println ("nbre de phrasesFR:"+ phrasesNL.size()); //println ("phrasesFR0:"+ phrasesFR.get(0).words); //println();
// ARAB phrasesAR = new ArrayList (); offset = new PVector(Border, 300); for (int i=0; i< wordsAR.length; i++) {
Write w = new Write (wordsAR[i], offset, fontAR, sm);
offset.add(0, (w.getNumLines())*100);
phrasesAR.add(w);
} // ENGLISH phrasesEN = new ArrayList (); offset = new PVector(Border, 320); Write e= new Write(wordsEN[0], offset, fontEN, sm); offset.add(0, (e.getNumLines())*100); phrasesEN.add(e);
for (int i=1; i< wordsEN.length-2; i++) { Write w = new Write (wordsEN[i], offset, fontEN, sm); offset.add(0, (w.getNumLines())120); phrasesEN.add(w); } for (int j=3; j< wordsEN.length; j++) { Write en= new Write(wordsEN [j], offset, fontEN, sm); offset.add(0, (en.getNumLines())100); phrasesEN.add(en); }
//currentPhrases = phrasesFR;*/
// VISITORS (VIRTUAL VISITORS TO CHECK INTERACTIVITY) for (int i = 0; i<visitors.length; i++) { visitors[i] = new People(random(0, width), random(0, height)); } startTime = millis(); }
void draw() {
checkLanguageTime(); translate(0, 1080); rotate(-HALF_PI); fill (0, 200); rect(0, 0, width, height);
// affichage des repères //image (fond, Border, Border-10);
if (visitors.length>0) { // si le blob 0 est inactif, on met le personnage 0 hors champs. Sinon on passe la valeur de sa position if (BActif0==0) { visitors[0].location.x=-10; visitors[0].location.y=-10; } else { visitors[0].location.x=BX0; visitors[0].location.y=BY0; }
// si le blob 1 est inactif, on met le personnage 1 hors champs. Sinon on passe la valeur de sa position
if (BActif1==0) {
visitors[1].location.x=-10;
visitors[1].location.y=-10;
} else {
visitors[1].location.x=BX1;
visitors[1].location.y=BY1;
}
// si le blob 2 est inactif, on met le personnage 2 hors champs. Sinon on passe la valeur de sa position
if (BActif2==0) {
visitors[2].location.x=-10;
visitors[2].location.y=-10;
} else {
visitors[2].location.x=BX2;
visitors[2].location.y=BY2;
}
// si le blob 3 est inactif, on met le personnage 3 hors champs. Sinon on passe la valeur de sa position
if (BActif3==0) {
visitors[3].location.x=-10;
visitors[3].location.y=-10;
} else {
visitors[3].location.x=BX3;
visitors[3].location.y=BY3;
}
// si le blob 4 est inactif, on met le personnage 4 hors champs. Sinon on passe la valeur de sa position
if (BActif4==0) {
visitors[4].location.x=-10;
visitors[4].location.y=-10;
} else {
visitors[4].location.x=BX4;
visitors[4].location.y=BY4;
}
}
if (visitors.length > 0) {
// on force la mise à jour du mode à défaut
for (int i=0; i< visitors.length; i++) {
currentPhrases.get(i).reset();
}
// en fonction des visiteurs présent on détermine le mode
for (int i=0; i< visitors.length; i++) {
if (visitors[i].location.y > Border && visitors[i].location.y < height-Border) {
for (int j=0; j< currentPhrases.size(); j++) {
if (visitors[i].location.y < Border+384) {
currentPhrases.get(0).setVisitorPos(visitors[i].location);
}
if (visitors[i].location.y >=384 && visitors[i].location.y < Border+768) {
currentPhrases.get(1).setVisitorPos(visitors[i].location);
}
if (visitors[i].location.y >=768 && visitors[i].location.y < Border+1152) {
currentPhrases.get(2).setVisitorPos(visitors[i].location);
}
if (visitors[i].location.y >=1152 && visitors[i].location.y < Border+1536) {
currentPhrases.get(3).setVisitorPos(visitors[i].location);
}
if (visitors[i].location.y >=1536 && visitors[i].location.y < 1920 - Border) {
currentPhrases.get(4).setVisitorPos(visitors[i].location);
}
}
} else {
// NO VISITORS AROUND
//for (int i=0; i< currentPhrases.size(); i++) {
//currentPhrases.get(i).mode=VORTEX;
}
}
// println("taille de currentPhrases : "+currentPhrases.size());
// DEBUG affichage des modes courants pour chaque zone de texte
for (int j=0; j< currentPhrases.size(); j++) {
// println("affichage du mode courant : "+ currentPhrases.get(j).mode);
}
// affichage des zones de texte (classe Write)
for (int j =0; j< currentPhrases.size(); j++) {
currentPhrases.get(j).display();
}
} fade();
// UPDATE SOUND sm.update();
//println("============fin de draw=============="); //println(); }
void fade() { // gestion des fades au changement de langue int dur = millis()- startTime;
if ( dur >=-10 && dur < 2000) { fill(0, map(dur, 0, 0+duration, 255, 0)); noStroke(); rect(0, 0, 1080, 1920); } if ( dur > 5800 && dur < 6000) { fill(0, map(dur, 5800, 5800+duration, 0, 255)); noStroke(); rect(0, 0, 1080, 1920); } if ( dur > 6000 && dur < 6100) { noStroke (); fill(0, 255); rect (0, 0, 1080, 1920); } if ( dur > 6100 && dur < 6300) { fill(0, map(dur, 6100, 6100+duration, 255, 0)); noStroke(); rect(0, 0, 1080, 1920); } if ( dur > 18100 && dur < 18300) { fill(0, map(dur, 12100, 12100+duration, 0, 255)); noStroke(); rect(0, 0, 1080, 1920); } if ( dur > 18300 && dur < 18400) { noStroke (); fill(0, 255); rect (0, 0, 1080, 1920); } if ( dur > 18400 && dur < 18600) { fill(0, map(dur, 12400, 12400+duration, 255, 0)); noStroke(); rect(0, 0, 1080, 1920); } if ( dur > 24600 && dur < 24700) { fill(0, map(dur, 24600, 24700+duration, 0, 255)); noStroke(); rect(0, 0, 1080, 1920); } if ( dur > 24700 && dur < 24800) { noStroke (); fill(0, 255); rect (0, 0, 1080, 1920); } if ( dur > 24800 && dur < 24900) { fill(0, map(dur, 24800, 24900+duration, 255, 0)); noStroke(); rect(0, 0, 1080, 1920); } if ( dur > 24900) { startTime = millis(); } }
void checkLanguageTime() {
//currentPhrases = phrasesFR;
int dur = millis()- startTime;
if (dur < 6000) { currentPhrases = phrasesEN; } else if (dur < 18300) { currentPhrases = phrasesNL; } else if (dur < 24600) { currentPhrases = phrasesAR; } else { currentPhrases = phrasesNL; startTime = millis(); } //*/ }
// MESSAGE OSC (en-tête + valeur) OscMessage myMessage = new OscMessage ("/isadora/1"); // Envoi du message //oscP5.send(myMessage, to_isadora);
// reception des messages void oscEvent(OscMessage theOscMessage) { /* check if theOscMessage has the address pattern we are looking for. */
if (theOscMessage.checkAddrPattern("/isadora/1")==true) { /* check if the typetag is the right one. / if (theOscMessage.checkTypetag("iiffiffiffiffiff")) { / parse theOscMessage and extract the values from the osc message arguments. */ NbBlob = theOscMessage.get(0).intValue();
BActif0 = theOscMessage.get(1).intValue();
BX0 = theOscMessage.get(2).floatValue()*10.8;
BY0 = theOscMessage.get(3).floatValue()*19.2;
BActif1 = theOscMessage.get(4).intValue();
BX1 = theOscMessage.get(5).floatValue()*10.8;
BY1 = theOscMessage.get(6).floatValue()*19.2;
BActif2 = theOscMessage.get(7).intValue();
BX2 = theOscMessage.get(8).floatValue()*10.8;
BY2 = theOscMessage.get(9).floatValue()*19.2;
BActif3 = theOscMessage.get(10).intValue();
BX3 = theOscMessage.get(11).floatValue()*10.8;
BY3 = theOscMessage.get(12).floatValue()*19.2;
BActif4 = theOscMessage.get(13).intValue();
BX4 = theOscMessage.get(14).floatValue()*10.8;
BY4 = theOscMessage.get(15).floatValue()*19.2;
}
//println("### received an osc message. with address pattern "+theOscMessage.addrPattern());
//println("### received an osc message. with type tag "+theOscMessage.typetag());
} }
// DEBUG sans le logiciel de tracking void keyPressed() { if (BActif0==1) { BActif0=0; BX0=-10; BY0=-10; } else { BActif0=1; BX0=mouseY; BY0=mouseX; } }
////////////////////////////////////////////////////////////////////////////////////////
import ddf.minim.*;
class Write {
int particlesPerLetter = 60; Particle [] particles; PFont [] fontList; PFont f; int mode; PVector visitorPos; String words; SoundManager sm; // HERE I DECLARE THE SIZE OF THE FONT float PFontSize=45;
Write( String _words, PVector origin, PFont _f, SoundManager _sm) { words = _words; println("words:"+words); mode = VORTEX; sm = _sm;
visitorPos = new PVector();
f= _f;
PGraphics pg;
int nbParticle = particlesPerLetter * words.length();
particles = new Particle[nbParticle];
pg = createGraphics(width, height);
pg.beginDraw();
pg.fill(textCol);
pg.textAlign(CENTER);
pg.textFont(f, PFontSize);
pg.text(words, origin.x, origin.y, width-Border, height-Border);
pg.endDraw();
pg.loadPixels();
for (int i =0; i <particles.length; i++) {
particles[i] = new Particle(pg);
}
}
int getNumLines() { int n = 0; int lastIndex =0; while (lastIndex > -1) { lastIndex = words.indexOf("\n", lastIndex+1); if (lastIndex >-1) { n++; } } return n; }
void display() { for (int i=0; i< particles.length; i++) { particles[i].update(mode, visitorPos); particles[i].edges(); } //soundSelect(); }
void reset() { mode = FLOW; }
void setVisitorPos(PVector pos) { visitorPos = pos.get(); //if ( visitorsNb > 0) { /* for (int i=0; i< visitors.length; i++) { if (visitorPos.x>Border && visitorPos.x < 350) { mode = MOUSE; sm.playSound(0); } else if (visitorPos.x < 750) { mode = WORDS; sm.playSound(1); } else if ( mouseX < width-Border) { mode = FLOW; sm.playSound(2); } else { mode = VORTEX; sm.playSound(3);
// définir zone sans personne le son doit être lu globalement
}
*/
sm.playSound(3);
for (int i=0; i< visitors.length; i++) {
if (visitorPos.x>Border && visitorPos.x < 350) {
mode = WORDS; // protection si un précédent visiteur a activé le mode WORDS pour ne pas "retrograder" en MOUSE
sm.playSound(0);
}
}
for (int i=0; i< visitors.length; i++) {
if (visitorPos.x < width-Border && visitorPos.x >= 750) {
mode = WORDS; // protection si un précédent visiteur a activé le mode WORDS
sm.playSound(2);
}
}
for (int i=0; i< visitors.length; i++) {
if (visitorPos.x>= 350 && visitorPos.x < 750) {
if (mode != WORDS) mode = MOUSE;
sm.playSound(1);
}
}
// définir zone sans personne le son doit être lu globalement
} }