clsnyder
YaBB Newbies
Offline
Posts: 5
Rollover based on color rather than position
Oct 15th , 2008, 11:54pm
Hi I have some code that looks up stock data from yahoo's site, and then creates a colored pie graph based on the fractional value of each stock versus the total. I wanted to have a rollover to pop up specific info about the stock when the mouse rolls over a particular stocks 'wedge' of the pie. Trying to find the precise location of the wedge in x,y coordinates seemed difficult, so I am trying to use the color of the wedge to identify which stock is being rolled over. The code below doesn't work, and I'm not clear why not.... Maybe this isn't even possible? ---------------------------------- import processing.opengl.*; Record[] records; int recordCount; PFont body; int startingEntry = 0; int num; String alldata = ""; int total; int networth = 0; int dailych = 0; String summary_list; int diameter = 150; float lastAng = 0; color mycolor = 0; void setup() { size(600,600,OPENGL); background(150); frameRate(30); body = loadFont("Tahoma-10.vlw"); String[] mystocks = loadStrings("mystocks.tsv"); num = mystocks.length; records = new Record[mystocks.length]; for (int i = 1; i < mystocks.length; i++) { String[] pieces = split(mystocks[i], '\t'); records[recordCount] = new Record(pieces); recordCount++; } for(int i=0;i<mystocks.length-1;i++) { networth += int(records[i].holdings); colormaker(i); dailych += int((records[i].dollar_daily_change)); summary_list = "Today's net worth is: $ "+ nfc(networth) + "\n\n" + "Today's change was: $ " + nfc(dailych); } } void draw() { pushMatrix(); drawpie(); popMatrix(); } void colormaker(int index){ float n1=random(255-5*index); float n2=random(255-5*index); float n3=random(255-5*index); mycolor = color(n1,n2,n3); records[index].rectcolor = mycolor; } void drawpie(){ update(mouseX, mouseY); for (int i = 0; i < num-1; i++) { fill(records[i].rectcolor); textFont(body); arc(width/2, height/2, diameter, diameter, lastAng, lastAng+radians(records[i].holdings/networth*360)); lastAng += radians(records[i].holdings/networth*360); rect(30,30 +i *12, 10,10); fill(255); text(records[i].symb, 55,40+i *12); text(records[i].dollar_daily_change, 100,40+i *12); } } void update(int x, int y){ if(mousePressed == true) { color cp = get(mouseX, mouseY); for (int i = 0; i < num-1; i++) { print(records[1].rectcolor+ records[1].symb +"\n" + cp); if(cp == records[i].rectcolor){ print(records[1].symb); } } } } Thanks! Charles Snyder