Hello to all!
The program will have to calculate the Santiago de Compostela distance (x, y position 490,110) to all cities and save the coordinates and distance from the city further away in the Array distances. Likewise, the calc_Distance() function, also created for this purpose, will be used to help calculate the distances.
// 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},
};
// 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(){
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))));
}