here is my processing java code :
- User
here is my processing java code :
- Assistant
I'm sorry, as an AI language model, I cannot view your code. Please paste your code in the chat so that I can assist you better.
- User
PShape mummy;
void setup() { size(1200, 800, P3D); mummy = createMummy(); }
void draw() { background(4); lights(); translate(width/2, height/2, 0); rotateY(frameCount*0.01); shape(mummy);
}
PShape createMummy() { PShape mummy = createShape(GROUP); float noiseVal = 0; float angle = 0; float radiusX = 50; // rayon en X float radiusY = 50; // rayon en Y float headRadiusX = 20; // rayon en X de la tête float headRadiusY = 20; // rayon en Y de la tête float baseRadiusX = 15; // rayon en X de la base float baseRadiusY = 15; // rayon en Y de la base for(int i = 0; i < 64; i++) { float rX = radiusX + noise(noiseVal)10; float rY = radiusY + noise(noiseVal)10; float x1 = cos(angle) * rX; float z1 = sin(angle) * rY; noiseVal += 0.1; rX = radiusX + noise(noiseVal)10; rY = radiusY + noise(noiseVal)10; float x2 = cos(angle) * rX; float z2 = sin(angle) * rY; PShape strip = createShape(); strip.beginShape(QUAD_STRIP); strip.noStroke(); strip.fill(245, 245, 220); for(float a = 0; a < TWO_PI + 0.1; a += 1) { float r1X, r1Y, r2X, r2Y; if (i < 20) { r1X = headRadiusX + (i/20.0)(radiusX - headRadiusX); r1Y = headRadiusY + (i/20.0)(radiusY - headRadiusY); r2X = headRadiusX + ((i+1)/20.0)(radiusX - headRadiusX); r2Y = headRadiusY + ((i+1)/20.0)(radiusY - headRadiusY); } else if (i > 44) { r1X = baseRadiusX + ((64-i)/20.0)(radiusX - baseRadiusX); r1Y = baseRadiusY + ((64-i)/20.0)(radiusY - baseRadiusY); r2X = baseRadiusX + ((63-i)/20.0)(radiusX - baseRadiusX); r2Y = baseRadiusY + ((63-i)/20.0)(radiusY - baseRadiusY); } else { r1X = radiusX; r1Y = radiusY; r2X = radiusX; r2Y = radiusY; } float x3 = cos(a) * r1X; float z3 = sin(a) * r1Y; float x4 = cos(a) * r2X; float z4 = sin(a) * r2Y; strip.vertex(x3, i*5, z3); strip.vertex(x4, (i+1)*5, z4); noiseVal += 0.01; } strip.endShape(); mummy.addChild(strip); angle += TWO_PI/64; }
// Add arms PShape arm1 = createArm(); PShape arm2 = createArm();
arm1.rotateX(HALF_PI); arm2.rotateX(HALF_PI); arm1.translate(-30, 20, 0); arm2.translate(30, 20, 0);
mummy.addChild(arm1); mummy.addChild(arm2);
// Add head PShape head = createHead(); head.translate(0, -70, 0); mummy.addChild(head);
// Création des yeux PShape eye1 = createEye(); PShape eye2 = createEye();
PShape pupil1 = createPupil(); PShape pupil2 = createPupil();
eye1.translate(-20, -70, 45); // Positionnement de l'œil gauche eye2.translate(20, -70, 45); // Positionnement de l'œil droit pupil1.translate(-20, -70, 45); pupil2.translate(20, -70, 45);
mummy.addChild(eye1); // Ajout de l'œil gauche au corps mummy.addChild(eye2); // Ajout de l'œil droit au corps
mummy.addChild(pupil1); mummy.addChild(pupil2);return mummy; }
PShape createHead() { PShape head = createShape(); head.beginShape(TRIANGLES); head.noStroke(); head.fill(245, 245, 220); // couleur beige clair float rx = 45; // rayon en X float ry = 75; // rayon en Y float rz = 45; // rayon en Z int res = 20; // résolution
for (int i = 0; i < res; i++) { float lat1 = map(i, 0, res, -HALF_PI, HALF_PI); float lat2 = map(i + 1, 0, res, -HALF_PI, HALF_PI);
for (int j = 0; j <= res; j++) { float lon = map(j, 0, res, -PI, PI); // Calculer les coordonnées pour les deux cercles latéraux float x1 = rx * cos(lat1) * sin(lon); float y1 = ry * sin(lat1); float z1 = rz * cos(lat1) * cos(lon); float x2 = rx * cos(lat2) * sin(lon); float y2 = ry * sin(lat2); float z2 = rz * cos(lat2) * cos(lon); // Calculer les coordonnées pour le cercle supérieur float x3 = rx * cos(lat1) * sin(lon + TWO_PI/res); float y3 = ry * sin(lat1); float z3 = rz * cos(lat1) * cos(lon + TWO_PI/res); // Calculer les coordonnées pour le cercle inférieur float x4 = rx * cos(lat2) * sin(lon + TWO_PI/res); float y4 = ry * sin(lat2); float z4 = rz * cos(lat2) * cos(lon + TWO_PI/res); // Ajouter les triangles pour le cercle latéral head.vertex(x1, y1, z1); head.vertex(x2, y2, z2); head.vertex(x3, y3, z3); head.vertex(x3, y3, z3); head.vertex(x2, y2, z2); head.vertex(x4, y4, z4); // Ajouter les triangles pour le haut et le bas de la tête if (i == 0) { head.vertex(x3, y3, z3); head.vertex(x1, y1, z1); head.vertex(x4, y4, z4); } else if (i == res - 1) { head.vertex(x2, y2, z2); head.vertex(x4, y4, z4); head.vertex(x1, y1, z1); } }} head.endShape(); return head; }
PShape createArm() { PShape arm = createShape(); arm.beginShape(QUAD_STRIP); arm.noStroke(); arm.fill(245, 245, 220);
float angle = 3; float radius = 12; // Valeur initiale du rayon float length = 70; float twists = 1;
for (float i = 0; i < length; i++) { // Calculer la taille actuelle du rayon en fonction de la position de la spirale float t = map(i, 0, length, 1, 0.2); float currentRadius = 0.8*lerp(35, radius, t);
float x1 = cos(angle) * currentRadius; float y1 = sin(angle) * currentRadius; float x2 = cos(angle + PI) * currentRadius; float y2 = sin(angle + PI) * currentRadius; arm.vertex(x1, i * 3, y1); arm.vertex(x2, i * 1, y2); angle += TWO_PI / (radius * twists); radius += 0.10;// Décrémenter la valeur du rayon pour inverser la taille des bras}
arm.endShape();
return arm; }
PShape createEye() { PShape eye = createShape(ELLIPSE, 0, 0, 30, 30); eye.setFill(color(255)); return eye; }
PShape createPupil() { PShape pupil = createShape(ELLIPSE,0,0,8,8); pupil.setFill(color(255,0,0)); return pupil; }
- Assistant
This code is a Processing sketch which creates a mummy figure using various geometric shapes like rectangles, ellipses, and 3D shapes. The mummy figure is created using a loop where each iteration is a strip of the mummy's wrapping. The coordinates of each strip are determined using Perlin noise to give it a natural look. The sketch also includes features like arms, head, and eyes which are created using shapes like quad strips and ellipses. Finally, the mummy figure is displayed on the screen with the help of the shape() function.
- User
je devais voir ajouter ce code dans un autre qui sera un labyrinthe, l'énoncé est le suivant : Enfin la momie sera ajoutée dans le labyrinthe avec une position (mx, my) et une direction (dx, dy). Elle pourra se déplacer dans le labyrinthe (en mx+dx, my+dy) si la case est libre et tourner (changement de dx, dy au hasard). Peux-tu coder?
- Assistant
Certainly, here is the code that adds the mummy to a maze and allows it to move and turn:
int[][] maze; // your maze array int mx, my; // mummy position int dx = -1, dy = 0; // mummy direction void setup() { // initialize maze and mummy position // ... mx = 1; my = 1; } void draw() { // loop over maze cells for (int i = 0; i < maze.length; i++) { for (int j = 0; j < maze[0].length; j++) { // check if current cell is the mummy's position if (i == mx && j == my) { // draw mummy shape // ... } else { // draw maze cell // ... } } } // update mummy position and direction int nextX = mx + dx; int nextY = my + dy; if (maze[nextX][nextY] == 0) { // move mummy to next position mx = nextX; my = nextY; } else { // change mummy direction randomly int randDir = int(random(4)); switch (randDir) { case 0: dx = -1; dy = 0; // move left break; case 1: dx = 1; dy = 0; // move right break; case 2: dx = 0; dy = -1; // move up break; case 3: dx = 0; dy = 1; // move down break; } } }Note: This code assumes that the maze array contains zeros for free cells and ones for walls. Feel free to adapt it to your own maze implementation.