sliders & text
in
Contributed Library Questions
•
2 years ago
Hi!
For my first project with processing, I try to modify some text using sliders. I'd like that on key pressed the sliders affects just one part of the text but I have no idea how to do that. It's probably really simple but I'm quite new with processing. Has anyone an idea? Thanks!
code:
String textTyped = "J'ai faim_j'ai envie_d'aller_au_macdo!!!";
String [] Sentence = splitTokens(textTyped, "_");
splitLetters[] words = new splitLetters [Sentence.length];
import geomerative.*;
import controlP5.*;
ControlP5 controlP5;
ControlWindow controlWindow;
public float MYGAP = 4.5;
public int MYTHICKNESS = 2;
public int MYRANDOM = 0;
public float MY_VAL = 0;
RFont font;
void setup() {
size(1324, 1350, P3D);
controlP5 = new ControlP5(this);
controlP5.setAutoDraw(false);
controlWindow = controlP5.addControlWindow("externalWindow", 0, 0, 200, 200);
controlWindow.hideCoordinates();
controlWindow.setBackground(color(40));
Controller mySlider1 = controlP5.addSlider("MYGAP", -10, 0, MYGAP, 20, 20, 100, 10);
mySlider1.setWindow(controlWindow);
Controller mySlider2 = controlP5.addSlider("MYTHICKNESS", 0, 50, MYTHICKNESS, 20, 40, 100, 10);
mySlider2.setWindow(controlWindow);
Controller mySlider4 = controlP5.addSlider("MYRANDOM", 0, 20, MYRANDOM, 20, 60, 100, 10);
mySlider4.setWindow(controlWindow);
Controller mySlider6 = controlP5.addSlider("MY_VAL", -1, 1, MY_VAL, 20, 100, 100, 10);
mySlider6.setWindow(controlWindow);
controlWindow.setTitle("x4 Sliders");
// smooth();
RG.init(this);
font = new RFont("FreeSans.ttf", 60, RFont.LEFT);
RCommand.setSegmentLength (1);
RCommand.setSegmentator(RCommand.UNIFORMLENGTH);
background(0);
stroke(255);
noFill();
for (int k = 0; k < Sentence.length; k++) {
words[k] = new splitLetters(Sentence[k]);
}
}
void draw() {
background(0);
for (int k = 0; k < Sentence.length; k++) {
words[k].mySplit(k);
}
if (key == '1') {
words[0].transX = mouseY;
}
if (key == '2') {
words[1].transX = mouseY;
}
if (key == '3') {
words[2].transX = mouseY;
}
if (key == '4') {
words[3].transX = mouseY;
}
if (key == '5') {
words[4].transX = mouseY;
}
}
class splitLetters {
String mySentence;
float transX = 30;
splitLetters (String _mySentence) {
mySentence = _mySentence;
}
void mySplit (int textDist) {
if (mySentence.length() > 0) {
RGroup grp;
grp = font.toGroup(mySentence);
grp = grp.toPolygonGroup();
RPoint[] pnts = grp.getPoints();
pushMatrix();
translate(transX, 0 + -600 + (100 * textDist)); // calculate Sentence.length to fontsize
for (int j = 0; j < pnts.length; j++ ) {
float diameter = (MYRANDOM);
if (j%2 == 0) {
ellipse(pnts[j].x+100+MYGAP*20+(j*+(MY_VAL/2)), pnts[j].y+700, MYRANDOM, diameter );
strokeWeight(MYTHICKNESS);
}
}
popMatrix();
}
}
}
1