Interaction Design WikiProgramming

3D Reactors

It’s possible to export 3D geometry suitable for 3D printing with the objectExport library from nervous system.

import peasy.PeasyCam;
import nervoussystem.obj.*;

PeasyCam cam;
boolean record = false;
void setup() { 
  size(1000, 1000, P3D);
  cam = new PeasyCam(this, 400);
  lights();
  stroke(50);
}

void draw() {
  background(0);
  if (record) {
    beginRecord("nervoussystem.obj.OBJExport", "filename.obj");
  }

  pushMatrix();
  PVector Reactor = new PVector(mouseX-width/2, mouseY-height/2);
  for (int x = -5; x<=5; x++) {
    for (int y = -5; y<=5; y++) {
      PVector midPoint = new PVector(x*100, y*100);
      midPoint.sub(Reactor);
      float dist = midPoint.mag()*.1;
      pushMatrix();
      translate(x*100, y*100, dist);
      sphere(dist);
      popMatrix();
    }
  }
  popMatrix();
  
  if (record) {
    endRecord();
    record = false;
  }
}


void keyPressed()
{
  if (key == 'r') {
    record = true;
  }
}

Here is a more advanced example with constructed polygon forms.

import peasy.PeasyCam;
import nervoussystem.obj.*;

PeasyCam cam;
boolean record = false;
void setup() { 
  size(1000, 1000, P3D);
  cam = new PeasyCam(this, 400);
}

void draw() {
  background(0);
  if (record) {
    beginRecord("nervoussystem.obj.OBJExport", "filename.obj");
  }
  stroke(100);
  pushMatrix();
  PVector Reactor = new PVector(mouseX-width/2, mouseY-height/2);
  for (int x = -500; x<=500; x+= 200) {
    for (int y = -500; y<=500; y+= 200) {
      PVector midPoint = new PVector(x, y);
      midPoint.sub(Reactor);
      midPoint.normalize();
      midPoint.mult(300);
      midPoint.rotate(radians(dist(x,y,Reactor.x,Reactor.y)/10));
      
      midPoint.z = 200;// all pyramids are the same height
      Pyramid(x, y, midPoint);
    }
  }
  popMatrix();

  if (record) {
    endRecord();
    record = false;
  }
}

void Pyramid(float x, float y, PVector Point) {
  pushMatrix();
  translate(x, y, 0);
  beginShape(TRIANGLES);
  //side A
  vertex(-100, -100, -100);
  vertex( 100, -100, -100);
  vertex(Point.x, Point.y, Point.z);
  //side B
  vertex( 100, -100, -100);
  vertex( 100, 100, -100);
  vertex(Point.x, Point.y, Point.z);
  //side C
  vertex( 100, 100, -100);
  vertex(-100, 100, -100);
  vertex(Point.x, Point.y, Point.z);
  //side D
  vertex(-100, 100, -100);
  vertex(-100, -100, -100);
  vertex(Point.x, Point.y, Point.z);
  endShape(CLOSE);
  // pyramid base 
  beginShape(TRIANGLE_STRIP);
  vertex(-100, -100, -100);
  vertex(100, -100, -100);
  vertex( -100, 100, -100);
  vertex( 100, 100, -100);
  endShape(CLOSE);
  popMatrix();
}

void keyPressed()
{
  if (key == 'r') {
    record = true;
  }
}