Skip to content
Inho Oh edited this page Jul 6, 2018 · 1 revision

Processing

https://processing.org/

Install

Download a installation file(.tgz) from https://processing.org/download/ and extract.

Sample design code

import processing.dxf.*;

float angle = 0;
boolean record;

VWoodFrame vl = new VWoodFrame();
VWoodFrame vr = new VWoodFrame();
HWoodFrame ht = new HWoodFrame();
HWoodFrame hb = new HWoodFrame();
HWoodFrame hc = new HWoodFrame();
Monitor23 m23 = new Monitor23();

public void setup() {  
  float cbar_y;
  float frameDMargin = 30;

  size(450, 1000, P3D);

  vl.move(0, 0, frameDMargin);
  vl.setHeight(height);

  vr.move(width - vl._w, 0, frameDMargin);
  vr.setHeight(height);

  ht.move(vl._w, 0, frameDMargin);
  ht.setWidth(width - ht._x);

  hb.move(vl._w, height - vl._d, frameDMargin);  
  hb.setWidth(width - hb._x);

  m23.move((width - m23._w) / 2, ht._y + ht._h, frameDMargin + hc._d - m23._d);
  cbar_y = m23._y + m23._h + 5;

  hc.move(vl._w, cbar_y, frameDMargin);
  hc.setWidth(450 - hc._x);
}

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

public void draw() {
  background(128);
  if (record) {
    beginRaw(DXF, "output.dxf");
  }

  float cameraY = height/2.0;
  float fov = mouseX/float(width) * PI/2;
  float cameraZ = cameraY / tan(fov / 2.0);
  float aspect = float(width)/float(height);
  if (!mousePressed) {
    //aspect = aspect / 2.0;
    perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0);
  } else {
    angle = angle + 0.01;
    //angle = 2.7;
    translate(width/2-100, height/2-100);
    rotateX(cos(angle));
    rotateY(cos(angle));
    println(angle);
  }

  wall();

  ht.update();
  hb.update();
  hc.update();
  vl.update();
  vr.update();
  m23.update();

  if (record) {
    endRaw();
    println("saved to output.dxf");
    record = false;
  }
}

void wall()
{
  pushMatrix();
  translate(width/2, height/2, 0);
  stroke(255);
  fill(255);
  box(width*1.2, height*1.2, 0);
  popMatrix();
}

class Gakmok {
  float _x, _y, _z;
  float _w, _h, _d;

  Gakmok () {
    _d = 57;
  }

  void move(float x, float y, float z) {
    _x = x;
    _y = y;
    _z = z;
  }

  void setWidth(float w) {
    _w = w;
  }

  void setHeight(float h) {
    _h = h;
  }

  void update() {
    pushMatrix();
    translate(_x + (_w/2), _y + (_h/2), _z + (_d/2));
    fill(128, 128, 0);
    box(_w, _h, _d);
    popMatrix();
  }
}

class HWoodFrame extends Gakmok {
  HWoodFrame () {
    super();
    _h = _d;
  }
}

class VWoodFrame extends Gakmok {  
  VWoodFrame () {
    super();
    _w = _d;
  }
}

class Monitor23 {
  float _x, _y, _z;
  float _w, _h, _d;

  Monitor23 () {
    _w = 312;
    _h = 534;
    _d = 10;
  }
  void move(float x, float y, float z) {
    _x = x;
    _y = y;
    _z = z;
  }
  void update() {
    pushMatrix();
    translate(_x + _w/2, _y + _h/2, _z + _d/2);
    fill(0, 128, 128);
    box(_w, _h, _d);
    popMatrix();
  }
}
Clone this wiki locally