Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Code Processing Dataglove Pierre,Feuille, Ciseaux :
- /* Librairie pour la réalisation 3D et la communication série */
- import peasy.*; // Librairie pour la fenêtre 3D
- import processing.serial.*; // Librairie pour la communication série avec l'ESP32
- /* VARIABLES */
- float d1p1;
- float d1p2;
- float d1p3;
- float d2p1;
- float d2p2;
- float d2p3;
- float d3p1;
- float d3p2;
- float d3p3;
- float d4p1;
- float d4p2;
- float d4p3;
- float d5p1;
- float d5p2;
- float d5p3;
- Serial myPort; // déclaration de la variable 'myPort' pour la communication série
- String data_transmise;
- int valeurs[]; //pour stocker les valeurs reçues
- float angle_1;
- float angle_2;
- float angle_3;
- float angle_4;
- float angle_5;
- PGraphics dessin;
- PeasyCam cam;
- int score = 0; //initilaisation du score
- void setup() {
- size(1000, 1000, P3D); // Définir la taille de la fenêtre, P3D (traitement 3D): rendu graphique 3D
- myPort = new Serial (this, "/dev/cu.Dataglove-ESP32SPP", 115200); // Config du port COM de l'ESP32
- myPort.bufferUntil ( '\n' ); // Reception des données via ce port COM
- dessin = createGraphics(1000, 700, P3D); // création d'un objet PGraphics
- cam = new PeasyCam(this, dessin, 1500); // permet de créer un objet caméra pour pouvoir faire tourner l'objet PGraphics
- cam.reset(); // permet de remettre la camera aux parametres de départ
- }
- void serialEvent (Serial myPort) {
- data_transmise = myPort.readStringUntil ( '\n' ) ; // récupération de la chaine du port COM
- if (data_transmise != null) { //vérification de la trame
- data_transmise = trim(data_transmise);
- valeurs = int(split(data_transmise, ','));
- for (int i = 0; i < 5; i++) {
- print(valeurs[i] + ","); //affichage dans la console des valeurs reçues
- }
- angle_1= valeurs[0];
- angle_2= valeurs[1];
- angle_3= valeurs[2];
- angle_4= valeurs[3];
- angle_5= valeurs[4];
- println(); // retour à la ligne dans la console :
- }
- }
- /* Fonction permettant d'afficher du contenu dans la fenêtre */
- void draw() {
- background(200); // couleur de fond
- float fingerThumbMin = 2800; // extremums des valeurs des flexomètres
- float fingerIndexMin = 1200;
- float fingerMiddleMin = 1550;
- float fingerRingMin = 1400;
- float fingerLittleMin = 2700;
- float fingerThumbMax = 3200;
- float fingerIndexMax = 2900;
- float fingerMiddleMax = 2800;
- float fingerRingMax = 2600;
- float fingerLittleMax = 3400;
- float angleThumb = map(angle_1, fingerThumbMin, fingerThumbMax, PI/4, 0); //map pour transformer des valeurs numériques en angles (rad)
- float angleIndex = map(angle_2, fingerIndexMin, fingerIndexMax, PI/4, 0);
- float angleMiddle = map(angle_3, fingerMiddleMin, fingerMiddleMax, PI/4, 0);
- float angleRing = map(angle_4, fingerRingMin, fingerRingMax, PI/4, 0);
- float angleLittle = map(angle_5, fingerLittleMin, fingerLittleMax, PI/4, 0);
- d1p1=4*(angleMiddle)-2.7468; // Majeur
- d1p2=3*(angleMiddle)-1.6613;
- d1p3=2*(angleMiddle)-1.0813;
- d2p1=4*(angleRing)-2.7468; //Annulaire
- d2p2=3*(angleRing)-1.6613;
- d2p3=2*(angleRing)-1.0813;
- d3p1=4*(angleIndex)-2.7468; //Index
- d3p2=3*(angleIndex)-1.6613;
- d3p3=2*(angleIndex)-1.0813;
- d4p1=4*(angleLittle)-2.7468; //Auriculaire
- d4p2=3*(angleLittle)-1.6613;
- d4p3=2*(angleLittle)-1.0813;
- d5p1=4*(angleThumb)-2.7468; //Pouce
- d5p2=2*(angleThumb)-1.6613;
- /* appel de la fonction pour créer et dessiner la main */
- graphMain( d1p1, d1p2, d1p3, d2p1, d2p2, d2p3, d3p1, d3p2, d3p3, d4p1, d4p2, d4p3, d5p1, d5p2);
- image(dessin, 100, 100); // affichage de la main en 3D
- /*
- affichage de la valeur des 5 capteurs en dessous de la main
- */
- textSize(16); // taille du texte
- text("Pouce: ", 20, 650);
- text(angleThumb, 120, 650);
- text("Index : ", 300, 650);
- text(angleIndex, 400, 650);
- text("Majeur : ", 600, 650);
- text(angleMiddle, 700, 650);
- text("Annulaire : ", 20, 700);
- text(angleRing, 120, 700);
- text("Auriculaire : ", 300, 700);
- text(angleLittle, 400, 700);
- fill(0, 102, 153);
- //-------------------Rock,Paper,Scisors---------------------------
- int coup = -1;
- if (angleThumb<PI/16 && angleIndex<PI/16 && angleMiddle<PI/16 && angleRing<PI/16 && angleLittle<PI/16 ) //pierre
- {
- textSize(35); // taille du texte
- text("Pierre! ", 20, 780);
- coup=0;
- }
- if (angleThumb>PI/8 && angleIndex>PI/8 && angleMiddle>PI/8 && angleRing>PI/8 && angleLittle>PI/8 ) //feuille
- {
- textSize(35); // taille du texte
- text("Feuille! ", 20, 780);
- coup=1;
- }
- if (angleThumb<PI/8 && angleIndex>PI/8 && angleMiddle>PI/8 && angleRing<PI/8 && angleLittle<PI/8 ) //ciseaux
- {
- textSize(35); // taille du texte
- text("Ciseaux! ", 20, 780);
- coup=2;
- }
- if (angleThumb<PI/16 && angleIndex<PI/16 && angleMiddle>PI/8 && angleRing<PI/16 && angleLittle<PI/16 ) //...(._.)
- {
- textSize(35); // taille du texte
- text(" (ʘ‿ʘ) ╭∩╮ ", 20, 780);
- }
- if (mousePressed) // Si on clique sur la fenêtre :
- {
- int random=int(random(0, 2.99)); //l'ordinateur choisit
- textSize(35); // taille du texte
- text("Ordinateur : ", 200, 780);
- if(random == coup) //si égalité
- {
- textSize(35);
- text("Pareil : Égalité",460,780);
- }
- if(random == 0 && coup == 1) // comparaison entre l'ordinateur et notre mouvement
- {
- textSize(35);
- text("Pierre : Gagné",460,780);
- score++;
- }
- if(random == 0 && coup == 2)
- {
- textSize(35);
- text("Pierre : Perdu",460,780);
- score--;
- }
- if(random == 1 && coup == 0)
- {
- textSize(35);
- text("Feuille : Perdu",460,780);
- score--;
- }
- if(random == 1 && coup == 2)
- {
- textSize(35);
- text("Feuille : Gagné",460,780);
- score++;
- }
- if(random == 2 && coup == 0)
- {
- textSize(35);
- text("Ciseaux : Gagné",460,780);
- score++;
- }
- if(random == 2 && coup == 1)
- {
- textSize(35);
- text("Ciseaux : Perdu",460,780);
- score--;
- }
- }
- textSize(16);
- text("Score : ",900,780);
- text(score,970,780);
- }
- /* Fonction graphMain permettant de dessiner la main en fonction des valeurs d'angles */
- void graphMain(float d1p1, float d1p2, float d1p3, float d2p1, float d2p2, float d2p3, float d3p1, float d3p2, float d3p3, float d4p1, float d4p2, float d4p3, float d5p1, float d5p2 )
- {
- dessin.beginDraw();
- dessin.background(200); // couleur de fond
- dessin.stroke(224, 144, 90); // couleur des arêtes l'objet
- //dessin.fill(234, 154, 100); // couleur de l'objet
- // Majeur
- dessin.pushMatrix(); // cette fonction permet d'enregistrer les coordonnées actuel
- dessin.rotateX(d1p1); // rotation de la 1er phalange
- /* creation de la premiere partie du doigt */
- for (int i=0; i<25; i++) {
- dessin.sphere(45);
- dessin.translate(0, 10);
- }
- dessin.rotateX(d1p2); // rotation de la 2eme phalange
- /* creation de la deuxieme partie du doigt */
- for (int i=0; i<15; i++) {
- dessin.sphere(45);
- dessin.translate(0, 10);
- }
- dessin.rotateX(d1p3);// rotation de la 3eme phalange
- /* creation de la 3eme partie du doigt */
- for (int i=0; i<7; i++) {
- dessin.sphere(45);
- dessin.translate(0, 10);
- }
- //Annulaire
- dessin.popMatrix(); // permet de restaurer les coordonnées antérieures
- dessin.pushMatrix();
- dessin.rotateX(d2p1);
- dessin.translate(100, 0 );
- for (int i=0; i<20; i++) {
- dessin.sphere(45);
- dessin.translate(0, 10);
- }
- dessin.rotateX(d2p2);
- for (int i=0; i<10; i++) {
- dessin.sphere(45);
- dessin.translate(0, 10);
- }
- dessin.rotateX(d2p3);
- for (int i=0; i<5; i++) {
- dessin.sphere(45);
- dessin.translate(0, 10);
- }
- //Index
- dessin.popMatrix();
- dessin.pushMatrix();
- dessin.rotateX(d3p1);
- dessin.translate(-100, 0);
- for (int i=0; i<20; i++) {
- dessin.sphere(45);
- dessin.translate(0, 10);
- }
- dessin.rotateX(d3p2);
- for (int i=0; i<10; i++) {
- dessin.sphere(45);
- dessin.translate(0, 10);
- }
- dessin.rotateX(d3p3);
- for (int i=0; i<5; i++) {
- dessin.sphere(45);
- dessin.translate(0, 10);
- }
- //Auriculaire
- dessin.popMatrix();
- dessin.pushMatrix();
- dessin.rotateX(d4p1);
- dessin.translate(200, 0);
- for (int i=0; i<15; i++) {
- dessin.sphere(45);
- dessin.translate(0, 10);
- }
- dessin.rotateX(d4p2);
- for (int i=0; i<10; i++) {
- dessin.sphere(45);
- dessin.translate(0, 10);
- }
- dessin.rotateX(d4p3);
- for (int i=0; i<3; i++) {
- dessin.sphere(45);
- dessin.translate(0, 10);
- }
- // Pouce
- dessin.popMatrix();
- dessin.translate(-200, 0, 200);
- dessin.pushMatrix();
- dessin.rotateZ((PI/3)-d5p1);
- dessin.rotateX(-d5p1/6);
- for (int i=0; i<15; i++) {
- dessin.sphere(45);
- dessin.translate(0, 10);
- }
- dessin.rotateZ(-d5p2);
- for (int i=0; i<5; i++) {
- dessin.sphere(45);
- dessin.translate(0, 10);
- }
- dessin.popMatrix();
- dessin.endDraw();
- } // fin de la fonction graphMain
Advertisement
Add Comment
Please, Sign In to add comment