Recently I've been looking at Povray, pyprocessing, and cfdg (version 3.0) as tools for creating digital images. I have branched two separate blogs where I mainly explore jruby + processing and processing.py

Tuesday, 24 May 2011

Using if in Context Free 3.0 (Linux v12)

Using if to control x displacement in context free, and more subtle mod statement to to produce less obvious repeat patterns:-

   1 startshape pattern
   2 
   3 SQRT3 = sqrt(3)
   4 TTOP = sin(30)/SQRT3
   5 HEXS = SQRT3/4
   6 BLUE = [b .73 h 201 sat .53]
   7 MAGENTA = [b .53 h 42 sat .76]
   8 RED = [b .53 h 356 sat .7]
   9 GREEN = [b .68 h 132 sat .64]
  10  
  11 CF::Size = [s 8.0 x -4 y -4] 
  12 
  13 CF::Background = [b -0.2]
  14 
  15 path triangle {              
  16     MOVETO(-0.5, -TTOP)
  17     loop 3 [r 120]{
  18     CURVETO(0, -TTOP, -0.25, -0.1) 
  19     CURVETO(0.5, -TTOP, CF::Continuous)
  20     }
  21     CLOSEPOLY() 
  22     FILL[]     
  23 }
  24 
  25 shape pattern{
  26    loop i = 0, 10 [x 0.97]{
  27      loop j = 0, 10 [y 0.85]{
  28        if (mod(j, 2) == 0){           
  29        triangle [trans select(mod((i + j), 4), BLUE, MAGENTA, RED, GREEN)]
  30        }
  31        else{
  32          triangle [x 0.48 trans select(mod((i + j), 4), BLUE, MAGENTA, RED, GREEN)]
  33        }
  34      }
  35    }
  36 }
  37 

Monday, 23 May 2011

Alhambra Tiling II demonstrates the use of select() function

More suggestions from MountainViewJohn have helped to simplify this design I was originally using the new switch syntax; here is a more elegant solution using trans and select (also new in the version 3 of the cfdg program). Orientation of triangle is more similar to the tiling in the Alhambra palace.
Updated 26 June 2011 to include latest syntax as per (v12) linux.

CF::Alpha = 0       // Testing version 3.0 syntax
CF::ColorDepth = 16

SQRT3 = sqrt(3)
TTOP = sin(30)/SQRT3
HEXS = SQRT3/4

// Similar to original Alhambra tiling color
GOLD = [h 33 sat 0.967 b 0.592]
BLACK = [h 0 sat 0.909 b 0.129]
GREEN = [h 148 sat 0.696 b 0.271]
BLUE = [h 225 sat 0.777 b 0.475]
RED = [h 17 sat 0.983 b 0.231]

startshape alhambraII

CF::Size = [s 6 x -2.5 y -3.5]  // trim to hide the ragged edge

CF::Background = [b -0.22]

shape alhambraII{        
  loop i = 0, 10 [x 1]{
    loop j = 0, 10 [y (HEXS * 2) x -0.5]{
      triangle[trans select(mod(i, 5), GOLD, BLACK, GREEN, BLUE, RED)]
      hexastar[x 0.5 y 0.29 s 0.33 trans select(mod(j, 5), GOLD, BLACK, GREEN, BLUE, RED)]
      hexagon[s 0.4 b 0.77]
    }    
  }
}

// Orientation more like original Alhambra tiling
path triangle {              // CF 3.0 Syntax in path loop and definition
    MOVETO(-0.5, -TTOP)
    loop 3 [r 120]{
    CURVETO(0, -TTOP, -0.25, -0.1) 
    CURVETO(0.5, -TTOP, CF::Continuous)
    }
    CLOSEPOLY() 
    FILL[]     
}

path hexagon{ 
  MOVETO(0.25, HEXS)          // 3.0 Syntax in path loop and definition
  loop 5 [r -60]{
  LINETO(0.5, 0)
  }
  CLOSEPOLY()  
  FILL[]    
} 

shape hexastar{
  TRIANGLE[r 90]
  TRIANGLE[r 270]
}

Saturday, 14 May 2011

Alhambra Tiling (for CFDG Version 3.0) as Context Free Rules

The new Version of Context Free Art program is at version 3.0 alpha. The new syntax supports tuples in path/shape definition. Anything defined in the shape definition is new syntax, old path is still supported inside path (except when path is nested?). Definitions are now allowed, as is a new loop syntax, parameters are supported but I haven't got that far yet with my experiments. Update 26 June 2011 now includes changed syntax (since V12 linux), and is more precisely tesselated.

startshape alhambra

SQRT3 = sqrt(3)
TTOP = sin(30)/SQRT3
HEXS = SQRT3/4
GOLD = 31      
BLUE = 201     
        
CF::Size = [s 6 x -2.5 y -3.5]  // trim to hide the ragged edge

shape alhambra{
   loop 10 [x 1]{
   loop 10 [y (SQRT3/2) x -0.5]{
   triangle[b 0.73 h BLUE sat 0.8]
   hexagon[s 0.5 b 1 r 15]      // tilt hexagon slightly
   hexastar[s 0.4 h GOLD sat 0.8 b 0.9 x -0.5 y 0.3]
   }
   }
}

path triangle {              // CF 3.0 Syntax in path loop and definition
    MOVETO(-0.5, -TTOP)
    loop 3 [r 120]{
    CURVETO(0, -TTOP, -0.25, -0.1) 
    CURVETO(0.5, -TTOP, CF::Continuous)
    }
    CLOSEPOLY() 
    FILL[]     
}

path hexagon{ 
  MOVETO(0.25, HEXS)          // 3.0 Syntax in path loop and definition
  loop 5 [r -60]{
  LINETO(0.5, 0)
  }
  CLOSEPOLY()  
  FILL[]    
} 

shape hexastar{
  TRIANGLE[r 90]
  TRIANGLE[r 270]
}

Friday, 13 May 2011

Processing to PovRAY (some reflections)

I have just updated my povwriter processing library to version 0.57.  This library simplifies the export of processing sketches to PovRAY format, and works well with many processing sketches. Ideally I would like to support the direct export of primitives (box, sphere etc) but currently its all triangle mesh, with the exception that processing stroke, that is realised as a cylinder/blob primitive (after Guillaume LaBelles supercad).
 My library differs from supercad in the following way

  1. my library supports external templates 
  2. my library "corrects" for different coordinate system
  3. it uses a degenerate filter rather than a random (but biased) random fuzzer kludge to combat degenerate triangles
  4. my library detects fill color (this mostly works, but make sure to turn off processing lights)
  5. the entire processing sketch is encapsulated in a union and can be scaled/translated/rotated independently from the background provided by the PovRAY template file
I recommend that PovRAY is used to provide textures/finish/transparency etc, by using different color for objects in your processing sketch that you want to treat differently, then it is easy to post edit these attributes.

Here is PovRAY image demonstrating the different coordinate systems:-













Its good to be back after blogger hiatus (update 14th May just deleted last post since this replaces what google just restored).

Here is yet another look at the toxmeisters "implicit function sketch" rendered in PovRAY (click on image to view full size)


Monday, 9 May 2011

Toxis Implicit Function Sketch as a bit of Marble (Laplacian Smooth)

PovRAY rendered processing sketch (povwriter export)
Click on Image to View Full Size

Sunday, 8 May 2011

Toxis Implicit Function Sketch as a bit of Granite

Povray Rendered (exported using my povwriter library)

NB: Click on the sketch to View full Size

Dreaming of Processing to Povray Export of Primitives

I would like to support the export of processing primitives to PovRAY, but I have found simple processing tools to be next to useless ( I had hoped modelX, modelY and modelZ would come to my rescue, but I think they are probably broken). Next I looked at using toxiclibs primitives and they do seem somewhat more interesting, dispensing with all the matrix operations needed to use the box and sphere of vanilla processing:-

import povexport.*;
import peasy.*;
import processing.opengl.*;
import toxi.geom.*;
import toxi.processing.*;

ToxiclibsSupport gfx;
PeasyCam cam;
PovExporter export;
boolean record = false;

void setup() {
  size(600,600,OPENGL);
  hint(ENABLE_OPENGL_4X_SMOOTH);
  hint(DISABLE_OPENGL_ERROR_REPORT);
  cam = new PeasyCam(this, 0.0, 0.0, 0.0, 300);
  gfx=new ToxiclibsSupport(this);
  export = new PovExporter(this);
}

void draw() {
  background(0);
  lights();
  noStroke();
  if (record) {
    noLights();
    noLoop();
    beginRaw(PovExporter.POV, dataPath("output.pov"));
  }  
  Vec3D p1=new Vec3D(50,50,50);
  Vec3D p2=new Vec3D(-50,-50,-50);
  Vec3D p3=new Vec3D(60,60,60);
  AABB b=AABB.fromMinMax(p1,p2);
  fill(255, 0, 0);
  gfx.box(b);
   fill(0, 0, 255);
  gfx.sphere(new Sphere(p3, 50), 30);
  if (record) {
    endRaw();
    record = false;
    loop();
  }
}

void keyPressed() {
  switch(key) {
  case 'r':    
    record = true;    
    break;
  case 'e': 
    String[] args = {
      "/home/tux/bin/jedit", dataPath("output.pov")
    };
    //String[] args = {export.getPovrayPath(), dataPath("output.pov")}; // use this if path has been set
    try {    // open(args); just should work on processing but didn't for me
      java.lang.Runtime runtime = java.lang.Runtime.getRuntime();
      runtime.exec(args);
    }
    catch(IOException e) {
      e.printStackTrace();
    }
    break;
  }
}


This is the sort of PovRAY output I would like to be able to produce:-

// Persistence Of Vision Ray Tracer Scene Description File
// File:  Simple Scene <template for povwriter>
// Vers: 3.7
// Date: March 2011
// Auth: Martin Prout 

// +w300 +h300

#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 "colors.inc"
#include "skies.inc"

// ---------------declare adjustments to processing scene
#declare ScaleP5 = 0.3;     // scale factor
#declare TransXP5 = -20;    // translate in X axis
#declare TransYP5 = 70;    // translate in Y axis
#declare TransZP5 = -50;    // translate in Z axis
#declare RotYP5 = 15;       // rotate around Y axis
#declare RotXP5 = 0;        // rotate around Y axis
#declare RotZP5 = 0;         // rotate around Y axis
// ---------------end of declare adjustments to scene

//----------------declare default colors
#declare CornellRed = rgb<0.57, 0.025, 0.025>;  // Right wall Cornell Box
#declare CornellGreen = rgb<0.025, 0.236, 0.025>; // Left wall Cornell Box
#declare LineFill = rgb<1.0, 0.9, 0.8>; // polygon outline color
#declare LineCol = rgb<0.3, 0.225, 0.12>; // polygon outline color
#declare TransFill = rgbf<1.0, 0.95, 0.8, 0.7>; // polygon outline color
#declare BuddhaGold = rgb<195, 160, 4>/255; // Custom Gold
//----------------end declare default colors #### paste sketch after this ####

//----------------begin declare finish

#declare Finish0=finish{diffuse 0.75 emission 0}  // Stroke
#declare Finish1=finish{diffuse 0.78 emission 0}  // Cornell Box Light Patch
#declare Finish2=finish{emission 0.1 phong 0.5 phong_size 10.0}   // Processing object finish

//----------------end declare finish

#declare SWIDTH=1.0; // processing equivalent is stroke width

//----------------begin declare pigment

#declare Pigment0 = pigment{rgb<1, 1, 1>}  // Cornell Box Light Patch

//----------------end declare pigment

//----------------begin declare texture

#declare WhiteT=texture{pigment{White} finish{Finish0}} //
#declare RedT=texture{pigment{CornellRed} finish{Finish0}}   // Cornell Box Walls
#declare GreenT=texture{pigment{CornellGreen} finish{Finish0}} //
#declare Texture0=texture{pigment{LineFill} finish{Finish1}} // this is for 'stroke' color

//----------------end declare texture

//----------------declare scene Settings
#declare camera0 = camera {            // define additional cameras to suit viewing preferences
   location <-1.5, 30.0, -150.0>
   direction <0.0, 0.0, 2.0>
   up  <0.0, 1.0, 0.0>
   right <1.33333, 0.0, 0.0>
   look_at <0.0, 25.0, 35.0>
}

#declare light0 = light_source { <100.0, 100.0, -200.0> colour White }

#declare ground0 = plane { <0.0, 1.0, 0.0>, 0.0  // a reflective ground plane
   pigment { NeonBlue }
   finish {reflection 0.15}
}

//------------------end of declare scene settings

// -----------------set the scene

camera { camera0 }              // ------------------------------------------
                                //  The use of declared values makes it possible to easily 
light_source{ light0 }          //  change the way the scene is rendered. Just define an
                                //  additional camera say for your template, and do the
sky_sphere{ S_Cloud3 }          //  substitution here. Retain the original definition and
                                //  you can easily backtrack. Definitions can also be saved
plane{ ground0 }                //  as included file see colors.inc for an example.
                                // ---------------------------------------------  
// -----------------end set the scene

// -----------------hand crafted sketch begins here------------------------

union{
  box{ <50,50,50>,<-50,-50,-50>
    texture{ pigment{rgb<0.7, 0, 0>}
      finish {Finish2}    }
  }
   sphere{ <50,40,40>,60
    texture{ pigment{rgb<0.7, 0.7, 0.7>}
      finish {Finish2}
    }
  }
  translate<TransXP5, TransYP5, TransZP5>
rotate<RotXP5, RotYP5, RotZP5>
scale<ScaleP5, ScaleP5, ScaleP5>

}

Povray Primitives Hand Edited




Sunday, 1 May 2011

Toxiclibs Inflate Mesh Examples (Processing sketch Exported To Povray)

For some reason this sketch exported very nicely to PovRAY format using my povwriter library (icebergs comes to mind). Click on image to view full size. To follow my example be sure to "supress lights" when exporting the sketch (the number of possible shapes seems limitless some of the spiky versions might look good with a checkered floor).

PovRAY rendered toxiclibs inflate mesh example

Followers

Blog Archive

About Me

My photo
Pembrokeshire, United Kingdom
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2