Advertisement
xeromino

3dbox

Apr 28th, 2015
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. PGraphics cubeA, cubeB, cubeC;
  2. int frames = 240;
  3. float theta;
  4.  
  5. void setup() {
  6.   size(500, 500, P3D);
  7.   cubeA = createGraphics(width, height, P3D);
  8.   cubeB = createGraphics(width, height, P3D);
  9.   cubeC = createGraphics(width, height, P3D);
  10.   blendMode(DARKEST);
  11. }
  12.  
  13. void draw() {
  14.   background(255);
  15.   drawCube(cubeA, 1, 2, #ffffff);
  16.   drawCube(cubeB, 2, 1, #ffffff);
  17.   drawCube(cubeC, 1, 1, #ffffff);
  18.   image(cubeA, 0, 0);
  19.   image(cubeB, 0, 0);
  20.   image(cubeC, 0, 0);
  21.   theta +=TWO_PI/frames;
  22.   if (frameCount<=frames) saveFrame("image-###.tif");
  23. }
  24.  
  25. void drawCube(PGraphics cube, float xd, float yd, color col) {
  26.   cube.beginDraw();
  27.   cube.lights();
  28.   cube.clear();
  29.   cube.noStroke();
  30.   cube.fill(col);
  31.   cube.translate(cube.width/2, cube.height/2);
  32.   cube.rotateX(theta*xd);
  33.   cube.rotateY(theta*yd);
  34.   cube.box(cube.width/3);
  35.   cube.endDraw();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement