peux-tu modifier createHead() pour ajouter des strips de mommie : PShape mummy; void…
- User
peux-tu modifier createHead() pour ajouter des strips de mommie : 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
Voici la fonction createHead() modifiée pour ajouter des strips de mommie :
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); } // Ajouter des strips de mommie aléatoires if (i < 10 && random(1) < 0.3) { PShape strip = createShape(); strip.beginShape(QUAD_STRIP); strip.noStroke(); strip.fill(245, 245, 220); float stripAngle = random(PI/4, 3*PI/4); float stripLength = random(10, 20); float x5 = rx * cos(lat1 + stripAngle) * sin(lon); float y5 = ry * sin(lat1 + stripAngle); float z5 = rz * cos(lat1 + stripAngle) * cos(lon); float x6 = rx * cos(lat1 + stripAngle) * sin(lon + TWO_PI/res); float y6 = ry * sin(lat1 + stripAngle); float z6 = rz * cos(lat1 + stripAngle) * cos(lon + TWO_PI/res); for (float k = 0; k <= stripLength; k++) { float t = k / stripLength; float currentX = lerp(x5, x6, t); float currentY = lerp(y5, y6, t); float currentZ = lerp(z5, z6, t); strip.vertex(currentX, currentY, currentZ); strip.vertex(currentX, currentY + 5, currentZ); } strip.endShape(); head.addChild(strip); } }} head.endShape(); return head; }