// Poker Analzyer // Daniel Shiffman // Hacked together in all of 15 minutes // Needs a ton of work. . . float cards = 13; float w,h; int offset = 32; PFont f; String file = "pokerstats.csv"; Hand hands[]; void setup() { size(600,600); w = (width - offset*2) / cards; h = (height - offset*2) / cards; smooth(); colorMode(RGB,255,255,255,255); String[] data = loadStrings(file); hands = new Hand[13*13]; f = loadFont("ArialNarrow-14.vlw"); for (int i = 0; i < data.length; i++) { String[] h = split(data[i],','); String name = h[0]; float val = float (h[1]); int card1 = card(name.charAt(0)); int card2 = card(name.charAt(1)); boolean suited; if (name.length() > 2) suited = suited(name.charAt(2)); else suited = false; hands[i] = new Hand(card1,card2,suited,val,name); } float mx = findmax(hands); float mn = findmin(hands); //normalize(hands,mx,mn); normalize(hands,mx*0.8,mn*0.8); //HACKY HACKY HACK HACK } void draw() { background(25); int mx = mouseX; int my = mouseY; Hand thehand = null; for (int i = 0; i < hands.length; i++) { Hand hand = hands[i]; float s = hand.norm*(255+50);//constrain(hand.val * 200,-255,255); float overage = constrain(abs(s) - 255,0,100); color c; if (s > 0) c = color(0,constrain(abs(s),0,255),overage); else c = color(constrain(abs(s),0,255),0,overage); stroke(100); if (hand.rollover(mx,my)) { thehand = hand; } fill(c); //ellipse(x*w + w/2 + offset,y*h + h/2 + offset,s,s); strokeWeight(1); rect(hand.x,hand.y,w,h); textFont(f); textAlign(CENTER); if (brightness(c) > 200) fill(0); else fill(255); //if (hand.rollover(mx,my)) fill(50); text(hand.name,hand.x+w/2,hand.y + h/2 +4); } if (thehand != null) { textFont(f); textAlign(LEFT); text(thehand.name + ": ",offset,height-offset/2.5); text(thehand.val + " big blinds per hand.",offset+36,height-offset/2.5); //noStroke(); //if (thehand.val > 0) fill(0,255,0,50); //else fill(255,0,0,50); noFill(); strokeWeight(2); if (thehand.val > 0) { stroke(0,255,0); fill(0,255,0,50); } else { stroke(255,0,0); fill(255,0,0,50); } rect(thehand.x,thehand.y,w,h); } fill(255); textAlign(LEFT); text("Poker Hand Analysis (Limit Texas Hold'em) of ~16,000 hands played",offset,offset/1.5); //noLoop(); } void mousePressed() { saveFrame(); }