« Utilisateur:Adrien » : différence entre les versions
Aller à la navigation
Aller à la recherche
(→Code) |
(→Code) |
||
| Ligne 21 : | Ligne 21 : | ||
====Code==== | ====Code==== | ||
Embryon de code pour une sous-grille (il suffit de la dupliquer et de l'adapter à d'autres lettres) | |||
<pre> | <pre> | ||
Cell[][] grille; //tableau d'objets tri-dimensionnel | Cell[][] grille; //tableau d'objets tri-dimensionnel | ||
/*int nb=3;*/ | |||
int cols=5; | int cols=5; | ||
int rows=5; | int rows=5; | ||
int larg=854; | int larg=854; | ||
int haut=480; | int haut=480; | ||
boolean[] motif={true,true,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,true,true}; | |||
boolean[] motif | |||
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[] 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[] motifP={true,true,true,true,true,true,false,false,false,true,true,true,true,true,true,true,false,false,false,false,true,false,false,false,false}; | |||
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}; | 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 | int n; | ||
char c; | |||
//setup | |||
void setup() { | void setup() { | ||
size(larg,haut); | size(larg,haut); | ||
grille = new Cell[cols][rows]; | 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,15,15); | |||
} | } | ||
} | |||
} | } | ||
void draw() { | void draw() { | ||
background(0); //fond noir | background(0); //fond noir | ||
n=0; | |||
for (int i = 0; i < cols; i++) { | |||
for (int j = 0; j < rows; j++) { | |||
if (motif[n]==true) { | |||
grille[j][i].allumer(); | |||
} | } | ||
else { | |||
grille[j][i].eteindre(); | |||
} | |||
n++; | |||
} | } | ||
} | |||
} | } | ||
//classe des cellules | |||
class Cell { | |||
float x,y; | float x,y; | ||
float w,h; | float w,h; | ||
| Ligne 81 : | Ligne 77 : | ||
void allumer() { | void allumer() { | ||
stroke (0); //contour noir | stroke (0); //contour noir | ||
fill (255); // | fill (255); //interieur blanc | ||
rect(x,y,w,h); //dessine les cellules | rect(x,y,w,h); //dessine les cellules | ||
} | } | ||
| Ligne 92 : | Ligne 88 : | ||
} | } | ||
/ | //fonction de mise a jour | ||
void keyPressed() { | |||
switch (key) { | |||
case 'e': arrayCopy(motifE,motif); | |||
break; | |||
case 'p': arrayCopy(motifP,motif); | |||
break; | |||
case 'x': arrayCopy(motifX,motif); | |||
break; | |||
} | } | ||
} | |||
} | |||
</pre> | </pre> | ||
Version du 14 novembre 2010 à 20:33
Le projet au --Adrien 13 novembre 2010 à 12:53 (UTC)
Projet Lausanne 2011
But du jeu
Algorithme
Pseudo-code
Grille
- initialiser la grille (11x5x5 objets-cellules)
- charger un mot, le décomposer en caractères
- 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)
- copier le motif dans chaque sous-grille
- parcourir chaque sous grille: pour chaque cellule reconnue, attribuer une valeur (i.e. 'true') et incrémenter indice d'usure
- 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
- charger un texte depuis un fichier externe
- afficher, faire défiler
- biffer (comment?)
- pour tout mot biffé: lorsque ce mot est sorti du champ, le comparer au lexique
- afficher le mot le plus similaire dans la grille
Code
Embryon de code pour une sous-grille (il suffit de la dupliquer et de l'adapter à d'autres lettres)
Cell[][] grille; //tableau d'objets tri-dimensionnel
/*int nb=3;*/
int cols=5;
int rows=5;
int larg=854;
int haut=480;
boolean[] motif={true,true,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,true,true};
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[] motifP={true,true,true,true,true,true,false,false,false,true,true,true,true,true,true,true,false,false,false,false,true,false,false,false,false};
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;
char c;
//setup
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,15,15);
}
}
}
void draw() {
background(0); //fond noir
n=0;
for (int i = 0; i < cols; i++) {
for (int j = 0; j < rows; j++) {
if (motif[n]==true) {
grille[j][i].allumer();
}
else {
grille[j][i].eteindre();
}
n++;
}
}
}
//classe des cellules
class Cell {
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); //interieur blanc
rect(x,y,w,h); //dessine les cellules
}
void eteindre() {
stroke (0);
fill (0);
rect(x,y,w,h);
}
}
//fonction de mise a jour
void keyPressed() {
switch (key) {
case 'e': arrayCopy(motifE,motif);
break;
case 'p': arrayCopy(motifP,motif);
break;
case 'x': arrayCopy(motifX,motif);
break;
}
}
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);
}
}
