PImage image; int hen = 100; float takasa = hen * sqrt(3) / 2; boolean hanten = false; int texture_x = 0; int texture_y = 0; float camera_x = 0; float camera_y = 0; void setup() { size(1024, 768, P3D); noStroke(); frameRate(30); image = loadImage("chairs.jpg"); camera_x = width/2.0; camera_y = height/2.0; perspective(); } void draw() { background(#000000); camera(camera_x, camera_y, (height/2.0) / tan(PI*60.0 / 360.0) / 2, width/2.0, height/2.0, 0, 0, 1, 0); for(int i=0 ; takasa * i < height + takasa ; i++) { if (i % 2 == 0) { pushMatrix(); translate(hen / 2, takasa * i); sankaku6(); for(int j=3 ; hen * j < width ; j+=3) { translate(hen * 3, 0); sankaku6(); } popMatrix(); }else{ for(int j=2 ; hen * j < width + hen ; j+=3) { pushMatrix(); translate(hen * j, takasa * i); sankaku6(); popMatrix(); } } } } void sankaku6() { for(int i=0 ; i < 360 ; i += 60) { pushMatrix(); if (hanten) { rotateY(radians(180)); hanten = false; }else{ hanten = true; } rotate(radians(i)); sankaku1(); popMatrix(); } } void sankaku1() { beginShape(TRIANGLES); texture(image); vertex(0, 0, hen / 2 + texture_x, 0 + texture_y); vertex(hen / 2, takasa, hen + texture_x, takasa + texture_y); vertex(-hen / 2, takasa, 0 + texture_x, takasa + texture_y); endShape(); } void mouseDragged() { if(mouseButton == LEFT) { texture_x += mouseX - pmouseX; if (texture_x < 0) { texture_x = 0; }else if (texture_x > image.width - hen) { texture_x = image.width - hen; } texture_y += mouseY - pmouseY; if (texture_y < 0) { texture_y = 0; }else if (texture_y > image.height - hen) { texture_y = image.height - hen; } } else if (mouseButton == RIGHT) { camera_x += mouseX - pmouseX; if (camera_x < 0) { camera_x = 0; }else if (camera_x > width) { camera_x = width; } camera_y += mouseY - pmouseY; if (camera_y < 0) { camera_y = 0; }else if (camera_y > height) { camera_y = height; } } }