xxxxxxxxxx
44
let table;
let pokemonMap;
let anglearr;
let numRows;
function preload() {
table = loadTable("assets/pokemon.csv", "csv", "header");
}
function setup() {
angleMode(DEGREES)
pokemonMap = new Map();
numRows = table.getRowCount();
for (let r = 0; r < numRows; r++){
let type = table.getString(r, 'type1');
if(!pokemonMap.get(type)){
pokemonMap.set(type, {val: 1});
}else{
pokemonMap.get(type).val+=1;
}
}
anglearr = [];
for(let [type,obj] of pokemonMap){
anglearr.push({type,val:obj.val})
}
createCanvas(400, 400);
textAlign(CENTER);
}
function draw() {
const textrad = 130;
noLoop();
background(255);
let currangle = 0;
for(let i=0; i < anglearr.length; i++){
fill(random(255),random(255),random(255));
let nextdeg = anglearr[i].val/numRows*360;
arc(width/2, height/2, width/2, height/2, currangle, nextdeg, PIE);
let midangle = (2*currangle+nextdeg)/2
let y = textrad * sin(midangle)
let x = textrad * cos(midangle)
text(anglearr[i].type, width/2+x, height/2+y)
currangle+=nextdeg;
}
}