import java.util.Random; SetOfBoroughs soB; PGraphics fake; public class SetOfBoroughs { String[] boroughNames = new String[33]; color[] identCol = new color[33]; Borough[] boroughs; PShape parent; SetOfBoroughs(){ boroughNames[0] = "City of London"; boroughNames[1] = "City of Westminster"; boroughNames[2] = "Kensington and Chelsea"; boroughNames[3] = "Hammersmith and Fulham"; boroughNames[4] = "Wandsworth"; boroughNames[5] = "Lambeth"; boroughNames[6] = "Southwark"; boroughNames[7] = "Tower Hamlets"; boroughNames[8] = "Hackney"; boroughNames[9] = "Islington"; boroughNames[10] = "Camden"; boroughNames[11] = "Brent"; boroughNames[12] = "Ealing"; boroughNames[13] = "Hounslow"; boroughNames[14] = "Kingston upon Thames"; boroughNames[15] = "Merton"; boroughNames[16] = "Sutton"; boroughNames[17] = "Croydon"; boroughNames[18] = "Bromley"; boroughNames[19] = "Lewisham"; boroughNames[20] = "Greenwich"; boroughNames[21] = "Bexley"; boroughNames[22] = "Havering"; boroughNames[23] = "Barking and Dagenham"; boroughNames[24] = "Redbridge"; boroughNames[25] = "Newham"; boroughNames[26] = "Waltham Forest"; boroughNames[27] = "Haringey"; boroughNames[28] = "Enfield"; boroughNames[29] = "Barnet"; boroughNames[30] = "Harrow"; boroughNames[31] = "Hillingdon"; boroughNames[32] = "Richmond upon Thames"; identCol[0] = color(255,204,0); identCol[1] = color(0,136,170); identCol[2] = color(128,0,0); identCol[3] = color(103,120,33); identCol[4] = color(147,172,157); identCol[5] = color(212,85,0); identCol[6] = color(40,11,11); identCol[7] = color(44,160,137); identCol[8] = color(85,0,34); identCol[9] = color(255,128,128); identCol[10] = color(255,0,204); identCol[11] = color(255,0,255); identCol[12] = color(135,170,222); identCol[13] = color(108,83,93); identCol[14] = color(68,170,0); identCol[15] = color(0,255,204); identCol[16] = color(55,200,113); identCol[17] = color(255,42,127); identCol[18] = color(200,55,55); identCol[19] = color(255,213,246); identCol[20] = color(170,212,0); identCol[21] = color(221,85,255); identCol[22] = color(0,0,255); identCol[23] = color(113,55,200); identCol[24] = color(255,170,170); identCol[25] = color(85,221,255); identCol[26] = color(255,127,42); identCol[27] = color(153,85,255); identCol[28] = color(255,255,0); identCol[29] = color(212,255,42); identCol[30] = color(85,153,255); identCol[31] = color(255,0,0); identCol[32] = color(128,0,128); boroughs = new Borough[33]; //locations[0] = new PVector(300,300); parent = loadShape("All_Boroughs.svg"); for (int i = 0; i < 33; i++) { boroughs[i] = new Borough(boroughNames[i], identCol[i], parent); } } Borough getBorough(int Index){ Borough ret = boroughs[Index]; return ret; } void drawBoroughs(){ for (int i = 0; i < 33; i++) { //boroughs[i].updateColor(BOROUGH SCORE); 101 - 3305 boroughs[i].drawBorough(); } } } public class Borough { String name; PShape shape; color colour; color identColour; //PVector v; float scale; Borough(String aName, color aIdent, PShape parentShape){ name = aName; shape = parentShape.getChild(aName); identColour = aIdent; colour = color(255,255,255); scale = 1.0; shape.disableStyle(); //v = location; Random rand = new Random(); updateColor(rand.nextInt(3305-101)+102); } Integer normalizeScore(Integer score){ if (score < 0) { score = 0; } else if (score > 255) { score = 255; } return score; } Integer scoreToColor(Integer score){ // score is from 101 to 3305 or something. // level of colour = 20; float levelOfColor = 20; float pLA = (3305 - 101)/levelOfColor; float pLB = (255 - 0)/levelOfColor; float ret = (score/pLA)*(pLB); Integer put = (int)Math.floor(ret); Integer retInt = normalizeScore(put); return retInt; } void updateColor(Integer score){ colour = color(0,scoreToColor(score),0); } void drawBorough(){ shapeMode(CORNER); fill(colour); shape(shape, 0, 0, displayWidth, displayHeight+250); } Boolean isIdent(color identCol){ return identCol==identColour; } String getName(){ return name; } } String pressedBorough = null; void mousePressed() { color colpos = fake.get(mouseX,mouseY); // get colour for (int i = 0; i < 33; i++){ if (soB.getBorough(i).isIdent(colpos)){ pressedBorough=soB.getBorough(i).getName(); break; } } } PShape f; void setup(){ soB = new SetOfBoroughs(); f = loadShape("colBoroughs.svg"); fake = createGraphics(displayWidth,displayHeight+250,JAVA2D); orientation(LANDSCAPE); size(displayWidth, displayHeight); } void draw(){ background(51); fake.shape(f, 0,0, displayWidth, displayHeight); soB.drawBoroughs(); if (pressedBorough != null){ fill(255,255,255); textSize(32); text(pressedBorough, 100,100); //pressedBorough=null; } }