# Animated Cube of Cubes with Java and Processing

**URL:** <https://discourse.processing.org/t/animated-cube-of-cubes-with-java-and-processing/28661>\
**Category:** Gallery\
**Created:** [March 19, 2021, 4:53pm UTC](https://discourse.processing.org/t/animated-cube-of-cubes-with-java-and-processing/28661 "2021-03-19T16:53:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [March 19, 2021, 4:53pm UTC](https://discourse.processing.org/t/animated-cube-of-cubes-with-java-and-processing/28661/1 "2021-03-19T16:53:39Z")

</div>

[![](https://img.youtube.com/vi/iJh8dvEt03E/maxresdefault.jpg "Animated Cube of Cubes with Java and Processing") ](https://www.youtube.com/watch?v=iJh8dvEt03E)

```auto
int OFF_MAX = 300;

void setup() {
  size(1080, 1060, P3D);
}

void draw() {
  background(0);
  translate(width / 2, height / 2, -OFF_MAX);
  rotateX(frameCount * .01);
  rotateY(frameCount * .01);
  rotateZ(frameCount * .01);
  
  for (int xo = -OFF_MAX; xo <= OFF_MAX; xo += 50) {
    for (int yo = -OFF_MAX; yo <= OFF_MAX; yo += 50) {
      for (int zo = -OFF_MAX; zo <= OFF_MAX; zo += 50) {
        pushMatrix();
        translate(xo, yo, zo);
        rotateX(frameCount * .02);
        rotateY(frameCount * .02);
        rotateZ(frameCount * .02);
        fill(colorFromOffset(xo), colorFromOffset(yo), 
          colorFromOffset(zo));
        box((float) (20 + (Math.sin(frameCount / 20.0)) * 15));
        popMatrix();
      }
    }
  }
}

int colorFromOffset(int offset) {
  return (int) ((offset + OFF_MAX) / (2.0 * OFF_MAX) * 255);
}

```
