Read Strings from data.txt into array
in
Programming Questions
•
3 years ago
Hey, i'm absolutely a beginner...
who can tell me how to read out the values from the data.txt (
n,car,#FF0000
c,blue,#0000FF
c,green,#0000FF
i,yellow,#00FF00
c,blue,#0000FF
c,green,#0000FF
i,yellow,#00FF00
)as strings and put each line from the .txt into a seperate array?
Another problem for me will be how to convert the hexcode which is then treated as string to a color.
THX alot to everbody helping me!
(later i want to replace Car and Blue in the line: "stimulus Car = new stimulus ("Car" ,Blue );" with the data from the txt file ...)
stimulus[] stimuli;
void setup() {
size (1024,768);
smooth();
// Load text file as an array of String
String[] data = loadStrings("data.txt");
stimuli = new stimulus[data.length];
//each line from the data is converted into and array
for (int i = 0; i < stimuli.length; i++){
String[] values = String(split(data[i],","));
stimuli[i] = new stimulus(values[0],values[1],values[2]);
}
}
void draw(){
background(0);
stimulus Car = new stimulus ("Car" ,Blue );
Car.display();
}
// Define Class Stimulus
class stimulus {
String condition;
String word;
color kleur;
// Construct Stimulus
stimulus(String C, String W, color K) {
this.condition = n;
this.word = mouse;
this.kleur = #FF0000;
}
// Method to display Stimulus
void display() {
textAlign(CENTER, CENTER);
textSize(45);
fill(kleur);
text(word, horizPos, vertiPos);
}
}
void setup() {
size (1024,768);
smooth();
// Load text file as an array of String
String[] data = loadStrings("data.txt");
stimuli = new stimulus[data.length];
//each line from the data is converted into and array
for (int i = 0; i < stimuli.length; i++){
String[] values = String(split(data[i],","));
stimuli[i] = new stimulus(values[0],values[1],values[2]);
}
}
void draw(){
background(0);
stimulus Car = new stimulus ("Car" ,Blue );
Car.display();
}
// Define Class Stimulus
class stimulus {
String condition;
String word;
color kleur;
// Construct Stimulus
stimulus(String C, String W, color K) {
this.condition = n;
this.word = mouse;
this.kleur = #FF0000;
}
// Method to display Stimulus
void display() {
textAlign(CENTER, CENTER);
textSize(45);
fill(kleur);
text(word, horizPos, vertiPos);
}
}
1
