Hi Chigoz!
First of all I want to thank you for your help but I don’t think I’m doing well. I share my code and the text of my task so you can understand it better and see where the problem is.
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))));
}
Calculate the distance in a straight line between Santiago de Compostela and the city further away from it, as well as convert that distance (which you will obtain in pixels) to kilometers. Keep in mind that, for the scale of the canvas, you can assume that 1 pixel is equivalent to 1.56 km. The program will have to calculate the Santiago de Compostela distance to all cities and save the coordinates and distance from the city further away to the Aray distances created for this purpose. Likewise, the calc_Distance() function, also created for this purpose, will be used to help calculate the distances. The starting program with the distance variables, the aray distances and the calc_Distance() function are available in the enunciated folder, named NivellB.
Function of calc_Distance:
At some point in draw() you must use the following order:
distance = calc_Distance (X1, Y1, X2, Y2);
Which means "keep in the distance variable the value that returns the calc_Distance function(), which is a function that returns an integer which is the distance (in pixels) between
6
cities (i.e. distance saves the value of the distance in pixels between sent cities).
The values X1, Y1, X2 and Y2 refer to the position in X and Y of the first and second cities respectively, and you must put, where X1, Y1, X2, Y2, the variables you consider to be .
Represent this distance in a violet straight line (255, 0, 255) that goes from Santiago to the aforementioned city, and in which it appears, halfway between the cities, in black and in size 30 (indicate it through the instruction textSize(30)), the distance in kilometers between them. The remainder of the text must be followed in default size, i.e. textSize(10).Preformatted text