Skip to content
Snippets Groups Projects
Commit 382d8cc3 authored by Lucas Philippe's avatar Lucas Philippe
Browse files

ajout premiere partie TP5

parent 5694c27e
No related branches found
No related tags found
No related merge requests found
File added
//globally
//declare the min and max variables that you need in parseInfo
float minX, maxX;
float minY, maxY;
int totalCount; // total number of places
int minPopulation, maxPopulation;
int minSurface, maxSurface;
int minAltitude, maxAltitude;
//declare the variables corresponding to the column ids for x and y
int x = 1;
int y = 2;
// and the tables in which the city coordinates will be stored
float xList[];
float yList[];
void setup() {
size(800,800);
readData();
}
void draw(){
background(255);
color black = color(0);
for (int i = 0 ; i < totalCount ; ++i) {
// draw a point at the coordinates of the city
float x = mapX(xList[i]);
float y = mapY(yList[i]);
stroke(black);
point(x, y);
}
updatePixels();
}
void readData() {
String[] lines = loadStrings("./villes.tsv");
// check that the file has been loaded
if (lines == null) {
println("Error loading file");
exit();
} else {
println("File loaded");
}
parseInfo(lines[0]); // read the header line
xList = new float[totalCount];
yList = new float[totalCount];
for (int i = 2 ; i < totalCount ; ++i) {
String[] columns = split(lines[i], TAB);
xList[i-2] = float (columns[x]);
yList[i-2] = float (columns[y]);
}
}
void parseInfo(String line) {
String infoString = line.substring(2); // remove the #
String[] infoPieces = split(infoString, ',');
totalCount = int(infoPieces[0]);
minX = float(infoPieces[1]);
maxX = float(infoPieces[2]);
minY = float(infoPieces[3]);
maxY = float(infoPieces[4]);
minPopulation = int(infoPieces[5]);
maxPopulation = int(infoPieces[6]);
minSurface = int(infoPieces[7]);
maxSurface = int(infoPieces[8]);
minAltitude = int(infoPieces[9]);
maxAltitude = int(infoPieces[10]);
}
float mapX(float x) {
return map(x, minX, maxX, 0, 800);
}
float mapY(float y) {
return map(y, maxY, minY, 0, 800);
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment