Skip to content

Instantly share code, notes, and snippets.

@memish
Created December 12, 2018 18:43
Show Gist options
  • Save memish/75b14acb51bdae2fe180f3c13a0be522 to your computer and use it in GitHub Desktop.
Save memish/75b14acb51bdae2fe180f3c13a0be522 to your computer and use it in GitHub Desktop.
String[] lines;
ArrayList<String> pnames = new ArrayList<String>();
ArrayList<Integer> count = new ArrayList<Integer>();
int x = 0;
int y = 380;
int size = 1;
String name = "player";
int amount = 1;
void setup(){
size(700,400);
read();
}
void draw(){
background(5);
textSize(32);
text(name + " " + amount, 10, 30);
size = (width/count.size());
//printArray(size + " " + width + " " + count.size());
x = 0;
for(int j=0; j<count.size(); j++){
stroke(255,0,0);
rect(x,y,size,-count.get(j));
x += size;
}
}
public void read(){
lines = loadStrings("http://192.168.1.168/nba.csv");
println("There are " + lines.length + " lines.");
//printArray(lines);
for(int i=0; i<lines.length; i++){//look at each line
String[] s1 = lines[i].split(",");
//players name s1[1]
boolean found = false;
for(int j=0; j<pnames.size(); j++){//is it already in
//the pname arraylist?
if(pnames.get(j).equals(s1[1])){//if it is
count.set(j,count.get(j)+1);//update the count list
found = true;
}
}//
if(found==false){//if it's not add it
pnames.add(s1[1]);
count.add(1);
}
}//end of for loop
//remove if not more than once
for(int j=count.size()-1; j>=0; j--){
if(count.get(j)<10){
count.remove(j);
pnames.remove(j);
}
}
println(count.size());
}//end of read function
void mousePressed(){
int xspot = mouseX/size;
name = pnames.get(xspot);
amount = count.get(xspot);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment