We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi! I'm writing a really simple program to denote a certain dataset in colors. I'm sure there is a more elegant way to do this, but at this point, I'm trying to split the months across three categories (months Jan through April is blue, May through August is Yellow, and Sept through December is green). It seems to be working perfectly, until I insert month[i]==08. It returns unexpected token: 8. Any suggestions?
Table pdd;
String file ="data/somedatahere.tsv";
int year[];
int month[];
int downloads[];
int rows;
color white = color(255, 255, 255);
color blue = color(29, 145, 192);
color yellow = color(250, 187,12);
color green = color(70,138,7);
color mix;
void setup() {
//size & margins
size(1400, 800);
int lmargin = 50;
int tmargin = 50;
int canvaswd= (width-(2*lmargin));
//load & parse file
pdd=loadTable(file,"header");
rows= pdd.getRowCount();
println(rows);
year= new int[rows];
month= new int[rows];
downloads= new int[rows];
for (int i=0; i<rows; i++){
TableRow row= pdd.getRow(i);
year[i]=row.getInt("YY");
month[i]=row.getInt("MM");
downloads[i]=row.getInt("Downloads");
}
}
void draw(){
background(0);
int lmargin=50;
int tmargin=50;
for(int i=0; i<rows; i++){
float amt = map(downloads[i], 3974, 178736, 0, 1);
if(month[i]==01 ||month[i]==02 || month[i]==03 ||month[i]==04 ){
mix = lerpColor(white, blue, amt);
} else if (month[i]==05 || month[i] ==06 || month[i]==07){
mix =lerpColor(white,yellow,amt);
}
else {
mix = lerpColor(white, green, amt);}
fill(mix);
rect(lmargin+lmargin*0.2*i,(height-tmargin)/2,10,10);
}
}
Answers
Ha! Good one. Try running this:
Numbers that start with 0 are in octal, or base 8. For 01 to 07, this is the same as 1 to 7. But 08 doesn't make sense in octal, since the number after 07 is 010!
Just leave off the leading zeros and everything will be fine.
Thank you! :)