Architecturalising images
in
Programming Questions
•
3 years ago
Hi,
I'm fresh to this programming lark. Haven't played with any since Directorscript and HTML many moons ago.
I am currently studying architecture and interested in architecturalising (?) some images to inform my structure.
I am using PeasyCam library and the beautiful code of leonardo Solaas at http://solaas.com.ar/node/25 and trying to export my java files as a DXF file using the simple exporter code http://processing.org/learning/library/simpleexport.html.
I have been mashing the codes against each other for a while to try and export some of the great images I am getting.
Here is my code... apparently I am confusing active and static modes?
Any pointers or help to what I am doing wrong would be great. I hope I have not offended anyone with what is probably a very simple fix - I have done a few searches but there is nothing I could understand that would help me.
Thank you in advance. Matt
import processing.dxf.*;
boolean record;
import peasy.*; //PeasyCam library is required. Download from http://mrfeinberg.com/peasycam/
import javax.media.opengl.*;
import processing.opengl.*;
String image_name = "PB130049"; //set the name of the source .jpg image here. it should exist whithin the sketch 'data' folder.
PImage img;
int mode = RGB;
boolean forward = true;
PeasyCam cam;
PGraphicsOpenGL pgl;
GL gl;
void setup(){
size(800, 800, P3D);
colorMode(mode);
pgl = (PGraphicsOpenGL) g;
gl = pgl.gl;
}
void keyPressed() {
// use a key press so that it doesn't make a million files
if (key == 'r') record = true;
cam = new PeasyCam(this, 400);
cam.setMinimumDistance(50);
cam.setMaximumDistance(1000);
img = createImage(300, 300, RGB); //smaller image for sampling color values. lower dimensions if performance in your system is bad, or increase for more detail
PImage loaded = loadImage(image_name +".jpg");
img.copy(loaded, 0, 0, loaded.width, loaded.height, 0, 0, img.width, img.height);
}
void draw() {
if (record) {
beginRaw(DXF, "output.dxf");
}
gl.glDepthMask(false);
gl.glEnable( GL.GL_BLEND );
translate(-128, -128, -128);
travel();
}
void travel(){
PVector pos = new PVector(0, 0, 0);
PVector prev = new PVector(0, 0, 0);
makeAxis(); //paint the container cube borders
for(int i=0; i<img.pixels.length; i++){
color p = img.pixels[forward ? i : img.pixels.length-1-i];
if(mode == RGB) pos.set(red(p), green(p), blue(p));
else pos.set(hue(p), saturation(p), brightness(p));
stroke(p, 64); //using an alpha value of 64 - reduce or increase to your taste
if(i % img.width > 0) line(prev.x, prev.y, prev.z, pos.x, pos.y, pos.z); //do not draw row jumps
prev = pos.get();
}
}
void makeAxis(){
int m = 255;
int a = 64; //alpha value of containing box
strokeWeight(2); //line thickness of containing box
for(int i=0; i<m; i++){
//red or hue
stroke(i, 0, 0, a);
line(i, 0, 0, i+1, 0, 0);
stroke(i, m, m, a);
line(i, m, m, i+1, m, m);
stroke(i, m, 0, a);
line(i, m, 0, i+1, m, 0);
stroke(i, 0, m, a);
line(i, 0, m, i+1, 0, m);
//green or saturation
stroke(0, i, 0, a);
line(0, i, 0, 0, i+1, 0);
stroke(m, i, m, a);
line(m, i, m, m, i+1, m);
stroke(0, i, m, a);
line(0, i, m, 0, i+1, m);
stroke(m, i, 0, a);
line(m, i, 0, m, i+1, 0);
//blue or brightness
stroke(0, 0, i, a);
line(0, 0, i, 0, 0, i+1);
stroke(m, m, i, a);
line(m, m, i, m, m, i+1);
stroke(0, m, i, a);
line(0, m, i, 0, m, i+1);
stroke(m, 0, i, a);
line(m, 0, i, m, 0, i+1);
}
strokeWeight(1);
}
if (record) {
endRaw();
record = false;
}
I'm fresh to this programming lark. Haven't played with any since Directorscript and HTML many moons ago.
I am currently studying architecture and interested in architecturalising (?) some images to inform my structure.
I am using PeasyCam library and the beautiful code of leonardo Solaas at http://solaas.com.ar/node/25 and trying to export my java files as a DXF file using the simple exporter code http://processing.org/learning/library/simpleexport.html.
I have been mashing the codes against each other for a while to try and export some of the great images I am getting.
Here is my code... apparently I am confusing active and static modes?
Any pointers or help to what I am doing wrong would be great. I hope I have not offended anyone with what is probably a very simple fix - I have done a few searches but there is nothing I could understand that would help me.
Thank you in advance. Matt
import processing.dxf.*;
boolean record;
import peasy.*; //PeasyCam library is required. Download from http://mrfeinberg.com/peasycam/
import javax.media.opengl.*;
import processing.opengl.*;
String image_name = "PB130049"; //set the name of the source .jpg image here. it should exist whithin the sketch 'data' folder.
PImage img;
int mode = RGB;
boolean forward = true;
PeasyCam cam;
PGraphicsOpenGL pgl;
GL gl;
void setup(){
size(800, 800, P3D);
colorMode(mode);
pgl = (PGraphicsOpenGL) g;
gl = pgl.gl;
}
void keyPressed() {
// use a key press so that it doesn't make a million files
if (key == 'r') record = true;
cam = new PeasyCam(this, 400);
cam.setMinimumDistance(50);
cam.setMaximumDistance(1000);
img = createImage(300, 300, RGB); //smaller image for sampling color values. lower dimensions if performance in your system is bad, or increase for more detail
PImage loaded = loadImage(image_name +".jpg");
img.copy(loaded, 0, 0, loaded.width, loaded.height, 0, 0, img.width, img.height);
}
void draw() {
if (record) {
beginRaw(DXF, "output.dxf");
}
gl.glDepthMask(false);
gl.glEnable( GL.GL_BLEND );
translate(-128, -128, -128);
travel();
}
void travel(){
PVector pos = new PVector(0, 0, 0);
PVector prev = new PVector(0, 0, 0);
makeAxis(); //paint the container cube borders
for(int i=0; i<img.pixels.length; i++){
color p = img.pixels[forward ? i : img.pixels.length-1-i];
if(mode == RGB) pos.set(red(p), green(p), blue(p));
else pos.set(hue(p), saturation(p), brightness(p));
stroke(p, 64); //using an alpha value of 64 - reduce or increase to your taste
if(i % img.width > 0) line(prev.x, prev.y, prev.z, pos.x, pos.y, pos.z); //do not draw row jumps
prev = pos.get();
}
}
void makeAxis(){
int m = 255;
int a = 64; //alpha value of containing box
strokeWeight(2); //line thickness of containing box
for(int i=0; i<m; i++){
//red or hue
stroke(i, 0, 0, a);
line(i, 0, 0, i+1, 0, 0);
stroke(i, m, m, a);
line(i, m, m, i+1, m, m);
stroke(i, m, 0, a);
line(i, m, 0, i+1, m, 0);
stroke(i, 0, m, a);
line(i, 0, m, i+1, 0, m);
//green or saturation
stroke(0, i, 0, a);
line(0, i, 0, 0, i+1, 0);
stroke(m, i, m, a);
line(m, i, m, m, i+1, m);
stroke(0, i, m, a);
line(0, i, m, 0, i+1, m);
stroke(m, i, 0, a);
line(m, i, 0, m, i+1, 0);
//blue or brightness
stroke(0, 0, i, a);
line(0, 0, i, 0, 0, i+1);
stroke(m, m, i, a);
line(m, m, i, m, m, i+1);
stroke(0, m, i, a);
line(0, m, i, 0, m, i+1);
stroke(m, 0, i, a);
line(m, 0, i, m, 0, i+1);
}
strokeWeight(1);
}
if (record) {
endRaw();
record = false;
}
1