Help with arrays!

The fact you pasted it without Preformatting it (Ctrl+E) gave me a heart-ache. So I did this to make it easier to read

PImage SpainMap; //

// Multidimensional Array
// Position X of every city
// Position Y
// Population of the city
int cities = {
{930, 350, 800000},
{1063, 215, 1660000},
{900, 190, 675000},
{865, 115, 209000},
{825, 138, 151000},
{813, 111, 254000},
{750, 70, 172000},
{640, 70, 218000},
{490, 110, 98000},
{690, 190, 298000},
{755, 278, 3300000},
{738, 317, 85000},
{613, 378, 59000},
{633, 485, 684000},
{895, 445, 461000},
{1093, 335, 419000},
{667, 591, 83500},
{794, 630, 86000},
};

//Color variable
color blau = color (1,60,213); //Blue
color verd = color (0,255,0); //Green
color vermell = color (255,0,0); //Red
color negre = color (0,0,0); //Black
color blanc = color (255,255,255); //Whit

// Cities names
String  names = {“Valencia”, “Barcelona”, “Zaragoza”, “Pamplona”, “Logroño”, “Vitoria”, “Santander”, “Oviedo”, “Santiago de C.”, “Valladolid”, “Madrid”, “Toledo”, “Mérida”, “Sevilla”, “Murcia”, “Palma de M.”, “Ceuta”, “Melilla”};
// number of the cities
int total_Cities = 18;
// Variable to save the distance between cities
int distance;
// Array to save the position on X, Y and the distance between Santiago and the other cities
int distances = new int[3];

void setup(){

size(1227, 639);
// Load Image
SpainMap = loadImage(“MapaEsp.png”);
// Reajust the image
SpainMap.resize(1227, 639);

}

void draw(){

image(SpainMap, 0, 0);

// Bucle to generate circles
for (int i=0; i<names.length; i++) {
//Variable to modify the size of the circle
float circle_D = map (cities [i] [2], 59000, 3300000, 5,60);

//Conditional estructure
if (cities [i] [2] < 200000) { //Cities < 200.000 population
fill (blau); //
circle (cities [i][0], cities [i][1], circle_D);
} else if (cities [i] [2] > 200000 && cities [i] [2] < 400000) { //Cities > 200.000 and < 400.000 population
fill (verd);
circle (cities [i][0], cities [i][1], circle_D);
} else if (cities [i] [2] > 400000) { //Cities > 400.000 population
fill (vermell);
circle (cities [i][0], cities [i][1], circle_D);
}}

//Bucle to generate the name of the cities
for (int i = 0; i<names.length; i++){
fill (negre); //farcit del text
text (names [i], cities [i][0]+10, cities [i][1]); //names of the cities
}

//Elements of the legend
float x = width/61.35;
int base = width/3;
int altura = base/4;
float diametre = x/2;

//Rect of the legend
fill(blanc);
rect (x, height-altura-x, base , altura);
fill (blau);
circle (2x, height-altura+x, diametre);
fill (verd); //farcilt del cercle
circle (2x, height-altura+2x, diametre);
fill (vermell);
circle (2x, height-altura+3x, diametre);
fill (negre);
//Texts of the legend
text (“LLEGENDA”, x+x/2, height-altura);
text (“Ciutats amb menys de 200.000 habitants”, 3x, height-altura+x+diametre/2);
text (“Ciutats amb més de 200.000 habitants i menys de 400,000”, 3x, height-altura+2x+diametre/2);
text (“Ciutats amb més de 400.000 habitants”, 3x, height-altura+3x+diametre/2);

}

int calc_Distance(int posX_1, int posY_1, int posX_2, int posY_2){
// Apliquem Pitàgores i tornem el valor de la distància entre ciutats
return(int(sqrt(pow(posX_2-posX_1,2)+pow(posY_2-posY_1,2))));
}

4 Likes