how do i convert my external txt data (string) to numbers? [new to processing]
in
Programming Questions
•
6 months ago
hi! i am totally new to processing, and this is the first project i'm doing
so... im trying to get data from a txt file, and the txt file contains all words (voting results)
something like:
"Name: Amey"
"Voted For: Stephen Harper"
"Voted For: Stephen Harper"
"Name: Usman"
"Voted For: Thomas Mulcair"
"Voted For: Thomas Mulcair"
these results display fine underneath my code (by using println)
but i'm having trouble trying to record how many votes each person has, and convert it to a number percentage and display it on a pie chart.
Anyone help?!
Here is the code I have now:
PFont my_font;
String result;
String result;
float diameter;
int[] angles = { 144, 36, 36, 72, 72};
color[] MyOwnColor = {
color(133, 130, 149), color(237, 213, 117), color(240, 174, 232), color(183, 245, 222),
color(75, 219, 167), color(255, 250, 106), color(240, 92, 114),
color(157, 144, 250), color(144, 215, 250)
} ;
int[] angles = { 144, 36, 36, 72, 72};
color[] MyOwnColor = {
color(133, 130, 149), color(237, 213, 117), color(240, 174, 232), color(183, 245, 222),
color(75, 219, 167), color(255, 250, 106), color(240, 92, 114),
color(157, 144, 250), color(144, 215, 250)
} ;
float lastAngle = 0.0;
void setup () {
size (1000,700);
background(215);
smooth();
//ellipse(300, 360, 500, 500);
my_font=loadFont("TimesNewRomanPSMT-48.vlw");
textAlign(LEFT);
noLoop ();
diameter = min(width, height) * 0.75;
size (1000,700);
background(215);
smooth();
//ellipse(300, 360, 500, 500);
my_font=loadFont("TimesNewRomanPSMT-48.vlw");
textAlign(LEFT);
noLoop ();
diameter = min(width, height) * 0.75;
stroke (0);
fill (255);
rect (650,90,280,350);
fill (255);
rect (650,90,280,350);
}
void draw ()
{
textFont (my_font,26);
fill (0,0,0,200); //last num means transparency
text("Results for Federal Elections", width/6, height/11);
textFont (my_font,15);
fill (0,0,0,150);
text("© 2013 TTT",872,690);
{
textFont (my_font,26);
fill (0,0,0,200); //last num means transparency
text("Results for Federal Elections", width/6, height/11);
textFont (my_font,15);
fill (0,0,0,150);
text("© 2013 TTT",872,690);
for (int i = 0; i < angles.length; i++) {
//fill(angles[i] * 3.0);
fill (MyOwnColor [i]);
arc(300, 360, diameter, diameter, lastAngle, lastAngle+radians(angles[i]));
lastAngle += radians(angles[i]);
}
//fill(angles[i] * 3.0);
fill (MyOwnColor [i]);
arc(300, 360, diameter, diameter, lastAngle, lastAngle+radians(angles[i]));
lastAngle += radians(angles[i]);
}
String[] vs_results = loadStrings("FederalResults.txt");
println("there are " + vs_results.length + " lines");
for (int i=0; i < vs_results.length; i++) {
println(vs_results[i]);
println("there are " + vs_results.length + " lines");
for (int i=0; i < vs_results.length; i++) {
println(vs_results[i]);
}
}
}
1