A Blog Exploring Digital Art

This blog started life as blog for "A Mass Writing Project" to produce a book on processing. This blog has since evolved into a more general exploration of digital art. Recently I've been looking at Povray, pyprocessing, and cfdg (version 3.0) as tools for creating digital images. I have branched a separate blog where I mainly explore ruby/rp5.

Friday, 25 May 2012

Export of processing sketch with POvRAY primitives

It is a long term goal for my various povwriter/povmesh export libraries that I support the export of certain shapes as povray primitives (box and sphere in the first instance) along with triangles, lines and mesh2 objects. Its not easy, I thought modelX, modelY and modelZ would come to the solution, but somethings not quite right with the resulting x, y and z coordinates. However if I produce a processing sketch restricted to using the primitives I do get a pretty good result:-
A simple processing sketch exported as PovRAY primitives

Wednesday, 16 May 2012

Exporting A Generative Design Sketch in Processing 2.0 to povray

Previously, I had demonstrated the export to povray of a processing generativedesign sketch to povray using my povwriter library designed to work with processing-1.5.1 here. This is my first exploration with my povwriter2 library (requires processing version greater than 2.0a5, so you will need you need to grab it from svn and compile it yourself). Here is the sketch code see previous post to see what a running sketch looks like.
   1 import povexport2.*;
   2 import povexport2.gui.*;
   3 import povexport2.povwriter.*;
   4 
   5 /**
   6  * part of the example files of the generativedesign library.
   7  *
   8  * shows how to use the Mesh class.
   9  */
  10 
  11 
  12 // imports
  13 import generativedesign.*;
  14 
  15 PovExporter export; 
  16 
  17 void setup() {
  18   size(800, 800, P3D);
  19   export = new PovExporter(this);
  20   export.chooseTemplate();
  21   export.setPovrayPath("/usr/local/bin/povray"); //use this once to set povray path
  22   // Quality PREVIEW, MEDIUM, HIGH, HIGHEST, GRAYSCALE
  23   export.createIniFile(dataPath("screw.ini"), Quality.HIGH);
  24   export.addDeclareOption("ScaleP5", "0.5"); 
  25   export.addDeclareOption("TransYP5", "60"); // custom declare,translates Y axis in PovRAY
  26   export.addDeclareOption("TransP5", "-40"); // custom declare,translates X axis in PovRAY
  27 }
  28 
  29 void draw(){
  30   if (export.traced()) { // display traced image
  31     display();
  32   }
  33   else{
  34   // setup lights
  35   background(255);
  36     noStroke();
  37   fill(0);
  38   lightSpecular(230, 230, 230); 
  39   directionalLight(200, 200, 200, 0.5, 0.5, -1); 
  40   specular(color(220)); 
  41   shininess(5.0); 
  42   export.beginRaw(dataPath("screw.pov")); 
  43   // setup view
  44   translate(width*0.5, height*0.5);
  45   rotateX(-0.2); 
  46   rotateY(-0.5); 
  47   scale(100);
  48   // setup Mesh, set colors and draw  
  49   Mesh myMesh = new Mesh(this, Mesh.STEINBACHSCREW, 200, 200, -3.0, 3.0, -PI, PI);
  50   myMesh.setColorRange(200, 200, 50, 50, 40, 40, 100);
  51   myMesh.draw();
  52 
  53   export.endRaw();  //end tracing
  54   }
  55 }
  56 
  57 /**
  58  * Display ray traced image in sketch window
  59  */
  60 void display() {
  61   background(loadImage(dataPath("screw.png")));
  62 }
  63 
  64 

Monday, 14 May 2012

Fast ray tracing of processing sketches, using povray-3.7

Use povray-3.7-RC5, with my processing povwriter2 library, and get virtually instant (depending on quality of trace setting and complexity of sketch) ray-traced image displayed in processing window. To use this library you must use the latest processing-2.0, available as an svn checkout, processing-2.0a5 won't do. This is definitely an offline activity, and to benefit from the the SMP features of povray-3.7, you obviously need need a processor with more than one core. Here is my "ftest" sketch, before and after:-
Processing sketch, note record button
Povray traced image in sketch window (simple scene template)

Friday, 11 May 2012

Raw Export from Processing 2.0 (currently only in svn)

I have been tracking the development processing-2.0, partly because since my povwriter libraries (based on the dxf export library) did not work at all with processing-2.0 alpha. This has changed very recently, and the svn version of processing (since revision r9560) now supports the raw export of processing vertices. The main change I needed to make to my library was to extend PGraphics, rather that PGraphics3D for the raw export file.
I have created a new repository on github, (which you are welcome to clone/fork) where I will publish my new library. As with my previous povwriter library, povwriter2 requires the existence of template folder (available as a zip download at github).

Saturday, 5 May 2012

Pure Povray Stochastic Menger Sponge

//+W1280
//+H1024
#version 3.7;

global_settings{
  assumed_gamma 1.0
  radiosity{
    pretrace_start 0.04
    pretrace_end 0.01
    count 200
    recursion_limit 3
    nearest_count 10
    error_bound 0.5
  }
}

#include "functions.inc"
#include "colors.inc"
#include "stones1.inc"
#include "metals.inc"

camera { 
  location  <0, 0, 800> 
  look_at <0, 0, 0> 
  right <1.25, 0, 0>
}

sky_sphere { pigment {
    function{abs(y)}
    color_map { [0.0 color blue 0.6] [1.0 color rgb 1] } 
  }
}

light_source {<-50,400,800> color rgb 1}

#declare data = array[20][3] // menger sponge data generated using python
{
{-1, -1, -1}, 
{-1, -1, 0}, 
{-1, -1, 1}, 
{-1, 0, -1}, 
{-1, 0, 1}, 
{-1, 1, -1}, 
{-1, 1, 0}, 
{-1, 1, 1}, 
{0, -1, -1}, 
{0, -1, 1}, 
{0, 1, -1}, 
{0, 1, 1}, 
{1, -1, -1}, 
{1, -1, 0}, 
{1, -1, 1}, 
{1, 0, -1}, 
{1, 0, 1}, 
{1, 1, -1}, 
{1, 1, 0}, 
{1, 1, 1} 
}

#declare RandW = seed(123);
#declare sz = 2;

#macro makemenger(d)
#if (d=0)
#if (rand(RandW) < 0.8)
box{-0.5,0.5}
texture{ T_Stone21 }
#else 
sphere{<0, 0, 0>, 0.5} 
texture{ T_Chrome_5E }
#end
#else
#local i=0;
union {
  #while (i<20)
  object { makemenger(d-1) translate<data[i][0], data[i][1], data[i][2]> scale 1/3}
  #local i=i+1;
  #end 
}
#end
#end
 
object{ 
makemenger(sz) 
scale<300, 300, 300>
rotate<0, 30, 10>
} 
PovRAY rendered

Tuesday, 1 May 2012

Non Recursive Menger Sponge Pyprocessing

from pyprocessing import *

FOV = PI/3.0
angle = 0.0
ANGLE_STEP = PI / 180.0
DATA = [-1,  0,  1]
       
def setup():
    size(800,600)
    cameraZ = (height/2.0) / tan(FOV/ 2.0)
    perspective(FOV, float(width)/float(height), cameraZ/10.0, cameraZ*10.0)
    
def draw():
    background(0,  0,  200)
    noStroke()
    stroke(0)
    lights()
    defineLights()
    translate(width/2.0, height/2.0, 0)
    global angle
    angle = (angle + ANGLE_STEP) % TWO_PI
    rotateZ(angle)
    rotateY(angle)
    create_menger_three(0, 0, 0, height/2.0)

def my_cube(xx,  yy,  zz,  sz):
    """
    Draw a cube with centre xx, yy, zz and size sz
    """
    sz *= 0.5
    beginShape(QUADS)
    normal(0, 0, 1)
    vertex(-sz + xx, -sz + yy, -sz + zz)
    vertex(+sz + xx, -sz + yy, -sz + zz)
    vertex(+sz + xx, +sz + yy, -sz + zz)
    vertex(-sz + xx, +sz + yy, -sz + zz)
    
    #Back face    
    normal(0, 0, -1)
    vertex(-sz + xx, -sz + yy, +sz + zz)
    vertex(+sz + xx, -sz + yy, +sz + zz)
    vertex(+sz + xx, +sz + yy, +sz + zz)
    vertex(-sz + xx, +sz + yy, +sz + zz)
    
    #Left face    
    normal(1, 0, 0)
    vertex(-sz + xx, -sz + yy, -sz + zz)
    vertex(-sz + xx, -sz + yy, +sz + zz)
    vertex(-sz + xx, +sz + yy, +sz + zz)
    vertex(-sz + xx, +sz + yy, -sz + zz)
    
    #Right face    
    normal(-1, 0, 0)
    vertex(+sz + xx, -sz + yy, -sz + zz)
    vertex(+sz + xx, -sz + yy, +sz + zz)
    vertex(+sz + xx, +sz + yy, +sz + zz)
    vertex(+sz + xx, +sz + yy, -sz + zz)
    
    #Top face    
    normal(0, 1, 0)
    vertex(-sz + xx, -sz + yy, -sz + zz)
    vertex(+sz + xx, -sz + yy, -sz + zz)
    vertex(+sz + xx, -sz + yy, +sz + zz)
    vertex(-sz + xx, -sz + yy, +sz + zz)
    
    #Bottom face    
    normal(0, -1, 0)
    vertex(-sz + xx, +sz + yy, -sz + zz)
    vertex(+sz + xx, +sz + yy, -sz + zz)
    vertex(+sz + xx, +sz + yy, +sz + zz)
    vertex(-sz + xx, +sz + yy, +sz + zz)
    endShape()


def create_menger_three(xx, yy, zz, sz):
    """
    Create a non recursive menger sponge using create_menger
    """ 
    u = sz / 3.0
    for i in DATA:
        for j in DATA:
            for k in DATA:
                if ((abs(i) + abs(j) + abs(k)) > 1):
                    create_menger(xx + (i * u), yy + (j * u), zz + (k * u), u)

def create_menger(xx, yy, zz, sz):
    """
    Create a non recursive menger sponge using unit_menger
    """ 
    u = sz / 3.0
    for i in DATA:
        for j in DATA:
            for k in DATA:
                if ((abs(i) + abs(j) + abs(k)) > 1):
                    unit_menger(xx + (i * u), yy + (j * u), zz + (k * u), u)

def unit_menger(xx, yy, zz, sz):
    """
    Create a unit menger sponge using my_cube
    """ 
    u = sz / 3.0
    for i in DATA:
        for j in DATA:
            for k in DATA:
                if ((abs(i) + abs(j) + abs(k)) > 1):
                    my_cube(xx + (i * u), yy + (j * u), zz + (k * u), u)
                        
def defineLights():
    """
    Without lights you wouldn't see the menger
    """
    ambientLight(50, 50, 50)
    pointLight(150, 100, 0, 200, -150, 0)
    directionalLight(0, 102, 255, 1, 0, 0)
    spotLight(255, 255, 109, 0, 40, 200, 0, -0.5, -0.5, PI / 2, 2)     
 run()

Stochastic Menger II (structure-synth)

More efficient eisenscript for a stochastic menger, exploring using a "unit menger".
set maxdepth 200000
R1 


rule R1 w 10 maxdepth 2 > R2 {
  { s 1/3 x -1 y -1  } R1 
  { s 1/3 x -1 y -1  z -1 } R1 
  { s 1/3 x -1 y -1  z +1 } R1 
  { s 1/3 x 1 y -1  } R1 
  { s 1/3 x 1 y -1  z -1 } R1 
  { s 1/3 x 1 y -1  z +1 } R1 
  { s 1/3  y -1  z -1 } R1  
  { s 1/3  y -1  z +1 } R1 
  { s 1/3 x -1 y 1  } R1 
  { s 1/3 x -1 y 1  z -1 } R1
  { s 1/3 x -1 y 1  z +1 } R1 
  { s 1/3 x 1 y 1  } R1 
  { s 1/3 x 1 y 1  z -1 } R1
  { s 1/3 x 1 y 1  z +1 } R1
  { s 1/3  y 1  z -1 } R1  
  { s 1/3  y 1  z +1 } R1 
  { s 1/3 x -1   z -1 } R1 
  { s 1/3 x -1   z +1 } R1 
  { s 1/3 x 1    z -1 } R1 
  { s 1/3 x 1    z +1 } R1
}

rule R1  {R2}

rule R2 w 10 maxdepth 1 > c2{
  { s 1/3 x -1 y -1  } R2 
  { s 1/3 x -1 y -1  z -1 } R2 
  { s 1/3 x -1 y -1  z +1 } R2 
  { s 1/3 x 1 y -1  } R2 
  { s 1/3 x 1 y -1  z -1 } R2 
  { s 1/3 x 1 y -1  z +1 } R2 
  { s 1/3  y -1  z -1 } R2  
  { s 1/3  y -1  z +1 } R2 
  { s 1/3 x -1 y 1  } R2 
  { s 1/3 x -1 y 1  z -1 } R2 
  { s 1/3 x -1 y 1  z +1 } R2 
  { s 1/3 x 1 y 1  } R2 
  { s 1/3 x 1 y 1  z -1 } R2 
  { s 1/3 x 1 y 1  z +1 } R2 
  { s 1/3  y 1  z -1 } R2  
  { s 1/3  y 1  z +1 } R2 
  { s 1/3 x -1   z -1 } R2 
  { s 1/3 x -1   z +1 } R2 
  { s 1/3 x 1    z -1 } R2 
  { s 1/3 x 1    z +1 } R2 
}

rule R2{
{color orange} sphere
}

rule c2  w 3{
{color blue} box
}

rule c2 {
 {color orange} sphere
}

Followers

Blog Archive

About Me

My Photo
Pembrokeshire, United Kingdom
Consolidating my online identity as monkstone. I am a 64 bit linux user and advocate of open source software, you can sometimes find me on the processing forum.