clsnyder
YaBB Newbies
Offline
Posts: 5
ControlP5 and loop/noloop
Jan 30th , 2008, 5:30am
Hi I am using P5 in a sketch where I load a tsv file of stocks / mutual funds with price # shares etc; parse the data, and then a)create a pie graph from values of price * shares, etc - simple stuff. My actual question is this - when I use tabs / bangs/ buttons (any P5 element), they are inactive and freeze if I use noLoop() before drawing the graphics. On the other hand, if I don't use noLoop, the pie graph doesn't work and the data values are recalculated endlessly. Obviously, I'm missing something... (also, I wanted to set the color of the buttons to match the appropriate pie graph wedges, but can't get that to work either) ------------------------------------------------ //Code is : import controlP5.*; import processing.opengl.*; ControlP5 controlP5; Record[] records; int recordCount; PFont body; int startingEntry = 0; int num; String alldata = ""; Textarea myTextarea; int total; int networth = 0; int dailych = 0; String summary_list; int diameter = 150; float lastAng = 0; void setup() { size(600,600,OPENGL); background(100, 25); frameRate(30); controlP5 = new ControlP5(this); myTextarea = controlP5.addTextarea("Report", "Data Shown Here",100,100,200,60); myTextarea.setColorForeground(0xffff0000); controlP5.addSlider("changeWidth",0,200,100,100,80,100,9); controlP5.addSlider("changeHeight",0,200,100,100,60,100,9); String[] mystocks = loadStrings("mystocks.tsv");//reads mystocks data num = mystocks.length; records = new Record[mystocks.length]; //sets the size of the array by num rows in the mystocks.tsv for (int i = 1; i < mystocks.length; i++) { //skips the first row of headers String[] pieces = split(mystocks[i], '\t'); // Load mystocks data into array, based on the tab delimiter records[recordCount] = new Record(pieces); recordCount++; } for(int i=0;i<mystocks.length-1;i++) { networth += int(records[i].holdings); dailych += int((records[i].dollar_daily_change)); summary_list = "Today's net worth is: $ "+ nfc(networth) + "\n\n" + "Today's change was: $ " + nfc(dailych); myTextarea.setText(summary_list); } } void draw() { pushMatrix(); drawpie(); popMatrix(); } void changeWidth(int theValue) { myTextarea.setWidth(theValue); } void changeHeight(int theValue) { myTextarea.setHeight(theValue); } void controlEvent(ControlEvent theEvent) { println(theEvent.controller().id()); } void button(float theValue) { println("a button event. "+theValue); } void drawpie(){ noLoop(); for (int i = 0; i < num-1; i++) { fill(random(255 -5*i), random(255 -5*i), random(255 -5*i)); arc(width/2, height/2, diameter, diameter, lastAng, lastAng+radians(records[i].holdings/networth*360)); lastAng += radians(records[i].holdings/networth*360); controlP5.addButton(records[i].symb,30,0, 30+i*15,50,20).setId(i); //this.setColorValue(color(random(255 -5*i), random(255 -5*i), random(255 -5*i))); } } //-------------------------------------------------------- The class code is : class Record { String symb; String name; String asset_class; float basis; float num_shares; float price; float holdings; float per_daily_change; float dollar_daily_change; float asset_per_holdings; float per_overall_change; float dollar_overall_change; float pe_ratio; String sector; public Record(String[] pieces) { //This is used for the order of columns in the tsv file (last 2 are from yahoo) symb = pieces[0]; name = pieces[1]; asset_class = pieces[2]; basis = float(pieces[3]); num_shares = float(pieces[4]); price = float(pieces[5]); holdings = float(pieces[6]); per_daily_change = float(pieces[7]); dollar_daily_change = float(pieces[8]); asset_per_holdings = float(pieces[9]); per_overall_change = float(pieces[10]); dollar_overall_change = float(pieces[11]); pe_ratio = float(pieces[12]); } } Thanks in advance