« Utilisateur:Adrien » : différence entre les versions

De Wikilipo
Aller à la navigation Aller à la recherche
Ligne 22 : Ligne 22 :
====Code====
====Code====
<pre>
<pre>
Cell[][][] grille; //tableau d'objets tri-dimensionnel (3x11x8)
Cell[][] grille; //tableau d'objets tri-dimensionnel (3x11x8)


int num=3;
int cols=5;
int cols=11;
int rows=5;
int rows=8;
int larg=854;
int w=854;
int haut=480;
int h=480;
//char c;
char c; //caractère saisi
boolean[] motif= new boolean[25];
int charge; //indice de couleur
boolean[] motifTemp={false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false};
boolean[] motifE={true,true,true,true,true,true,false,false,false,false,true,true,true,true,true,true,false,false,false,false,true,true,true,true,true};
boolean[] motifX={true,false,false,false,true,false,true,false,true,false,false,false,true,false,false,false,true,false,true,false,true,false,false,false,true};
int n=0;


void setup() {
void setup() {
   size(w,h);
   size(larg,haut);
   grille = new Cell[num][cols][rows];
   grille = new Cell[cols][rows];
  for (int h = 0; h < num; h++) { 
     for (int i = 0; i < cols; i++) {
     for (int i = 0; i < cols; i++) {
       for (int j = 0; j < rows; j++) {
       for (int j = 0; j < rows; j++) {
        // Initialize each object
        grille[i][j] = new Cell(i*20,j*20,20,20);
        grille[h][i][j] = new Cell(h*w/h+20,i*w/h+20,j*w/h+20,20/*,20,c*/);
       }
       }
     }
     }
  }
}
}


void draw() {
void draw() {
   background(0); //fond noir
   background(0); //fond noir
  /*for (int a = 0; a < motifTemp.length; a++) {
    motif[a]=motif[a]+motifTemp[a];
  }*/
   // The counter variables i and j are also the column and row numbers and  
   // The counter variables i and j are also the column and row numbers and  
   // are used as arguments to the constructor for each object in the grid.   
   // are used as arguments to the constructor for each object in the grid.   
  for (int h = 0; h < num; h++) {
     for (int i = 0; i < cols; i++) {
     for (int i = 0; i < cols; i++) {
       for (int j = 0; j < rows; j++) {
       for (int j = 0; j < rows; j++) {
         grille[h][i][j].afficher();
         if (motifX[n]==true) { /* GENERE UNE ERREUR DE SORTIE DE TABLEAU*/
          grille[i][j].allumer();       
          n++;
        }
        else {
          grille[i][j].eteindre();
          n++;
        }
       }
       }
     }
     }
  }
}
}


Ligne 70 : Ligne 78 :
   }  
   }  


  void afficher() {
void allumer() {
    stroke(0); //bordures noires
  stroke (0); //contour noir
    for (int a = 0; a<motif.length; a++) {
  fill (255); //intérieur blanc
      //?//
  rect(x,y,w,h); //dessine les cellules
      case 0:
        fill(0); //intérieur noir
        break;
      case 1:
        fill(211); //intérieur gris
        break;
      case 2:
        fill (255); //intérieur blanc
        break;
    }
    rect(x,y,w,h); //dessine les cellules
   }
   }
void eteindre() {
  stroke (0);
  fill (0);
  rect(x,y,w,h);
}
}
}


char caract(char c) { //FONCTION vérification de la saisie
/*char caract(char c) { //FONCTION vérification de la saisie
   if (keyPressed) {
   if (keyPressed) {
     c=key;
     c=key;
   }
   }
   return c;
   return c;
}
}*/
 
double[] motif(char c) { //FONCTION initialisation du motif de caractère
  switch (c) { //3x8cases -- à partir du 'o'
      case'a': motif[]={2.3,0.4,1.4,2.4,0.5,2.5,0.6,2.6,0.7,1.7,2.7};
      break;
      case'b': motif[]={0.0,0.1,0.2,0.3,0.4,1.4,2.4,0.5,2.5,0.6,2.6,0.7,1.7,2.7};
      break;
      case'c': motif[]={0.4,1.4,2.4,0.5,0.6,0.7,1.7,2.7};
      break;
      case'd': motif[]={2.0,2.1,2.2,2.3,0.4,1.4,2.4,0.5,2.5,0.6,2.6,0.7,1.7,2.7};
      break;
      case'e': motif[]={0.3,1.3,2.3,0.4,0.5,1.5,2.5,0.6,0.7,1.7,2.7};
      break;
      case'f': motif[]={0.0,1.0,2.0,0.1,0.2,0.3,1.3,0.4,1.4,2.4,0.5,0.6,0.7,1.7,2.7};
      break;
      case'g':
      break;
      case'h':
      break;
      case'i': motif[]={1.2,1.4,1.5,1.6,1.7};
      break;
      case'j': motif[]={1.2,1.4,1.5,1.6,1.7,1.8,1.9};
      break;
      case'k':
      break;
      case'l': motif[]={1.2,1.3,1.4,1.5,1.6,1.7};
      break;
      case'm': motif[]={0.4,1.4,2.4,0.5,1.5,2.5,0.6,2.6,0.7,2.7};
      break;
      case'n': motif[]={0.4,1.4,2.4,0.5,2.5,0.6,2.6,0.7,2.7};
      break;
      case'o': motif[]={0.4,1.4,2.4,0.5,2.5,0.6,2.6,0.7,1.7,2.7};
      break;
      case'p': motif[]={0.4,1.4,2.4,0.5,2.5,0.6,2.6,0.7,1.7,2.7,0.8,0.9,0.10};
      break;
      case'q': motif[]={0.4,1.4,2.4,0.5,2.5,0.6,2.6,0.7,1.7,2.7,2.8,2.9,2.10};
      break;
      case'r': motif[]={0.4,1.4,2.4,0.5,0.6,0.7};
      break;
      case's': motif[]={0.4,1.4,2.4,0.5,1.5,2.5,2.6,0.7,1.7,2.7};
      break;
      case't': motif[]={0.0,0.1,0.2,0.3,0.4,1.4,2.4,0.5,0.6,0.7,1.7,2.7};
      break;
      case'u': motif[]={0,.4,2.4,0.5,2.5,0.6,2.6,0.7,1.7,2.7};
      break;
      case'v': motif[]={0.4,2.4,0.5,2.5,0.6,2.6,1.7};
      break;
      case'w':
      break;
      case'x':
      break;
      case'y':
      break;
      case'z':
    }
  return motif;
}
</pre>
</pre>



Version du 14 novembre 2010 à 20:13

Le projet au --Adrien 13 novembre 2010 à 12:53 (UTC)

Projet Lausanne 2011

But du jeu

Scheme.jpg

Algorithme

Pseudo-code

Grille

  1. initialiser la grille (11x5x5 objets-cellules)
  2. charger un mot, le décomposer en caractères
  3. pour chaque caractère, sélectionner le motif correspondant (un motif est un tableau bi-dimensionnel 5x5 comportant les coordonnées (ensemble de paires ordonnées) de chaque cellule à illuminer)
  4. copier le motif dans chaque sous-grille
  5. parcourir chaque sous grille: pour chaque cellule reconnue, attribuer une valeur (i.e. 'true') et incrémenter indice d'usure
  6. parcourir la grille: pour chaque cellule 'true' ayant un indice d'usure inférieur à 11, afficher cette cellule en blanc; sinon, l'afficher en gris (rvb=211,211,211)

Ruban

  1. charger un texte depuis un fichier externe
  2. afficher, faire défiler
  3. biffer (comment?)
  4. pour tout mot biffé: lorsque ce mot est sorti du champ, le comparer au lexique
  5. afficher le mot le plus similaire dans la grille

Code

Cell[][] grille; //tableau d'objets tri-dimensionnel (3x11x8)

int cols=5;
int rows=5;
int larg=854;
int haut=480;
//char c;
boolean[] motif= new boolean[25];
boolean[] motifTemp={false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false};
boolean[] motifE={true,true,true,true,true,true,false,false,false,false,true,true,true,true,true,true,false,false,false,false,true,true,true,true,true};
boolean[] motifX={true,false,false,false,true,false,true,false,true,false,false,false,true,false,false,false,true,false,true,false,true,false,false,false,true};
int n=0;

void setup() {
  size(larg,haut);
  grille = new Cell[cols][rows];
    for (int i = 0; i < cols; i++) {
      for (int j = 0; j < rows; j++) {
         grille[i][j] = new Cell(i*20,j*20,20,20);
      }
    }
}

void draw() {
  background(0); //fond noir
  /*for (int a = 0; a < motifTemp.length; a++) {
    motif[a]=motif[a]+motifTemp[a];
  }*/
  // The counter variables i and j are also the column and row numbers and 
  // are used as arguments to the constructor for each object in the grid.  
    for (int i = 0; i < cols; i++) {
      for (int j = 0; j < rows; j++) {
        if (motifX[n]==true) { /* GENERE UNE ERREUR DE SORTIE DE TABLEAU*/
          grille[i][j].allumer();         
          n++;
        }
        else {
          grille[i][j].eteindre();
          n++;
        }
      }
    }
}

class Cell { //classe des cellules
  float x,y;
  float w,h;
  
  Cell(float tempX, float tempY, float tempW, float tempH/*, int tempC*/) {
    x = tempX;
    y = tempY;
    w = tempW;
    h = tempH;
    /*c = tempC;*/
  } 

 void allumer() {
  stroke (0); //contour noir
  fill (255); //intérieur blanc
  rect(x,y,w,h); //dessine les cellules
  }

 void eteindre() {
  stroke (0);
  fill (0);
  rect(x,y,w,h);
 }
}

/*char caract(char c) { //FONCTION vérification de la saisie
  if (keyPressed) {
    c=key;
  }
  return c;
}*/

Exemples

Ruban
// An array of news headlines
String[] headlines = {
  "Processing downloads break downloading record.", 
  "New study shows computer programming lowers cholesterol.",
  };

PFont f;  // Global font variable
float x;  // horizontal location of headline
int index = 0;

void setup() {
  size(400,200);
  f = createFont("Arial",16,true);  
  // Initialize headline offscreen to the right 
  x = width; 
}

void draw() {
  background(255);
  fill(0);

  // Display headline at x  location
  textFont(f,16);        
  textAlign(LEFT);
  text(headlines[index],x,180); 

  // Decrement x
  x = x - 3;

  // If x is less than the negative width, 
  // then it is off the screen
  float w = textWidth(headlines[index]);
  if (x < -w) {
    x = width; 
    index = (index + 1) % headlines.length;
  }
}

Grille

// 2D Array of objects
Cell[][] grid;

// Number of columns and rows in the grid
int cols = 10;
int rows = 10;

void setup() {
  size(200,200);
  grid = new Cell[cols][rows];
  for (int i = 0; i < cols; i++) {
    for (int j = 0; j < rows; j++) {
      // Initialize each object
      grid[i][j] = new Cell(i*20,j*20,20,20,i+j);
    }
  }
}

void draw() {
  background(0);
  // The counter variables i and j are also the column and row numbers and 
  // are used as arguments to the constructor for each object in the grid.  
  for (int i = 0; i < cols; i++) {
    for (int j = 0; j < rows; j++) {
      // Oscillate and display each object
      grid[i][j].oscillate();
      grid[i][j].display();
    }
  }
}

// A Cell object
class Cell {
  // A cell object knows about its location in the grid as well as its size with the variables x,y,w,h.
  float x,y;   // x,y location
  float w,h;   // width and height
  float angle; // angle for oscillating brightness

  // Cell Constructor
  Cell(float tempX, float tempY, float tempW, float tempH, float tempAngle) {
    x = tempX;
    y = tempY;
    w = tempW;
    h = tempH;
    angle = tempAngle;
  } 
  
  // Oscillation means increase angle
  void oscillate() {
    angle += 0.02; 
  }

  void display() {
    stroke(255);
    // Color calculated using sine wave
    fill(127+127*sin(angle));
    rect(x,y,w,h); 
  }
}

Comparaison lexicale