parent
7c5a02e226
commit
45015eda75
@ -0,0 +1 @@
|
||||
data/scoreboard.csv
|
||||
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
|
@ -0,0 +1,53 @@
|
||||
class Equipe {
|
||||
int id, score, radius;
|
||||
float pos_x, pos_y;
|
||||
String membres;
|
||||
color couleur;
|
||||
Pion pion;
|
||||
|
||||
Equipe(int id) {
|
||||
this.id = id;
|
||||
this.score = 0;
|
||||
//float randomHue = random(255);
|
||||
//float randomSaturation = random(100,255);
|
||||
//float randomBrightness = random(80,255);
|
||||
//color inverseText = color(float(255)-randomHue, float(255)-randomSaturation, float(255)-randomBrightness);
|
||||
//this.couleur = color(randomHue, randomSaturation, randomBrightness);
|
||||
//this.pion = new Pion(this.id, this.couleur, inverseText);
|
||||
|
||||
// générer un pion pour l'équipe
|
||||
this.pion = new Pion(this.id);
|
||||
|
||||
// récupérer les valeurs de positionnement initial du pion
|
||||
this.pos_x = this.pion.posX;
|
||||
this.pos_y = this.pion.posY;
|
||||
this.radius = this.pion.radius;
|
||||
|
||||
// afficher l'emplacement de l'équipe avant le pion
|
||||
this.update();
|
||||
}
|
||||
|
||||
void update() {
|
||||
// affichage de l'emplacement d'équipe, qui restera toujours fixe
|
||||
color bgColor = color(235, 112, 71, 0.8);
|
||||
color textColor = color(200);
|
||||
fill(bgColor);
|
||||
stroke(bgColor);
|
||||
strokeWeight(0.5);
|
||||
circle(this.pos_x,this.pos_y,radius);
|
||||
|
||||
fill(textColor);
|
||||
float textSize = this.radius/4*3;
|
||||
textSize(textSize);
|
||||
float pos_x = this.id<9? this.pos_x-radius/5: this.pos_x-radius/3;
|
||||
text(this.id+1, pos_x, this.pos_y+radius/5);
|
||||
|
||||
// mise à jour du pion
|
||||
this.pion.draw();
|
||||
}
|
||||
|
||||
void setScore(int score) {
|
||||
this.score = score;
|
||||
println("Equipe", this.id+1, "setScore", score);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,63 @@
|
||||
class Pion {
|
||||
int id;
|
||||
float posX, posY; // position
|
||||
color bgColor, textColor; // couleur du fond et du texte
|
||||
boolean hovered, dragged = false; // état au survol et en déplacement
|
||||
int radius = 30; // rayon du pion
|
||||
int margin = 45; // marge au bord de l'écran
|
||||
PVector offset;
|
||||
|
||||
Pion(int id) {
|
||||
this.id = id;
|
||||
this.bgColor = color(235, 112, 71, 0.8);
|
||||
this.textColor = color(200);
|
||||
this.posX = floor((displayWidth-margin*2)/nombreEquipes)*id+radius+margin;
|
||||
this.posY = displayHeight-24;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
color bgColor = this.getBgColor();
|
||||
color textColor = this.getTextColor();
|
||||
|
||||
stroke(bgColor);
|
||||
strokeWeight(0.5);
|
||||
fill(bgColor);
|
||||
float radius = this.radius;
|
||||
circle(this.posX,this.posY,radius);
|
||||
|
||||
fill(textColor);
|
||||
float textSize = radius/3*2;
|
||||
textSize(textSize);
|
||||
textFont(quicksandFont, textSize);
|
||||
|
||||
float pos_x = this.id<9? this.posX-radius/5: this.posX-radius/3;
|
||||
text(this.id+1, pos_x, this.posY+radius/5+1);
|
||||
}
|
||||
|
||||
color getBgColor() {
|
||||
return this.dragged? color(177, 255, 51): this.hovered? this.textColor: this.bgColor;
|
||||
}
|
||||
|
||||
color getTextColor() {
|
||||
return this.dragged? color(0): this.hovered? this.bgColor: this.textColor;
|
||||
}
|
||||
|
||||
void dragStart() {
|
||||
this.dragged = true;
|
||||
// calcul et stockage du décalage au curseur pour éviter l'effet snap
|
||||
this.offset = new PVector(posX-mouseX, posY-mouseY);
|
||||
}
|
||||
|
||||
void dragStop() {
|
||||
this.dragged = false;
|
||||
this.offset = new PVector(0,0);
|
||||
}
|
||||
|
||||
void hoverStart() {
|
||||
this.hovered = true;
|
||||
}
|
||||
|
||||
void hoverStop() {
|
||||
this.hovered = false;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,247 @@
|
||||
PImage backgroundImage;
|
||||
Equipe[] equipes;
|
||||
Position[] positions;
|
||||
int nombreEquipes = 42;
|
||||
PFont quicksandFont;
|
||||
boolean EDITING;
|
||||
|
||||
Table table_Cercles, positionTable, scoreboard;
|
||||
float[] coord_x;
|
||||
float[] coord_y;
|
||||
int[] coord_rayon;
|
||||
|
||||
void setup() {
|
||||
|
||||
size(displayWidth, displayHeight);
|
||||
fullScreen(1);
|
||||
//randomSeed(3);
|
||||
//frameRate(60);
|
||||
colorMode(RGB, 255);
|
||||
rectMode(CENTER);
|
||||
noStroke();
|
||||
EDITING=false;
|
||||
|
||||
table_Cercles = loadTable("data/positionTable.csv", "header");
|
||||
quicksandFont = loadFont("Quicksand-Bold-40.vlw");
|
||||
|
||||
backgroundImage = loadImage("backgroundImage.jpg");
|
||||
image(backgroundImage, 0, 0, displayWidth, displayHeight);
|
||||
|
||||
equipes = new Equipe[nombreEquipes];
|
||||
for (int i=0; i<equipes.length; i++) {
|
||||
equipes[i] = new Equipe(i);
|
||||
}
|
||||
|
||||
positions = new Position[table_Cercles.getRowCount()];
|
||||
for (int i=0; i<table_Cercles.getRowCount(); i++) {
|
||||
positions[i] = new Position(table_Cercles.getInt(i, "id"));
|
||||
positions[i].radius = (i==0 || i==table_Cercles.getRowCount()-1)? 145: 60;
|
||||
positions[i].posX = table_Cercles.getFloat(i, "posx");
|
||||
positions[i].posY = table_Cercles.getFloat(i, "posy");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void mouseMoved() {
|
||||
// pour chaque équipe
|
||||
for (int i = 0 ; i < equipes.length; i++) {
|
||||
Equipe e = equipes[i];
|
||||
Pion p = e.pion;
|
||||
|
||||
// calcul de distance entre la souris et le pion
|
||||
float distPion = dist(p.posX, p.posY, mouseX, mouseY);
|
||||
// calcul de distance entre la souris et l'emplacement d'équipe
|
||||
float distEquipe = dist(e.pos_x, e.pos_y, mouseX, mouseY);
|
||||
// seuil de collision
|
||||
float threshold = p.radius/2;
|
||||
|
||||
// si la souris est au delà du seuil de collision et que le pion est dans un état actif
|
||||
if (distPion>threshold && distEquipe>threshold && (p.hovered || p.dragged)) {
|
||||
// cloture des deux états
|
||||
p.dragStop();
|
||||
p.hoverStop();
|
||||
break;
|
||||
|
||||
// si la souris est sous le seuil de collision du pion et qu'il n'est pas déjà dans l'état survolé
|
||||
} else if ((distPion<=threshold || distEquipe<=threshold) && !p.hovered) {
|
||||
// activation de l'état survolé
|
||||
p.hoverStart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (EDITING) {
|
||||
for (int i = 0 ; i < positions.length; i++) {
|
||||
Position p = positions[i];
|
||||
float distPosition = dist(p.posX, p.posY, mouseX, mouseY);
|
||||
float threshold = p.radius/2;
|
||||
|
||||
if (distPosition>threshold && (p.hovered || p.dragged)) {
|
||||
p.dragStop();
|
||||
p.hoverStop();
|
||||
break;
|
||||
} else if (distPosition<=threshold && !p.hovered) {
|
||||
p.hoverStart();
|
||||
//println(p.posX, p.posY);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mousePressed() {
|
||||
for (int i = 0 ; i < equipes.length; i++) {
|
||||
Pion p = equipes[i].pion;
|
||||
float d = dist(p.posX, p.posY, mouseX, mouseY);
|
||||
if (d<p.radius/2) {
|
||||
//println(p.id+1);
|
||||
p.dragStart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (EDITING) {
|
||||
for (int i = 0 ; i < positions.length; i++) {
|
||||
Position p = positions[i];
|
||||
float d = dist(p.posX, p.posY, mouseX, mouseY);
|
||||
if (d<p.radius/2) {
|
||||
//println(p.id+1);
|
||||
p.dragStart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mouseDragged() {
|
||||
for (int i = 0 ; i < equipes.length; i++) {
|
||||
Pion p = equipes[i].pion;
|
||||
if (p.dragged) {
|
||||
p.posX = mouseX+p.offset.x;
|
||||
p.posY = mouseY+p.offset.y;
|
||||
// cloture de la boucle for, pour ne pas cibler plusieurs pions si c'était possible
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (EDITING) {
|
||||
for (int i = 0 ; i < positions.length; i++) {
|
||||
Position p = positions[i];
|
||||
if (p.dragged) {
|
||||
p.posX = mouseX+p.offset.x;
|
||||
p.posY = mouseY+p.offset.y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mouseReleased() {
|
||||
for (int i = 0 ; i < equipes.length; i++) {
|
||||
Pion p = equipes[i].pion;
|
||||
if (p.dragged) {
|
||||
p.dragStop();
|
||||
equipes[i].setScore(findClosestPositionFrom(p).getScore());
|
||||
saveScoreboard();
|
||||
}
|
||||
}
|
||||
|
||||
if (EDITING) {
|
||||
for (int i = 0 ; i < positions.length; i++) {
|
||||
Position p = positions[i];
|
||||
if (p.dragged) {
|
||||
p.dragStop();
|
||||
savePositionTable();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mouseWheel(MouseEvent event) {
|
||||
// pour chaque équipe
|
||||
for (int i = 0 ; i < equipes.length; i++) {
|
||||
Equipe e = equipes[i];
|
||||
Pion p = e.pion;
|
||||
|
||||
// calcul de distance entre la souris et l'emplacement d'équipe
|
||||
float distEquipe = dist(e.pos_x, e.pos_y, mouseX, mouseY);
|
||||
// seuil de collision
|
||||
float threshold = p.radius/2;
|
||||
// nouveau rayon
|
||||
int radius = p.radius + event.getCount()*-5;
|
||||
|
||||
// si la souris est sous le seuil de collision
|
||||
if (distEquipe<=threshold && radius>20 && radius<120) {
|
||||
p.radius = radius;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void savePositionTable() {
|
||||
positionTable = new Table();
|
||||
|
||||
positionTable.addColumn("id");
|
||||
positionTable.addColumn("posx");
|
||||
positionTable.addColumn("posy");
|
||||
|
||||
for (int i = 0 ; i < positions.length; i++) {
|
||||
Position p = positions[i];
|
||||
TableRow position = positionTable.addRow();
|
||||
|
||||
position.setInt("id", p.id);
|
||||
position.setFloat("posx", p.posX);
|
||||
position.setFloat("posy", p.posY);
|
||||
}
|
||||
|
||||
saveTable(positionTable, "data/positionTable.csv", "csv");
|
||||
|
||||
}
|
||||
|
||||
void saveScoreboard() {
|
||||
scoreboard = new Table();
|
||||
|
||||
scoreboard.addColumn("equipe");
|
||||
scoreboard.addColumn("score");
|
||||
|
||||
for (int i = 0 ; i < equipes.length; i++) {
|
||||
Equipe e = equipes[i];
|
||||
TableRow scoreEquipe = scoreboard.addRow();
|
||||
|
||||
scoreEquipe.setInt("equipe", e.id+1);
|
||||
scoreEquipe.setInt("score", e.score);
|
||||
}
|
||||
|
||||
saveTable(scoreboard, "data/scoreboard.csv", "csv");
|
||||
}
|
||||
|
||||
Position findClosestPositionFrom(Pion pion) {
|
||||
|
||||
Position closest = positions[0];
|
||||
|
||||
for (int i = 0 ; i < positions.length; i++) {
|
||||
Position position = positions[i];
|
||||
|
||||
float distPion = dist(pion.posX, pion.posY, position.posX, position.posY);
|
||||
float distClosest = dist(pion.posX, pion.posY, closest.posX, closest.posY);
|
||||
|
||||
if (distPion<=distClosest) closest = positions[i];
|
||||
}
|
||||
|
||||
return closest;
|
||||
}
|
||||
|
||||
void draw() {
|
||||
image(backgroundImage, 0, 0, displayWidth, displayHeight);
|
||||
for (int i = 0 ; i < equipes.length; i++) {
|
||||
equipes[i].update();
|
||||
}
|
||||
|
||||
if (EDITING) {
|
||||
for (int i = 0 ; i < positions.length; i++) {
|
||||
positions[i].draw();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,192 +0,0 @@
|
||||
PImage backgroundImage;
|
||||
Equipe[] equipes;
|
||||
int nombreEquipes = 50;
|
||||
|
||||
void setup() {
|
||||
|
||||
size(displayWidth, displayHeight);
|
||||
fullScreen(1);
|
||||
randomSeed(3);
|
||||
frameRate(30);
|
||||
colorMode(HSB, 255);
|
||||
rectMode(CENTER);
|
||||
noStroke();
|
||||
|
||||
backgroundImage = loadImage("backgroundImage.jpg");
|
||||
image(backgroundImage, 0, 0, displayWidth, displayHeight);
|
||||
|
||||
equipes = new Equipe[nombreEquipes];
|
||||
for (int i = 0 ; i < equipes.length; i++) {
|
||||
equipes[i] = new Equipe(i);
|
||||
}
|
||||
}
|
||||
|
||||
class Equipe {
|
||||
int id, score, pos_x, pos_y, radius;
|
||||
String membres;
|
||||
color couleur;
|
||||
Pion pion;
|
||||
|
||||
Equipe(int id) {
|
||||
this.id = id;
|
||||
this.score = 0;
|
||||
//float randomHue = random(255);
|
||||
//float randomSaturation = random(100,255);
|
||||
//float randomBrightness = random(80,255);
|
||||
//color inverseText = color(float(255)-randomHue, float(255)-randomSaturation, float(255)-randomBrightness);
|
||||
//this.couleur = color(randomHue, randomSaturation, randomBrightness);
|
||||
//this.pion = new Pion(this.id, this.couleur, inverseText);
|
||||
|
||||
// générer un pion pour l'équipe
|
||||
this.pion = new Pion(this.id, color(0), color(255));
|
||||
|
||||
// récupérer les valeurs de positionnement initial du pion
|
||||
this.pos_x = this.pion.pos_x;
|
||||
this.pos_y = this.pion.pos_y;
|
||||
this.radius = this.pion.radius;
|
||||
|
||||
// afficher l'emplacement de l'équipe avant le pion
|
||||
this.update();
|
||||
}
|
||||
|
||||
void update() {
|
||||
color bgColor = color(100, 100, 200);
|
||||
color textColor = color(200, 100, 200);
|
||||
fill(bgColor);
|
||||
float radius = this.radius;
|
||||
circle(this.pos_x,this.pos_y,radius);
|
||||
fill(textColor);
|
||||
float textSize = this.radius/4*3;
|
||||
textSize(textSize);
|
||||
float pos_x = this.id<9? this.pos_x-radius/5: this.pos_x-radius/3;
|
||||
text(this.id+1, pos_x, this.pos_y+radius/5);
|
||||
|
||||
this.pion.update();
|
||||
}
|
||||
}
|
||||
|
||||
class Pion {
|
||||
int id, pos_x, pos_y, radius;
|
||||
color fond, texte;
|
||||
boolean hovered, dragged;
|
||||
|
||||
Pion(int id, color fond, color texte) {
|
||||
this.id = id;
|
||||
this.fond = fond;
|
||||
this.texte = texte;
|
||||
this.radius = 30;
|
||||
this.pos_x = floor(displayWidth/nombreEquipes)*id+radius;
|
||||
this.pos_y = 30;
|
||||
this.hovered = false;
|
||||
this.dragged = false;
|
||||
}
|
||||
|
||||
void update() {
|
||||
color bgColor = this.dragged? color(40, 250, 250): this.hovered? this.texte: this.fond;
|
||||
color textColor = this.dragged? color(210, 10, 10): this.hovered? this.fond: this.texte;
|
||||
|
||||
stroke(bgColor);
|
||||
strokeWeight(0.5);
|
||||
fill(bgColor);
|
||||
float radius = this.radius; //this.dragged? this.radius*1.4: this.hovered? this.radius*1.2: this.radius;
|
||||
circle(this.pos_x,this.pos_y,radius);
|
||||
|
||||
fill(textColor);
|
||||
float textSize = this.radius/4*3; //this.dragged? this.radius*0.75: this.hovered? this.radius*0.75: this.radius*0.75;
|
||||
textSize(textSize);
|
||||
|
||||
float pos_x = this.id<9? this.pos_x-radius/5: this.pos_x-radius/3;
|
||||
text(this.id+1, pos_x, this.pos_y+radius/5);
|
||||
}
|
||||
|
||||
void dragStart() {
|
||||
this.dragged = true;
|
||||
}
|
||||
|
||||
void dragStop() {
|
||||
this.dragged = false;
|
||||
}
|
||||
|
||||
void hoverStart() {
|
||||
this.hovered = true;
|
||||
}
|
||||
|
||||
void hoverStop() {
|
||||
this.hovered = false;
|
||||
}
|
||||
}
|
||||
|
||||
void mouseDragged() {
|
||||
for (int i = 0 ; i < equipes.length; i++) {
|
||||
Pion p = equipes[i].pion;
|
||||
if (p.dragged) {
|
||||
p.pos_x = mouseX;
|
||||
p.pos_y = mouseY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mouseMoved() {
|
||||
for (int i = 0 ; i < equipes.length; i++) {
|
||||
Equipe e = equipes[i];
|
||||
Pion p = e.pion;
|
||||
|
||||
float distPion = dist(p.pos_x, p.pos_y, mouseX, mouseY);
|
||||
float distEquipe = dist(e.pos_x, e.pos_y, mouseX, mouseY);
|
||||
float threshold = p.radius/2;
|
||||
|
||||
if (distPion>threshold && distEquipe>threshold && (p.hovered || p.dragged)) {
|
||||
p.dragStop();
|
||||
p.hoverStop();
|
||||
} else if (distPion<=threshold && !p.hovered) {
|
||||
println(p.id+1);
|
||||
p.hoverStart();
|
||||
} else if (distEquipe<=threshold && !p.dragged) {
|
||||
println(p.id+1);
|
||||
p.dragStart();
|
||||
}
|
||||
|
||||
//if (distPion<p.radius/2 && !p.hovered) {
|
||||
// println(p.id+1);
|
||||
// p.hoverStart();
|
||||
//} else if(distPion>=p.radius/2 && p.hovered) {
|
||||
// p.hoverStop();
|
||||
//} else if(distEquipe<e.radius/2 && !p.hovered) {
|
||||
// println(p.id+1);
|
||||
// p.dragStart();
|
||||
//} else if(distEquipe>=e.radius/2 && p.hovered) {
|
||||
// p.dragStop();
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
void mousePressed() {
|
||||
//println(mouseX, mouseY);
|
||||
for (int i = 0 ; i < equipes.length; i++) {
|
||||
Pion p = equipes[i].pion;
|
||||
float d = dist(p.pos_x, p.pos_y, mouseX, mouseY);
|
||||
if (d<p.radius/2) {
|
||||
println(p.id+1);
|
||||
p.dragStart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mouseReleased() {
|
||||
for (int i = 0 ; i < equipes.length; i++) {
|
||||
Pion p = equipes[i].pion;
|
||||
if (p.dragged) {
|
||||
p.dragStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
image(backgroundImage, 0, 0, displayWidth, displayHeight);
|
||||
for (int i = 0 ; i < equipes.length; i++) {
|
||||
equipes[i].update();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,72 @@
|
||||
class Position {
|
||||
int id;
|
||||
float posX, posY; // position
|
||||
color bgColor, textColor; // couleur du fond et du texte
|
||||
boolean hovered, dragged = false; // état au survol et en déplacement
|
||||
int radius = 60; // rayon du pion
|
||||
PVector offset;
|
||||
|
||||
Position(int id) {
|
||||
this.id = id;
|
||||
this.bgColor = color(255);
|
||||
this.textColor = color(0);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
color bgColor = this.getBgColor();
|
||||
color textColor = this.getTextColor();
|
||||
|
||||
stroke(bgColor);
|
||||
strokeWeight(0.5);
|
||||
fill(bgColor);
|
||||
float radius = this.radius;
|
||||
circle(this.posX,this.posY,radius);
|
||||
|
||||
fill(textColor);
|
||||
float textSize = radius/3*2;
|
||||
textSize(textSize);
|
||||
textFont(quicksandFont, textSize);
|
||||
|
||||
float pos_x = this.id<9? this.posX-radius/5: this.posX-radius/3;
|
||||
text(this.id+1, pos_x, this.posY+radius/5+1);
|
||||
}
|
||||
|
||||
color getBgColor() {
|
||||
return this.dragged? color(177, 255, 51): this.hovered? this.textColor: this.bgColor;
|
||||
}
|
||||
|
||||
color getTextColor() {
|
||||
return this.dragged? color(0): this.hovered? this.bgColor: this.textColor;
|
||||
}
|
||||
|
||||
int getScore() {
|
||||
return this.id+1;
|
||||
}
|
||||
|
||||
void setBgColor(color bgColor) {
|
||||
this.bgColor = bgColor;
|
||||
}
|
||||
|
||||
void setTextColor(color textColor) {
|
||||
this.textColor = textColor;
|
||||
}
|
||||
|
||||
void dragStart() {
|
||||
this.dragged = true;
|
||||
// calcul et stockage du décalage au curseur pour éviter l'effet snap
|
||||
this.offset = new PVector(posX-mouseX, posY-mouseY);
|
||||
}
|
||||
|
||||
void dragStop() {
|
||||
this.dragged = false;
|
||||
this.offset = new PVector(0,0);
|
||||
}
|
||||
|
||||
void hoverStart() {
|
||||
this.hovered = true;
|
||||
}
|
||||
|
||||
void hoverStop() {
|
||||
this.hovered = false;
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 25 MiB After Width: | Height: | Size: 552 KiB |
Binary file not shown.
|
@ -0,0 +1 @@
|
||||
main=Plateau.pde
|
||||
Loading…
Reference in new issue