dataviz_tp2.pde 2,01 ko
Newer Older
Hugo Landrin's avatar
Hugo Landrin a validé
PImage carte;
Table table;
Table tableDoubles;
int lignes;

PImage iconKorok;
PImage iconKorokDouble;

int baseKorokHeight = 7 * 4;
int baseKorokWidth = 7 * 4;
int baseKorokDoubleWidth = 9 * 4;
int baseKorokDoubleHeight = 7 * 4;

PFont font;

KorokGroup[] korokGroups;

void setup() {
    size(1200, 1000);
    frameRate(30);

    carte = loadImage("totk_map.jpg");
    carte.resize(1200, 1000);
    
    iconKorok = loadImage("korogu_simple.png");
    iconKorokDouble = loadImage("korogu_double.png");
    iconKorokDouble.resize(9 * 4, 7 * 4);
    
    table = loadTable("korogus.csv");
    tableDoubles = loadTable("korogus_duos.csv");
    
    font = loadFont("Rockwell-16.vlw");
    textFont(font);
    textAlign(CENTER);
    
    int minX = -4000;
    int maxX = 4000;
    int minY = -4000;
    int maxY = 4000;
    
    int divisions = 10;
    
    KorokGroup[] korokGroups;
    
    for (TableRow row : table.rows()) {
       korokGroups
    }
}

void draw() {
    background(255);
    image(carte, 0, 0);

    smooth();
    fill(192, 0, 0);
    noStroke();

    image(carte, 0, 0);
    for (TableRow row : table.rows()) {
        drawIcon(row, iconKorok, baseKorokWidth, baseKorokHeight);
    }
    for (TableRow row : tableDoubles.rows()) {
        drawIcon(row, iconKorokDouble, baseKorokDoubleWidth, baseKorokDoubleHeight);
    }
}

void drawIcon(TableRow row, PImage icon, float baseWidth, float baseHeight) {
    float iconWidth = baseWidth;
    float iconHeight = baseHeight;
    float x = (row.getFloat(0) + 6000) / 10;
    float y = (row.getFloat(2) + 5000) / 10;
    
    if(mouseX > x - iconWidth / 2 &&
       mouseX < x + iconWidth / 2 &&
       mouseY > y - iconHeight/ 2 &&
       mouseY < y + iconHeight/ 2
    ) {
      iconHeight = iconHeight * 1.5;
      iconWidth = iconWidth * 1.5;
      fill(255);
      text((int)row.getFloat(0) + ", " + (int)row.getFloat(1) + ", " + (int)row.getFloat(2), x, y - iconHeight / 2 - 10);
    }
    
    x = x - iconWidth / 2;
    y = y - iconHeight / 2;
    image(icon, x, y, iconWidth, iconHeight);
}