Whats wrong with my processing code?

processingjs

#1

Table energyTable, genderTable;
int energyTableRowCount, genderTableRowCount;
float femaleEnergy, maleEnergy, personalEnergy;
float maxFemaleEnergy, maxMaleEnergy, maxPersonalEnergy;

void setup() {
size(1000, 300); //size of screen

//load tables
energyTable = loadTable(“EnergyKcal.csv”, “header”);
genderTable = loadTable(“GenderTable.csv”, “header”);

energyTableRowCount = energyTable.getRowCount();
genderTableRowCount= genderTable.getRowCount();

println(“There are " + energyTableRowCount + " rows and " + genderTableRowCount + " rows in each table.”);

for (TableRow row : genderTable.rows()) {

femaleEnergy = row.getFloat(“Female Energy (kcal)”);
maleEnergy = row.getFloat(“Male Energy (kcal)”);

maxFemaleEnergy = max(femaleEnergy, maxFemaleEnergy);
maxMaleEnergy = max(maleEnergy, maxMaleEnergy);
}

for (TableRow row : energyTable.rows()) {

personalEnergy = row.getFloat(“Energy (kcal)”);

maxPersonalEnergy = max(personalEnergy, maxPersonalEnergy);
}
}

void draw() {
background(0); //black background

for (int i = 0; i < energyTableRowCount; i++) {

//femaleEnergy = genderTable.getRow(i).getFloat(“Female Energy (kcal)”);
// maleEnergy = genderTable.getRow(i).getFloat(“Male Energy (kcal)”);
personalEnergy = energyTable.getRow(i).getFloat(“Energy (kcal)”);

beginShape();
float centerX = 300.0;
float centerY = 100.0;
// add center vertex
curveVertex(centerX, centerY);
curveVertex(centerX, centerY);

float angle = map(i, 0, energyTableRowCount, 0, TWO_PI);

float mappedPersonalEnergy = map(personalEnergy, 0, maxPersonalEnergy, 60.0, 120.0);

float outerRadius = mappedPersonalEnergy;
float angleOffset1 = 20;
float distanceOffset2 = 40;
float angleOffset3 = 20;

float xCoord1 = centerX + outerRadius * sin(angle - radians(angleOffset1));
float yCoord1 = centerY + outerRadius * cos(angle - radians(angleOffset1));
curveVertex(xCoord1, yCoord1);

float xCoord2 = centerX + (outerRadius - distanceOffset2) * sin(angle);
float yCoord2 = centerY + (outerRadius - distanceOffset2) * cos(angle);
curveVertex(xCoord2, yCoord2);

float xCoord3 = centerX + outerRadius * sin(angle + radians(angleOffset3));
float yCoord3 = centerY + outerRadius * cos(angle + radians(angleOffset3));
curveVertex(xCoord3, yCoord3);

curveVertex(centerX, centerY);
curveVertex(centerX, centerY);
endShape();
}

for (int i = 0; i <genderTableaRowCount; i++) {

maleEnergy = genderTable.getRow(i).getFloat(“Male Energy (kcal)”);

beginShape();
float centerX = 300.0;
float centerY = 100.0;
// add center vertex
curveVertex(centerX, centerY);
curveVertex(centerX, centerY);

float angle = map(i, 0, genderTableRowCount, 0, TWO_PI);

float mappedMaleEnergy = map(maleEnergy, 0, maxMaleEnergy, 60.0, 120.0);

float outerRadius = mappedMaleEnergy;
float angleOffset1 = 20;
float distanceOffset2 = 40;
float angleOffset3 = 20;

float xCoord1 = centerX + outerRadius * sin(angle - radians(angleOffset1));
float yCoord1 = centerY + outerRadius * cos(angle - radians(angleOffset1));
curveVertex(xCoord1, yCoord1);
float xCoord2 = centerX + (outerRadius - distanceOffset2) * sin(angle);
float yCoord2 = centerY + (outerRadius - distanceOffset2) * cos(angle);
curveVertex(xCoord2, yCoord2);
float xCoord3 = centerX + outerRadius * sin(angle + radians(angleOffset3));
float yCoord3 = centerY + outerRadius * cos(angle + radians(angleOffset3));
curveVertex(xCoord3, yCoord3);
curveVertex(centerX, centerY);
curveVertex(centerX, centerY);
endShape();

for (int i = 0; i <genderTableaRowCount; i++) {

femaleEnergy = genderTable.getRow(i).getFloat(“Female Energy (kcal)”);

beginShape();
float centerX = 300.0;
float centerY = 100.0;
// add center vertex
curveVertex(centerX, centerY);
curveVertex(centerX, centerY);

float angle = map(i, 0, genderTableRowCount, 0, TWO_PI);

float mappedFemaleEnergy = map(femaleEnergy, 0, maxFemaleEnergy, 60.0, 120.0);

float outerRadius = mappedFemaleEnergy;
float angleOffset1 = 20;
float distanceOffset2 = 40;
float angleOffset3 = 20;

float xCoord1 = centerX + outerRadius * sin(angle - radians(angleOffset1));
float yCoord1 = centerY + outerRadius * cos(angle - radians(angleOffset1));
curveVertex(xCoord1, yCoord1);
float xCoord2 = centerX + (outerRadius - distanceOffset2) * sin(angle);
float yCoord2 = centerY + (outerRadius - distanceOffset2) * cos(angle);
curveVertex(xCoord2, yCoord2);
float xCoord3 = centerX + outerRadius * sin(angle + radians(angleOffset3));
float yCoord3 = centerY + outerRadius * cos(angle + radians(angleOffset3));
curveVertex(xCoord3, yCoord3);
curveVertex(centerX, centerY);
curveVertex(centerX, centerY);
endShape();
}}}


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.