Advertisement
xeromino

chrom3D

Apr 28th, 2015
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. PGraphics cubeA, cubeB;
  2. float theta, alphaA, alphaB,sz;
  3. int frames = 240;
  4.  
  5. void setup() {
  6.   size(500, 500, P3D);
  7.   //smooth(8);
  8.   cubeA = createGraphics(250, 250, P3D);
  9.   cubeB = createGraphics(250, 250, P3D);
  10.   background(0);
  11. }
  12.  
  13. void draw() {
  14.   background(0);
  15.   drawCubeA();
  16.   drawCubeB();
  17.   alphaA = map(sin(theta), -1, 1, 50, 255);
  18.   alphaB = map(sin(theta+PI), -1, 1, 50, 255);
  19.   sz = map(sin(theta), -1, 1, .5, 1);
  20.   for (int x=0; x<width; x+=cubeA.width) {
  21.     for (int y=0; y<height; y+=cubeA.height) {
  22.       tint(255, alphaA);
  23.       image(cubeA, x, y);
  24.       tint(255, alphaB);
  25.       image(cubeB, x, y);
  26.     }
  27.   }
  28.   theta += TWO_PI/frames;
  29.   //if (frameCount<=frames) saveFrame("image-###.png");
  30. }
  31.  
  32. void drawCubeA() {
  33.   cubeA.beginDraw();
  34.   cubeA.lights();
  35.   cubeA.background(0);
  36.   cubeA.noStroke();
  37.   //cubeA.fill(255,0,0);
  38.   cubeA.pushMatrix();
  39.   cubeA.translate(cubeA.width/2, cubeA.height/2);
  40.   cubeA.rotateX(theta*2);
  41.   cubeA.rotateY(theta*1);
  42.   cubeA.box(cubeA.width*.5);
  43.   cubeA.popMatrix();
  44.   cubeA.endDraw();
  45. }
  46.  
  47. void drawCubeB() {
  48.   cubeB.beginDraw();
  49.   cubeB.lights();
  50.   cubeB.background(0);
  51.   cubeB.noStroke();
  52.   //cubeB.fill(255,255,0);
  53.   cubeB.pushMatrix();
  54.   cubeB.translate(cubeB.width/2, cubeB.height/2);
  55.   cubeB.rotateX(PI+theta*1);
  56.   cubeB.rotateY(theta*2);
  57.   cubeB.box(cubeB.width/2);
  58.   cubeB.popMatrix();
  59.   cubeB.endDraw();
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement