xxxxxxxxxx
85
let data;
function preload() {
//data = loadTable(url, 'csv', 'header');
data = loadTable('2020A.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(20);
//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 author = data.getColumn("Author");
let genre = data.getColumn("Main Genre");
//debug
print(pages);
print(title);
print(genre);
//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]/2; //pages is length of bar
let h = 10;
if (genre[i] == 1) {
fill("#05C3DD");
} else if (genre[i] == 2) {
fill("#004C97");
} else if (genre[i] == 3) {
fill("#5F249F");
} else if (genre[i] == 4) {
fill("#FFAD00");
} else if (genre[i] == 5) {
fill("#007A33");
} else if (genre[i] == 6) {
fill("#A7D500");
} else if (genre[i] == 7) {
fill("#EE3831");
} else if (genre[i] == 8) {
fill("#8A2B2B");
} else if (genre[i] == 9) {
fill("#DA1984");
} else if (genre[i] == 10) {
fill("#8C8985");
}
push();
translate(width / 2, height / 2);
rotate((360 / numRows) * i);
rect(300, 0, w, h); // outside circle
rect(200, 0, 30, 10); // inside circle
// rect(100, 0, rating, 10); // inside circle
circle(300+w+20,5,10);
// image(picture, 300+w+20,5);
fill(255);
text(title[i], 300+w+40, 5);
pop();
}
}
//save();
}