var table; var myDictionary; var colors = []; var legend = []; function preload() { table = loadTable('crime3.csv', 'csv', 'header'); } function setup() { createCanvas(1000, 1000); var dept = table.getColumn('Department'); var idx = 0; myDictionary = createNumberDict("dept", 00); for(var x = 0; x < table.getRowCount(); x++){ if(!myDictionary.hasKey(dept[x])){ var color = [] for(var n = 0; n < 3; n++){ var c = random(256) append(color, c) } append(colors, color) append(legend, dept[x]) myDictionary.set(dept[x], idx); idx = idx + 1; } } print(colors) print(myDictionary) } function draw(){ clear() var total_Rape = table.getColumn('Totals.Violent.Rape'); var total_Murder = table.getColumn('Totals.Violent.Murder'); var dept = table.getColumn('Department'); push(); fill(0,0,0) textSize(30) textStyle(BOLD) text("Police Department Crimes", 250, 500) pop() fill(0,0,0) textSize(10); text('# of Rapes', 10, 200); line(110,10,110, 410); textSize(10); text("# of Murders", 410, 450); line(100,400,800, 400); for(var x = 0; x < table.getRowCount(); x++){ var tick1 = map(total_Murder[x], min(total_Murder), max(total_Murder), 110,800) line(tick1,400, tick1,406) } for(var x = 0; x < table.getRowCount(); x++){ var tick1 = map(total_Murder[x], min(total_Murder), max(total_Murder), 110,800) text(total_Murder[x], tick1-3, 420) } for(var x = 0; x < table.getRowCount(); x++){ var tick2 = map(total_Rape[x], min(total_Rape), max(total_Rape), 400,10) line(105,tick2, 110,tick2) text(0,0,0) text(total_Rape[x], 90,tick2+2) } translate(110,400); var first_x = map(total_Murder[0], min(total_Murder), max(total_Murder), 0, 690) var first_y = map(total_Rape[0], min(total_Rape), max(total_Rape), 0,390) var time = 0; for(var x = 0; x < table.getRowCount(); x++){ var x0 = map(total_Murder[x-1], min(total_Murder), max(total_Murder), 0, 690) var y0 = map(total_Rape[x-1], min(total_Rape), max(total_Rape), 0,390) var x1 = map(total_Murder[x], min(total_Murder), max(total_Murder), 0, 690) var y1 = map(total_Rape[x], min(total_Rape), max(total_Rape), 0,390) var name = dept[x] var color_id = myDictionary.get(name) print(color_id) var colorList = colors[color_id]; print(colorList) fill(colorList[0], colorList[1], colorList[2]) ellipse(x1, -y1, 5, 5); if(mouseX-110 < x1+2 && mouseX-110 > x1-2 && mouseY-400 < -y1+2 && mouseY-400> -y1-2){ textSize(10); fill(0,0,0) text(" # of Rapes: " + total_Rape[x], mouseX-110, mouseY-400) text(" # of Murders: " + total_Murder[x], mouseX-110, mouseY-390) } } var depty = -310 for(var x = 0; x < legend.length; x++){ var clist = colors[x] fill(clist[0], clist[1], clist[2]) text(legend[x], 700, depty) depty = depty - 10 } fill(0,0,0) text("Department: ", 700, depty-10) }