Actually both changing coordinates as well as adding grid lines. The grid lines is the second part of my problem. I started by adding a map, and adding towns to that map. Then I used a new map which is bigger than the first one, so I have to change the coordinates, so that the towns are located at their correct positions on the new map.
This is what I have, but then I'l probably have to email you the data I have:
import java.util.Collections;
/* Mouseover version
with name and population
Also, better methods - atomic
*/
PImage mapImage;
Table locationTable = new Table();
PFont font;
int rowCount;
ArrayList<Town> towns;
void setup() {
size(1000, 887);
smooth();
mapImage = loadImage("NAM_satellite_01.png");
font = loadFont("ArialNarrow-12.vlw");
textFont(font, 14);
towns = new ArrayList<Town>();
this.populateTownsList();
// this.sortByTownName();
// this.sortByPopulationSize();
}
void draw() {
background(#7DE37C); // light green
image(mapImage, 0, 0);
stroke(0);
// scale(1.31);
for (Town town : towns) {
town.drawTown();
town.showTownData();
}
}
void populateTownsList() {
float x, y;
int malePopulation;
int femalePopulation;
String townName;
locationTable = loadTable("Towns_and_villages.csv");
rowCount = locationTable.getRowCount();
for (int i = 0; i < rowCount; i++) {
TableRow row = locationTable.getRow(i);
x = row.getFloat(10);
y = row.getFloat(11);
malePopulation = row.getInt(5);
femalePopulation = row.getInt(6);
townName = row.getString(0);
towns.add(new Town(x, y, malePopulation, femalePopulation, townName));
}
}
void sortByTownName() {
Collections.sort(towns, new SortByTownName());
for(Town town : towns) {
println(town.getTownName());
}
}
void sortByPopulationSize() {
Collections.sort(towns, new SortByPopulationSize());
for(Town town : towns) {
println(town.getPopulationSize() + " -> " + town.getTownName());
}
}
Then i have a Town class which is as follows:
class Town {
// Variables
int radius, malePopulation, femalePopulation, population;
int townSize1 = 300, townSize2 = 600, townSize3 = 1000, townSize4 = 10000,
townSize5 = 25000, townSize6 = 50000;
float x, y;
String townName;
color townColor;
// Constructor
Town(float x, float y, int malePopulation, int femalePopulation, String townName) {
// this.radius = radius;
this.x = x;
this.y = y;
this.malePopulation = malePopulation;
this.femalePopulation = femalePopulation;
this.population = malePopulation + femalePopulation;
this.townName = townName;
}
// Functions
// Draw a town symbol
void drawTown() {
if (population < townSize1) {
radius = 6;
townColor = color(#FC85B1);
} else if (population < townSize2) {
radius = 6;
townColor = color(#AA70FC);
} else if (population < townSize3) {
radius = 6;
townColor = color(#5C90FC);
} else if (population < townSize4) {
radius = 7;
townColor = color(#5CF0FC);
} else if (population < townSize5) {
radius = 9;
townColor = color(#D9FF31);
} else if (population < townSize6) {
radius = 11;
townColor = color(#FFD331);
} else {
radius = 13;
townColor = color(255);
}
fill(townColor);
rectMode(CENTER);
rect(x, y, radius, radius);
}
// Show town name and population on mouse rollover
void showTownData() {
if (dist(x, y, mouseX, mouseY) < this.radius - 4) {
fill(0);
textAlign(CENTER);
text(townName, x, y - (this.radius + 9));
text("Pop: " + population, x, y - (this.radius - 3));
this.showGenderPieChart();
}
}
private void showGenderPieChart() {
int xTitle = width - 175;
int yTitle = height - 275;
int diameter = radius * 10;
text("Gender balance: " + townName, xTitle, yTitle - (14 + diameter/2));
fill(#9DB8FF);
ellipse(xTitle, yTitle, diameter, diameter);
fill(#F39DFF);
arc(xTitle, yTitle, diameter, diameter, 0, TWO_PI * femalePopulation/(float)population, PIE);
}
}
Answers
vs
which is it?
anyway, grid lines: at its simplest it's just a for() loop and some calls to line(), some vertical, some horizontal.
show us what you have, we will help.
Actually both changing coordinates as well as adding grid lines. The grid lines is the second part of my problem. I started by adding a map, and adding towns to that map. Then I used a new map which is bigger than the first one, so I have to change the coordinates, so that the towns are located at their correct positions on the new map. This is what I have, but then I'l probably have to email you the data I have:
Then i have a Town class which is as follows: