oompa_l
Full Member
Offline
Posts: 212
Re: noob seek. optimization help for 3d dataviz gr
Reply #2 - Oct 26th , 2008, 1:17am
main sketch pt 2: void setupGrid(){ if (keyPressed && key == 'x' && keyreset == true) { // got first signal keyreset = false; if(xvisible == false) { xvisible = true; } else { xvisible = false; } } if (keyPressed && key == 'y' && keyreset == true) { // got first signal keyreset = false; if(yvisible == false) { yvisible = true; } else { yvisible = false; } } if (keyPressed && key == 'z' && keyreset == true) { // got first signal keyreset = false; if(zvisible == false) { zvisible = true; } else { zvisible = false; } } int numX = dietTypes.length+1; int numY = climateTypes.length+1; int numZ = specialTypes.length+1; int incX = (maxX-minX)/numX; int incY = (maxY-minY)/numY; int incZ = (maxZ-minZ)/numZ; for (int k =0; k < numZ+1; k++) { //for every plane along the Z axis // draw the line only if set to "visible" if(xvisible == true) { stroke(0,255,0); //draw a a series of lines along the X axis for (int i = 0; i < numX+1; i++) { //hor. direction line(minX + i * incX, minY, minZ + k * incZ, minX + i * incX, maxY, minZ + k * incZ); } } if(yvisible == true) { stroke(0,0,255); //draw a a series of lines along the Y axis for (int j = 0; j < numY+1; j++) { //=vert.direction line(minX, minY + j * incY, minZ + k * incZ, maxX, minY + j * incY, minZ + k * incZ); } } } if(zvisible == true) { stroke(255,0,0); for (int i = 0; i < numX+1; i++) { for (int j= 0; j < numY+1; j++) { line(minX + i * incX, minY + j * incY, minZ, minX + i * incX, minY + j * incY, maxZ); } } } } void drawAnimals (){ for (int row=1; row<rowCount; row++) { float weight = animalValuesTable.getFloat(row,1); String diet = animalValuesTable.getString(row,15); String climate = animalValuesTable.getString(row,4); String common = animalValuesTable.getString(row,0); String special = animalValuesTable.getString(row,10); int y = dietIndex(diet); float yfloat = y; yfloat = map(y, 0, dietTypes.length-1, minY, maxY); int x = climateIndex(climate); float xfloat = x; xfloat = map(x, 0, climateTypes.length-1, minX, maxZ); int z = specialIndex(special); float zfloat = z; zfloat = map(z, 0 , specialTypes.length-1, minZ, maxZ); drawData(xfloat, yfloat, zfloat, common, diet, weight); //drawCylinder(x, y, random(0, 100) , weight, weight, 50, 12); } } void drawData (float x, float y, float z, String common, String diet, float weight) { pushMatrix(); translate(0,0,z); if (diet.equals("carnivore")){ fill(#FF5166); } else if (diet.equals("herbivore")) { fill(#EC5166); } else { fill(#CC5166); } ellipse(x,y, weight/8,weight/8); //println(diet); fill(0); PFont font = loadFont("Swiss721BT-Light-12.vlw"); textFont(font); //textSize(24); text(common, x, y-weight/16); popMatrix(); }