hey Loop! once again you are there for the rescue, thanks a lot!
the thing is, and I might be aware that it should be a lack of knowledge issue on my part, I don’t know the specifics on using arrays, strings, lists and all of those.
/*
enTro
*/
import controlP5.*;
import processing.video.*;
ControlP5 cp5;
Capture cam;
Textfield infosInput; // naming textfield for better calling throughout the code
int state = 0;
int MAXSTATE = 6; // numbers of questions to implement switch/case
String infos;
String infosOutput[];
String infosOutputFilled[];
void setup() {
size (500, 500);
// String[] cameras = Capture.list();
cp5 = new ControlP5(this);
cp5.addTextarea("titulo")
.setPosition(100, 100)
.setSize(400, 40)
.setFont(createFont("arial", 30))
.setLineHeight(14)
.setColor(color(128))
.setColorBackground(color(185, 100))
.setColorForeground(color(255, 100))
.setText("enTro");
cp5.addTextarea("clique")
.setPosition(280, 295)
.setSize(200, 25)
.setFont(createFont("arial", 12))
.setLineHeight(14)
.setColor(color(135))
.setColorBackground(color(198, 100))
.setColorForeground(color(255, 100))
.setText("ENTER para continuar...")
;
infosInput = cp5.addTextfield("") //declared earlier, I name the textfield to aid later calling
.setPosition(120, 100)
.setSize(390, 30)
.setFont(createFont("arial", 30))
.setColor(color(128))
.setColorBackground(color(185, 100))
.setColorForeground(color(255, 100))
;
cp5.addTextarea("nome")
.setPosition(20, 350)
.setSize(320, 40)
.setFont(createFont("arial", 26))
.setLineHeight(14)
.setColor(color(120))
.setColorBackground(color(195, 100))
.setColorForeground(color(249, 100))
.setText("digite seu nome");
/* camera settings
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int i = 0; i < cameras.length; i++) {
println(cameras[i]);
}
// The camera can be initialized directly using an
// element from the array returned by list():
cam = new Capture(this, cameras[0]);
} */
}
void draw() {
background(0);
// if (cam.available() == true) {
// cam.read();
// }
switch (state) {
case 0: //splash screen
cp5.get(Textarea.class, "titulo").setVisible(true);
cp5.get(Textarea.class, "clique").setVisible(false);
cp5.get(Textarea.class, "nome").setVisible(false);
cp5.get(Textfield.class, "").setVisible(false);
break;
case 1: //enter to continue
cp5.get(Textarea.class, "titulo").setVisible(true);
cp5.get(Textarea.class, "clique").setVisible(true);
break;
case 2: //user inputs their name
// cam.start();
cp5.get(Textarea.class, "titulo").setVisible(false);
cp5.get(Textarea.class, "clique").setVisible(false); //hides unused textfields
cp5.get(Textfield.class, "").setVisible(true);
cp5.get(Textfield.class, "").setPosition(120, 100);
cp5.get(Textarea.class, "nome").setVisible(true);
cp5.get(Textarea.class, "nome").setText("digite seu nome");
cp5.get(Textarea.class, "nome").setPosition(20, 350);
// saveFrame();
break;
case 3: //user inputs their age
cp5.get(Textfield.class, "").setPosition(180, 80);
cp5.get(Textarea.class, "nome").setText("digite sua idade"); //changes the question of the box, in order to avoid creating multiple fields
cp5.get(Textarea.class, "nome").setPosition(30, 280); //slightly changes the position for aesthetics
// saveFrame();
break;
case 4: //user inputs their nationality
cp5.get(Textfield.class, "").setPosition(100, 90);
cp5.get(Textarea.class, "nome").setText("digite sua nacionalidade");
cp5.get(Textarea.class, "nome").setPosition(45, 200);
// saveFrame();
break;
case 5: //user inputs their belief
cp5.get(Textfield.class, "").setPosition(180, 140);
cp5.get(Textarea.class, "nome").setText("descreva sua religião");
cp5.get(Textarea.class, "nome").setPosition(250, 120);
// saveFrame();
break;
case 6: //user inputs their skin tone
// cam.stop();
cp5.get(Textfield.class, "").setPosition(230, 80);
cp5.get(Textarea.class, "nome").setText("qual sua descrição fenotípica");
cp5.get(Textarea.class, "nome").setSize(420, 40);
cp5.get(Textarea.class, "nome").setPosition(95, 30);
break;
}
}
void keyPressed() {
for (int j=0; j<=100; j++) {
infosOutput = infosOutput + infosOutput[j];
infosOutputFilled = infosOutputFilled + infosOutputFilled[j];
}
if ( key == ENTER || key == RETURN)
{
/*
this step is reserved for saving the string into a .txt, but it raises the question: is it better to do
after each single keypress or at the very end of the program, when a whole string is formed?
that written, need to research a method for:
- saving textfield into a .txt;
- each answer from the user is stored in the same .txt;
- preferrably in this step I already multiply randomly the answers throughout the strings, in order to generate a treemap afterwards:
http://www.generative-gestaltung.de/2/sketches/?01_P/P_3_1_4_01;
*/
if (state > 1)
{
// even in state 3 we execute the following lines and save afterwards (so please no else if)
infos = infos + "#" + infosInput.getText();
infosInput.setText("");
println("boink: "+infos);
}
if (state == 6)
{
// saving
infos=infos.trim();
if (infos.charAt(0) == '#')
infos=infos.substring(1); // delete leading #
// println("new:"+infos);
String[] infosOutput1 = split(infos, '#');
//expanding string with the information
infosOutput1 = expand(infosOutput1, 100);
//randomizing its contents
for (int j=0; j<100; j++)
{
arrayCopy(infosOutput1, j, infosOutput1, j+4, 100);
}
// reference says: saveStrings(filename, data)
saveStrings(infosOutput1[0] + ".txt", infosOutput1);
// println(infos);
}
if (state==0) {
// reset
infos="";
}
state = (state+1) % (MAXSTATE+1);
println(state);
}
}
I think you remember this; in line 189 I try to expand and then randomize. in this particular case I’m showing, having the array filled with the already present information and then randomized, would you recommend using the hex color code, using String arrays? once again I’m not familiar with some classes, I come from a very basic C background and jumped right to Processing.
if that is the case, I’ll try to replace everything in my code with that, and if you have any readings aside from the reference I’d be thankful to have a look at!
thanks again!