» codelab : http://codelab.fr/accueil » Forum : Processing : http://codelab.fr/processing » random de vidéos : http://codelab.fr/3403 Ceci est la version imprimable d'un sujet du forum, pour retourner à la version complète : random de vidéos |
ArtMaggy — 2012-05-23 21:13:58 |
Bonjour, |
emoc — 2012-05-23 23:43:34 |
Bonjour et bienvenue, lien vers la page de la vidéo sur youtube |
emoc — 2012-05-24 00:22:47 |
Un petit exemple, finalement bien plus long que ce que j'avais imaginé avant de le faire... Code (processing) :boolean resultat_affiche; int resultat; int resultat_temp; int step; int next_step; int compteur; void setup() { size(500, 500); frameRate(25); initialiser(); } void draw() { if (step <= 0) { resultat_affiche = true; } if (resultat_affiche) { background(255, 0, 0); afficher_valeur(resultat); } else { background(0); if (step <= next_step) { next_step = next_step - compteur; resultat_temp = tirage_de(); } afficher_valeur(resultat_temp); step --; compteur ++; } } void initialiser() { resultat_affiche = false; step = 100; next_step = 99; compteur = 0; resultat = tirage_de(); } int tirage_de() { return floor(random(6) + 1); } void afficher_valeur(int chiffre) { fill(255); stroke(255); rect(50, 50, 400, 400); fill(0); ellipseMode(CENTER); switch(chiffre) { case 1 : ellipse(width / 2, height / 2, 40, 40); break; case 2 : ellipse(width / 3, 2 * height / 3, 40, 40); ellipse(2 * width / 3, height / 3, 40, 40); break; case 3 : ellipse(width / 3, 2 * height / 3, 40, 40); ellipse(width / 2, height / 2, 40, 40); ellipse(2 * width / 3, height / 3, 40, 40); break; case 4 : ellipse(width / 3, height / 3, 40, 40); ellipse(width / 3, 2 * height / 3, 40, 40); ellipse(2 * width / 3, height / 3, 40, 40); ellipse(2 * width / 3, 2 * height / 3, 40, 40); break; case 5 : ellipse(width / 3, height / 3, 40, 40); ellipse(width / 3, 2 * height / 3, 40, 40); ellipse(width / 2, height / 2, 40, 40); ellipse(2 * width / 3, height / 3, 40, 40); ellipse(2 * width / 3, 2 * height / 3, 40, 40); break; case 6 : ellipse(width / 3, height / 3, 40, 40); ellipse(width / 2, height / 3, 40, 40); ellipse(width / 3, 2 * height / 3, 40, 40); ellipse(2 * width / 3, height / 3, 40, 40); ellipse(width / 2, 2 * height / 3, 40, 40); ellipse(2 * width / 3, 2 * height / 3, 40, 40); break; } } void keyPressed() { if (key == ' ') { // espace pour tirer un nouveau chiffre initialiser(); } } |
Mushussu — 2012-05-24 08:12:37 |
Bonjour, Code (Processing) :int compteurX = 0; int rotationX = 0; int compteurY = 0; int rotationY = 0; int compteurZ = 0; int rotationZ = 0; Cube cube = new Cube(); void setup() { size(400, 400, P3D); stroke(0); lights(); frameRate(30); } void draw() { if (compteurX < rotationX) { compteurX = compteurX + 10; } if (compteurY < rotationY) { compteurY = compteurY + 10; } if (compteurZ < rotationZ) { compteurZ = compteurZ + 10; } background(0); translate(width/2, height/2, 0); cube.rotationCube(compteurX, compteurY, compteurZ); cube.dessinCube(); } void keyPressed() { compteurX = (rotationX % 360); rotationX = compteurX + 90*(1 + int(random(8))); compteurY = (rotationY % 360); rotationY = compteurY + 90*(1 + int(random(8))); compteurZ = (rotationZ % 360); rotationZ = compteurZ + 90*(1 + int(random(8))); } class Cube { Cube(){ } void rotationCube(int rx, int ry, int rz){ rotateX(radians(rx)); rotateY(radians(ry)); rotateZ(radians(rz)); } void dessinCube() { stroke(0); fill(255, 0, 0); box(100); fill(255); // Le 6 dessinPoint(0, 30, 50.1, 0 ,0); dessinPoint(0, -30, 50.1, 0 ,0); dessinPoint(30, 30, 50.1, 0 ,0); dessinPoint(-30, 30, 50.1, 0 ,0); dessinPoint(30, -30, 50.1, 0 ,0); dessinPoint(-30, -30, 50.1, 0 ,0); // Le 1 dessinPoint(0, 0, -50.1, 0 ,0); // Le 5 dessinPoint(-50.1, 30, -30, 0, 90); dessinPoint(-50.1, 30, 30, 0, 90); dessinPoint(-50.1, 0, 0, 0, 90); dessinPoint(-50.1, -30, 30, 0, 90); dessinPoint(-50.1, -30, -30, 0, 90); // Le 2 dessinPoint(50.1, -30, -30, 0, 90); dessinPoint(50.1, 30, 30, 0, 90); // Le 4 dessinPoint(-30, 50.1, -30, 90, 0); dessinPoint(30, 50.1, -30, 90, 0); dessinPoint(-30, 50.1, 30, 90, 0); dessinPoint(30, 50.1, 30, 90, 0); // Le 3 dessinPoint(-30, -50.1, -30, 90, 0); dessinPoint(0, -50.1, 0, 90, 0); dessinPoint(30, -50.1, 30, 90, 0); } void dessinPoint(float px, float py, float pz, int rx, int ry) { pushMatrix(); translate(px, py, pz); rotateX(radians(rx)); rotateY(radians(ry)); noStroke(); ellipse(0, 0, 18, 18); popMatrix(); } } |
EricRG — 2012-05-25 16:50:42 |
euh, il manque ta classe Cube :) |
EricRG — 2012-05-25 16:54:46 |
Sinon, pour utiliser des vidéos, |
cgiles — 2012-05-25 21:05:55 |
tu peux aussi taper int()random(6)+1 , ça marche aussi, on appel ça un casting |
emoc — 2012-05-25 22:30:27 |
Non, elle est bien dans l'exemple donné par Mushussu, qui fonctionne d'ailleurs, et c'est un chouette exemple ;) |
Mushussu — 2012-05-26 04:26:33 |
Merci maître … |
EricRG — 2012-05-27 12:33:05 |
OUi, en effet ! |