//sketch_3D_Z_6Bar void setup() { size(400, 400, P3D); } void draw() { background(255, 255, 255); lights(); ortho(-width/2, width/2, -height/2, height/2); // Same as ortho() translate(width / 2, height / 2); rotateY(map(mouseX, 0, width, -PI/1, PI/1)); rotateX(map(mouseY, 0, height, PI/1, -PI/1)); //noStroke(); strokeWeight(0.5); fill(255, 255, 255); scale(2,2,2); Z_6Bar(12,100);//Z_6角支柱 } void Z_6Bar(float B,float L)//Z_6角支柱 { int sides=6;//分割数=6 int Sn=2;//面数 float Pz[]={-L/2,L/2};//z座標 float r=B/(2*cos(30*PI/180)); float R[]={r,r};//回転物半径 int i,j; float angleIncrement = TWO_PI/sides; for(j=0;j< Sn-1;j++) { float angle = 0; beginShape(QUAD_STRIP); for (i = 0; i < sides + 1; ++i) { vertex(R[j]*cos(angle), R[j]*sin(angle), Pz[j]); vertex(R[j+1]*cos(angle), R[j+1]*sin(angle), Pz[j+1]); angle += angleIncrement; } endShape(CLOSE); } pushMatrix();translate(0,0,-L/2); Z_hexagon(B);popMatrix();//6角形 pushMatrix();translate(0,0,L/2); Z_hexagon(B);popMatrix();//6角形 } void Z_hexagon(float B)//6角形 { int sides=6;//分割数=6 float r=B/(2*cos(30*PI/180)); int i; float angleIncrement = TWO_PI/sides; float angle = 0; beginShape(); for (i = 0; i < sides + 1; ++i) { vertex(r*cos(angle), r*sin(angle),0); angle += angleIncrement; } endShape(CLOSE); }