nested cubes in processing

Nikolaus Gradwohl2020-10-04T03:33:17+00:00

for this processing sketch I created a set of 5 nested cubes - each half the size of it's predecessor.

nested cubes

Each cube rotates around the x and y axis with different speeds and each cube rotates at a 10% slower rate than its predecessor.

To make the 3D effect a little bit more prominent I activated the "ENABLE_STROKE_PERSPECTIVE" hint, so the lines of the cubes wireframe get thinner the further they are away from the camera.

Initally i planned to render the cubes only as wireframes, but after experimenting with them for a while I decided to go for a transparent light blue shading.

Usually I would link the sketch here and make it interactive using processing.js - unfortunately that project isn't activly developed anymore and doesn't support transparentcy on 3D faces or the stroke perspective hint - so here is the sourcecode for you to run it - and a short video showing the cubes

void setup() {
  size(600, 600, P3D);
  float fov = PI/4.0;
  float cameraZ = (height/2.0) / tan(fov/2.0);
  perspective(fov, float(width)/float(height),
    cameraZ/20.0, cameraZ*20.0);
  hint(ENABLE_STROKE_PERSPECTIVE);
  hint(ENABLE_DEPTH_SORT);
}

void draw() {
  background(255);
  translate(width/2, height/2, 00);
  float m = millis();
  for( float i=0; i<5; i++) {
  pushMatrix();
  scale(1.0/pow(2,i));
  float fx = (m*pow(0.9,i))/4399.3;
  float fy = (m*pow(0.9,i))/3588.7;
  rotateX(fx);
  rotateY(fy);

  stroke(0);
  strokeWeight(10);
  fill(205,205,255,128);
  box(200);
  popMatrix();
  }
}
Tweet This! submit to reddit Digg! Tags: | no comments | no trackbacks

See also:

simple clock in processing
colorclock in processing
sketch experiment 7 - osc events
processing phaseflower
Time Perception

Trackbacks

Comments

Leave a response

Leave a comment