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

Friday, 19 November 2010

StructureSynth javascript interface

Here is the the javascript that I wrote to test my idea for animating my tic tac toe (Jack wins!!). This is the chicken route, where I first create 9 eisenscripts for the following story board:-

  1. Empty frame Frame00.es
  2. One Jack (cross) Frame01.es
  3. One Jack and One Sphere (nought) Frame02.es
  4. Two Jacks and One Sphere Frame03.es
  5. Etc

Of course with cut and paste this is very easy (in fact easiest way of working is probably to create the "final frame" then work back commenting out the last step until you are left with the empty frame.

   1 #javascript
   2 
   3 function pad(num) {
   4   number = num + '';                        // convert integer to string
   5   while (number.length < 2) {
   6     number = "0" + number;    
   7   }
   8   return number;
   9 }
  10 
  11 for (i = 0; i <= 8; i++){
  12   name = "/home/tux/es/Frame" + pad(i);    // pad to match eisen script names
  13   Builder.load(name + ".es");
  14   Builder.reset();  
  15   Builder.setSize(0, 480);
  16   Builder.build();
  17   image = name + "00.png" // pad to allow for duplicate frames
  18   Builder.raytraceToFile(image, true);
  19 }
  20 

Here is the result where I padded the sketch with duplicate frames (1 .. 99), (101 - 199), etc...
It is still all over a bit too quickly but at least it works.
I used ffmpeg to stitch together frames as a movie:-

ffmpeg -f image2 -i Frame0%3d.png movie.mp4



3D tic tac toe (structuresynth 1.5) from monkstone on Vimeo.

Wednesday, 17 November 2010

Refactoring my Tic Tac Toe eisenscript to use flip and recursion

Exploring limited recursion, and flip directives in StructureSynth "Hinxton".

Using the javascript interface, it should be possible to create some sort of animation here.

The position of spheres/jacks, within the frame are known, so if we create a map of those, and then randomly select (remove) positions, we could then place jack or sphere (alternately). Ideally though there needs to be some logic to assess a "winning line" to stop the animation, it should not be impossible.
However a chicken way out would be create a game sequence, consisting of a set of valid moves. Create a eisenscript for each move, and then call those scripts in sequence using the javascript interface.

   1 // Camera settings. Place these before first rule call.
   2 set translation [-0.0633663 0.0965309 -20]
   3 set rotation [0.888729 0.0811242 0.451178 -0.094785 0.995468 0.00771677 -0.448509 -0.0496248 0.892393]
   4 set pivot [0 0 0]
   5 set scale 0.4
   6 
   7 
   8 game
   9 
  10 set background #fff
  11 
  12 rule game{
  13   {h 20} frame
  14   {s 4 h 220} sphere::reflection
  15   {x -5 z -5 y -5 ry 45 rz 45 rx 45} jack
  16   {x 5 z 5 y 5 ry 45 rz 45 rx 45} jack
  17 }
  18 
  19 
  20 rule frame maxdepth 2{
  21   cross
  22   {ry 90} frame
  23 }
  24 
  25 rule cross maxdepth 2{
  26   four
  27   {rz 90} cross
  28 }
  29 
  30 rule four{
  31  {y -2.5 z -2.5}bar
  32  {y -2.5 z 2.5}bar
  33  {y 2.5 z -2.5}bar
  34  {y 2.5 z 2.5}bar
  35 }
  36 
  37 rule bar{
  38   {s 14 0.5 0.5} box::phong
  39 }
  40   
  41 rule jack maxdepth 3{
  42   arm
  43   {ry 90}jack
  44   {rz 90}jack
  45 }
  46 
  47 rule arm maxdepth 2{
  48   5 *{x 0.28284271} sphere::phong
  49   {fx} arm
  50 }
  51 
  52 set raytracer::max-threads 2
  53 set raytracer::ambient-occlusion-samples 20
  54 set raytracer::size [600x0]
  55 set raytracer::shadows true
  56 set raytracer::phong [0.6,0.6,0.3]
  57 set raytracer::reflection 0.8

Rendered using built in raytracer






















Here is my experiment with the groovelock sunflow template (using mirror property for the ball)

Rendered in sunflow with groovelock template

Tuesday, 16 November 2010

Experimenting with eisenscript syntax

Here I experiment with the eisenscript flip (fx) command using faux recursion (md = 2), and the set raytracer::size instruction.

   1 // Camera settings. Place these before first rule call.
   2 set translation [0.0633663 0.0987654 -20]
   3 set rotation [0.737822 0.498871 -0.454654 -0.613818 0.776162 -0.144459 0.280819 0.385657 0.878888]
   4 set pivot [0 0 0]
   5 set scale 0.55
   6 
   7 set background gray
   8 
   9 balljack
  10 
  11 rule balljack{
  12 {x -4 s 2.1} box::phong
  13 {rz 30 ry 30} jack
  14   {x 4 s 2.1} sphere::reflection
  15   }
  16 
  17 rule jack{
  18 arm
  19 {ry 90}arm
  20 {rz 90}arm
  21 }
  22 
  23 rule arm md 2{
  24 5 *{x 0.28284271} sphere::phong
  25 {fx}arm  // trying the flip option 
  26 }
  27 
  28 set raytracer::size [600x0]  // nb using 0 to preserve aspect ratio
  29 set raytracer::samples 8
  30 set raytracer::max-threads 2
  31 set raytracer::reflection 0.4
  32 set raytracer::phong [0.6,0.6,0.3]
  33 
  34 
  35 

StructureSynth rendered

Sunday, 14 November 2010

Refactored cage.es with more bars

   1 // Camera settings. Place these before first rule call.
   2 set translation [-0.824668 0.0267332 -20]
   3 set rotation [0.765594 -0.375725 0.522327 0.620534 0.216121 -0.754077 0.170438 0.901452 0.39863]
   4 set pivot [0 0 0]
   5 set scale 2.35879
   6 
   7 cage
   8 
   9 rule cage {
  10   ring
  11  {rx 30} ring
  12  {rx 60} ring
  13  {rx 90} ring
  14  {rx 120} ring
  15  {rx 150} ring
  16  {ry 90 rz 90} ring
  17 }
  18 
  19 rule ring md  36{
  20 {s 0.16 x 4.9} sphere
  21  { rz 10} ring
  22 }
  23 
  24 set raytracer::size[0x600]
  25 set raytracer::max-threads 2
  26 set raytracer::light [0,0,-29]
  27 set raytracer::samples 8
  28 set raytracer::max-depth 5
  29 set raytracer::reflection 0.5

Spherical Cage In StructureSynth

According to the latest svn update the "Hinxton" release of Structure Synth will be version 1.5.0.
Here is the spherical cage of my previous post "realized", now I've just got to figure out how to animate it!!!

   1 // Camera settings. Place these before first rule call.
   2 set translation [0 -0.367113 -20]
   3 set rotation [-0.930895 -0.133324 -0.340329 -0.346242 0.0230767 0.938039 -0.117209 0.991068 -0.067656]
   4 set pivot [0 0 0]
   5 set scale 1.45879
   6 
   7 yring
   8 xring
   9 zring
  10 
  11 rule yring md  12{
  12 {s 1 x 1.83} sphere
  13  {rz 30 y 0} yring
  14 }
  15 
  16 rule xring {
  17  {rx 90} yring
  18 }
  19 
  20 rule zring {
  21  {rz 90} xring
  22 }
  23 
  24 set raytracer::ambient-occlusion-samples 8
  25 set raytracer::max-depth 5
  26 set raytracer::reflection 0.5


Saturday, 13 November 2010

Spheres

Here is an idea I had for creating an eisencript (yet to be realized), that is based on a processing sketch by Ira Greenberg from "Creative Coding and Computational Art". I also used the sketch to test using ffmpeg to encode the video (results in need of some refinement but it is damn quick).


Spheres from monkstone on Vimeo.

   1 import processing.opengl.*;
   2 
   3 // Interlocking Sphere Rings
   4 float radius = 150.0;
   5 int segments = 12;
   6 float sphereSize = 42;
   7 void setup() {
   8   size(640, 480, OPENGL);
   9   setupOpenGL();
  10   noStroke();
  11   fill(255);
  12   sphereDetail(24);
  13 }
  14 
  15 void draw() {
  16   background(0);
  17   lights();
  18   translate(width/2, height/2);
  19   rotateY(frameCount*PI/100);
  20   rotateX(frameCount*PI/92);
  21   float x, y, z;
  22   for(int i=0; i<3; i++) {
  23     float ang = 0;
  24     for(int j=0; j<segments; j++) {
  25       pushMatrix();
  26       if (i==0) {
  27         x = cos(ang)*radius;
  28         y = sin(ang)*radius;
  29         z=0;
  30       }
  31       else if (i==1) {
  32         x = cos(ang)*radius;
  33         z = sin(ang)*radius;
  34         y=0;
  35       }
  36       else {
  37         y = cos(ang)*radius;
  38         z = sin(ang)*radius;
  39         x=0;
  40       }
  41       translate(x, y, z);
  42       sphere(sphereSize);
  43       popMatrix();
  44       ang+=TWO_PI/segments;
  45     }
  46   }
  47   saveFrame("img####.jpg");
  48 }
  49 
  50 void setupOpenGL(){
  51   hint(DISABLE_OPENGL_ERROR_REPORT);
  52   hint(ENABLE_OPENGL_4X_SMOOTH);
  53 }

Creating the movie using ffmpeg:-

ffmpeg -f image2 -i img0%3d.jpg movie.mp4

.....................

Tuesday, 9 November 2010

A more complicated Cube Variant (StructureSynth)

   1 // Camera settings. Place these before first rule call.
   2 set translation [-0.464996 0.199158 -20]
   3 set rotation [-0.828686 0.413368 0.377243 -0.0922356 -0.765772 0.636483 0.551983 0.492647 0.672715]
   4 set pivot [0 0 0]
   5 set scale 1.45
   6 
   7 set background white 
   8 
   9 ecube
  10 
  11 rule ecube md 3 > scube {
  12 { x 1 y 1 z 1 s 1/2 } ecube
  13 { x -1 y 1 z 1 s 1/2 } ecube
  14 { x 1 y -1 z 1 s 1/2 } ecube
  15 { x -1 y -1 z 1 s 1/2 } ecube
  16 { x 1 y 1 z -1 s 1/2 } ecube
  17 { x -1 y 1 z -1 s 1/2 } ecube
  18 { x 1 y -1 z -1 s 1/2 } ecube
  19 { x -1 y -1 z -1 s 1/2 } ecube
  20 }
  21 
  22 rule scube {
  23  {s 4 h 220}box
  24 }
  25 
  26 rule scube {
  27 {h 5} sphere
  28  6 * {h 5 x 0.3}sphere
  29  6 * {h 5 x -0.3}sphere
  30 }
  31 
  32 rule scube md 3 > cube {
  33 { x 1 y 1 z 1 s 1/2 } scube
  34 { x -1 y 1 z 1 s 1/2 } scube
  35 { x 1 y -1 z 1 s 1/2 } scube
  36 { x -1 y -1 z 1 s 1/2 } scube
  37 { x 1 y 1 z -1 s 1/2 } scube
  38 { x -1 y 1 z -1 s 1/2 } scube
  39 { x 1 y -1 z -1 s 1/2 } scube
  40 { x -1 y -1 z -1 s 1/2 } scube
  41 }
  42 
  43 rule cube {
  44 {h 5} sphere
  45  6 * {h 5 x 0.3}sphere
  46  6 * {h 5 x -0.3}sphere
  47 }
  48 
  49 rule cube {
  50  {s 4 h 220}box
  51 }

Sunflow Rendered

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