xxxxxxxxxx
92
let data;
function preload() {
//data = loadTable(url, 'csv', 'header');
data = loadTable('2011data.csv', 'csv', 'header');
}
function setup() {
createCanvas(2000, 2000, SVG);
noStroke(); // this seems to be important to save an svg
// rotate with numbers instead of weird pi things
angleMode(DEGREES);
noLoop();
}
function draw() {
background(255);
//this makes sure there is content in the data
if (data) {
//get the amount of rows in the CSV
let numRows = data.getRowCount();
//get the column titled Miles
let pages = data.getColumn('Number of Pages');
let title = data.getColumn("Title");
let genre = data.getColumn("Main Genre");
let rating = data.getColumn("My Rating");
//debug
print(pages);
print(title);
print(genre);
print(rating);
//iterate over the number of rows
for (let i = 0; i < numRows; i++) {
let x = 100;
let y = 100 + (i * 15); //i*20 will increment by 20 each time the loop runs
let w = pages[i]/1.5; //pages is length of bar
let h = 25;
let z = rating[i]*10; //for inner circle bars
if (genre[i] == 1) {
fill("#99CCD3");
} else if (genre[i] == 2) {
fill("#7C96B0");
} else if (genre[i] == 3) {
fill("#A494AB");
} else if (genre[i] == 4) {
fill("#F2BE88");
} else if (genre[i] == 5) {
fill("#87A18F");
} else if (genre[i] == 6) {
fill("#DCD7A3");
} else if (genre[i] == 7) {
fill("#DB898E");
} else if (genre[i] == 8) {
fill("#CC6770");
} else if (genre[i] == 9) {
fill("#D28FB1");
} else if (genre[i] == 10) {
fill("#BCBEC0");
}
push();
translate(width / 2, height / 2);
rotate((360 / numRows) * i);
rect(400, 0, w, h); // outside circle
fill(80);
rect(330, 0, z, 25); // inside circle
// rect(100, 0, rating, 10); // inside circle
// circle(300+w+20,5,10);
// image(picture, 300+w+20,5);
fill(0);
textSize(14);
textFont ('Arial');
text(title[i], 405, 16);
pop();
}
}
save();
}