Beginner needs some help (code provided)
in
Programming Questions
•
1 year ago
I'm new to Processing and via experimentation and reading tutorials / posts, I've figured out how to do the following:
- import data from a .txt file
- arrange and display the data in 5 columns, 14 rows
- create a grid of gray boxes behind the text (same 5x14 arrangement)
What I'd really like to do next is use the gray boxes a bit more intelligently. I'd like to:
- Define a variable at the beginning of the program that identifies a single team - say Boston (shown as BOS)
- For each column, only draw the gray box for the player that plays for BOS and all the players below him in the column
The goal is to show how Boston pitchers rank compared to the rest of the league, with each column representing a quartile of pitchers. So each column would show (via the height of the gray boxes) how well ranked each Boston pitcher is). Sort of like a graphic equalizer. I tried to create some logic within the loop to do this, but got nowhere (a bit too advanced for me and I spun my wheels for a long time).
Can someone look at my code and help me figure out how to do this? Thanks a ton! Kevin
CODE BELOW:
// misc setup
void setup() {
size(1280,800);
PFont font;
font = loadFont("CenturyGothic-20.vlw");
textFont(font);
}
// color settings
// background color
int r1=240;int g1=235;int b1=235;
// highlighted color
int r2=165;int g2=165;int b2=165;
//text color
int r3=250;int g3=250;int b3=250;
void draw() {
background (r1,g1,b1); //gray
// parsing data from external file (column [0] is list of names, column [1] is ranks, column [2] is abbreviated team name)
String lines[] = loadStrings("rankometerdata.txt");
//loop formula for text
for(int k=0; k<5; k++){ // master loop to format 5 columns of names
for(int j=k*14; j<k*14+14; j++){ //sub loop to format 14 rows of names within each column
int z=j-k*14; // special variable I use to index down and across rows and columns
String[] name = splitTokens(lines[j+1]);
//highlighting each name across 5 columns and 14 rows
fill(r2,g2,b2);
rect(k*220+45,310+z*30,180,25);
// overlaying text
noStroke();
textSize(20);
fill(r3,g3,b3); //text color
text(name[0]+" ["+name[2]+"]",k*220+55,330+z*30);
}
}
}
- import data from a .txt file
- arrange and display the data in 5 columns, 14 rows
- create a grid of gray boxes behind the text (same 5x14 arrangement)
What I'd really like to do next is use the gray boxes a bit more intelligently. I'd like to:
- Define a variable at the beginning of the program that identifies a single team - say Boston (shown as BOS)
- For each column, only draw the gray box for the player that plays for BOS and all the players below him in the column
The goal is to show how Boston pitchers rank compared to the rest of the league, with each column representing a quartile of pitchers. So each column would show (via the height of the gray boxes) how well ranked each Boston pitcher is). Sort of like a graphic equalizer. I tried to create some logic within the loop to do this, but got nowhere (a bit too advanced for me and I spun my wheels for a long time).
Can someone look at my code and help me figure out how to do this? Thanks a ton! Kevin
CODE BELOW:
// misc setup
void setup() {
size(1280,800);
PFont font;
font = loadFont("CenturyGothic-20.vlw");
textFont(font);
}
// color settings
// background color
int r1=240;int g1=235;int b1=235;
// highlighted color
int r2=165;int g2=165;int b2=165;
//text color
int r3=250;int g3=250;int b3=250;
void draw() {
background (r1,g1,b1); //gray
// parsing data from external file (column [0] is list of names, column [1] is ranks, column [2] is abbreviated team name)
String lines[] = loadStrings("rankometerdata.txt");
//loop formula for text
for(int k=0; k<5; k++){ // master loop to format 5 columns of names
for(int j=k*14; j<k*14+14; j++){ //sub loop to format 14 rows of names within each column
int z=j-k*14; // special variable I use to index down and across rows and columns
String[] name = splitTokens(lines[j+1]);
//highlighting each name across 5 columns and 14 rows
fill(r2,g2,b2);
rect(k*220+45,310+z*30,180,25);
// overlaying text
noStroke();
textSize(20);
fill(r3,g3,b3); //text color
text(name[0]+" ["+name[2]+"]",k*220+55,330+z*30);
}
}
}
1