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

Thursday, 29 October 2009

Fiery? random walk

fiery.cfdg
   1 startshape walk // a random walk
   2 
   3 background{b -1}
   4 
   5 rule walk{ // target yellow, increment by .16
   6 1000*{|hue 60}step{hue .16|}
   7 }
   8 
   9 rule step 30{
  10 step {x .5 y (sin(30) / sqrt(3)) r 60}
  11 }
  12 
  13 rule step 30{
  14 step{x -.5 y (sin(30) / sqrt(3)) r 60}
  15 }
  16 
  17 rule step 5{
  18 step{y (-1/sqrt(3)) r 60}
  19 }
  20 
  21 rule step {
  22 triangle{b .9 sat .9}
  23 } 
  24  
  25 path triangle {
  26     MOVETO {x -0.5 y (sin(-30) / sqrt(3))}
  27     3* {r 120} {
  28         CURVEREL {x 0.5 x1 0.25 y1 0.2}
  29         CURVEREL {x 0.5}
  30     }
  31     CLOSEPOLY {p align}
  32     FILL{}
  33     STROKE{width .01 b -1}
  34  }
 

 

Targeting a color (and some hexagon tiling)

   1 startshape start
   2 
   3 background{b -1}
   4 
   5 rule start{
   6  7*{y (sin(30)*12) |hue 135}{ // target green
   7  5*{x (cos(30)*12)}{
   8  rosette2{b 1 hue .4|} // increment hue by .4
   9  }
  10 }
  11 }
  12 
  13 rule rosette2{
  14 rosette{}
  15 rosette{x (cos(30)*6) y (sin(30)*6)}
  16 }
  17 
  18 rule rosette{ 
  19 6*{r 60}hexagon{y 2 b .1 sat .1}
  20 }
  21 
  22 path hexagon{
  23 MOVETO{x (cos (30)) y (sin(30))}
  24 6*{r 60}{
  25 LINETO{y 1}
  26 }
  27 CLOSEPOLY{p align}
  28 STROKE{width 0.04 b -1}
  29 FILL{b 1 sat 1}
  30 }


Wednesday, 28 October 2009

More is less (a simple flower)

When you run context free recursion is limited by the size of the smallest element (the default minimum size = 0.3 pixels). However there is a command line option -x which allows you to change the minimum size. For the image below I set that value to 10 pixels for aesthetic reasons.  In my next posts I intend to look at random walks and targeting a color.


   1 startshape flower 
   2 
   3 background{h 0 sat .15 b .22} // set color to red
   4 
   5 rule flower{
   6   6*{r 60}petal{b .7 sat .7 r 180 s .6 y .35 a -.3}
   7   flower{s .6 r -33 sat .1 b .1 h 4} // shift color towards a stronger yellow
   8 } 
   9 
  10 path petal {  
  11 MOVETO {x -0.5 y (sin(-30) / sqrt(3))}
  12 3* {r 120} {
  13 CURVEREL {x 0.5 x1 0.25 y1 0.1}
  14 CURVEREL {x 0.5}
  15 }
  16 CLOSEPOLY {p align}
  17 FILL{}
  18 STROKE{width .007 h 0 sat .9 b -.1} // paint border/vein
  19 }


Tuesday, 20 October 2009

Islamic tiling Using Processing

For more control over tile color I'm going back to processing, this is just the current version, expect some evolution here:-

   1 color[]tcolor = {    // array of tile colors
   2 color(229, 164, 23), // modulo 2 = 0 or 1
   3 color(107, 7, 93),   // we want gold or purple stars
   4 color(41, 127, 237),
   5 color(12, 100, 38), 
   6 color(107, 7, 93),
   7 color(41, 127, 237),
   8 color(12, 100, 38),
   9 color(229, 164, 23),
  10 color(41, 127, 237), 
  11 color(12, 100, 38) 
  12 }; 
  13 
  14 void setup(){
  15   size(1100, 1000);
  16   smooth();  
  17   noStroke();
  18   background(250);
  19   Tiler tiler = new Tiler();
  20   tiler.render();
  21   saveFrame("tiling.png");
  22 }
  23 
  24 class Tiler{
  25   float[]xValues = {
  26     100, 300, 500, 700, 900, 1100};
  27   float[]yValues = {
  28     50 * sqrt(3), 150 * sqrt(3), 250 * sqrt(3), 350 * sqrt(3), 450 * sqrt(3), 550 * sqrt(3)};
  29   TriangleRenderer tr;
  30   Tiler(){
  31     tr = new TriangleRenderer();
  32   }
  33 
  34   void render(){
  35     int col = 1;
  36     for (int column = 0; column <xValues.length; column++)
  37     { 
  38       for (int row = 0; row <yValues.length; row++){
  39         if ((column + row) > 9)
  40         col = (column + row) % 9;
  41         else col = column + row;
  42 
  43         if (row % 2 == 0) 
  44         {
  45           tr.drawTriangle(xValues[column], yValues[row], 200, col, 0.3);
  46         }
  47         else // offset tiles so that they tesselate
  48         {
  49           tr.drawTriangle(xValues[column] - 100, yValues[row], 200, col - 1, 0.3);
  50         }
  51       }
  52     }
  53   }
  54 }
  55 
  56 class TriangleRenderer{
  57   TriangleRenderer(){
  58   }
  59 
  60   void drawHexagon(float xpos, float ypos, float sz, float theta){
  61     beginShape();
  62     for (int i = 0; i < 6; i++){
  63       vertex(xpos + sz*cos((THIRD_PI * i) + theta), ypos + sz*sin((THIRD_PI * i) +theta));
  64     }
  65     endShape(CLOSE);
  66   }
  67 
  68   void drawHexagram(float xpos, float ypos, float sz, float theta){
  69     PVector hexPoints[] = new PVector[6];    
  70     for (int i = 0; i < 6; i++){
  71       hexPoints[i]= new PVector(xpos + sz*cos((THIRD_PI * i) + theta), ypos + sz*sin((THIRD_PI * i) +theta));
  72     }
  73     triangle(hexPoints[0].x, hexPoints[0].y, hexPoints[2].x, hexPoints[2].y, hexPoints[4].x, hexPoints[4].y);
  74     triangle(hexPoints[1].x, hexPoints[1].y, hexPoints[3].x, hexPoints[3].y, hexPoints[5].x, hexPoints[5].y);
  75   }
  76 
  77   void drawTriangle(float x0, float y0, float sz, int col, float disp){
  78     // Calculate  triangle points
  79     PVector[] pts = new PVector[12];
  80     pts[0] = new PVector(x0, y0 - sz/sqrt(3));                 // A
  81     pts[1] = new PVector(x0 - 0.5 * sz, y0 + (sqrt(3)*sz)/6);  // B
  82     pts[2] = new PVector(x0 + 0.5 * sz, y0 + (sqrt(3)*sz)/6);  // C
  83     pts[3] = getMidPoint(pts[0], pts[1]);                      // Ab
  84     pts[4] = getMidPoint(pts[1], pts[2]);                      // Bc
  85     pts[5] = getMidPoint(pts[0], pts[2]);                      // Ca
  86     pts[6] = getMidPoint(pts[0], pts[3]);                      // Aba
  87     adjustBezier(pts[6], THIRD_PI, disp*sz);                   // Aba
  88     pts[7] = getMidPoint(pts[3], pts[1]);                      // Abb
  89     adjustBezier(pts[7], THIRD_PI, -disp*sz);                  // Abb
  90     pts[8] = getMidPoint(pts[1], pts[4]);
  91     adjustBezier(pts[8], HALF_PI, -disp*sz);
  92     pts[9] = getMidPoint(pts[4], pts[2]);
  93     adjustBezier(pts[9], HALF_PI, disp*sz);
  94     pts[10] = getMidPoint(pts[2], pts[5]);
  95     adjustBezier(pts[10], -THIRD_PI, -disp*sz);
  96     pts[11] = getMidPoint(pts[5], pts[0]);
  97     adjustBezier(pts[11], -THIRD_PI, disp*sz);
  98     // set color and render triangle
  99     fill(tcolor[col]);
 100     beginShape();
 101     vertex(pts[0].x, pts[0].y);
 102     bezierVertex(pts[0].x, pts[0].y, pts[6].x, pts[6].y, pts[3].x, pts[3].y);
 103     bezierVertex(pts[3].x, pts[3].y, pts[7].x, pts[7].y, pts[1].x, pts[1].y);
 104     bezierVertex(pts[1].x, pts[1].y, pts[8].x, pts[8].y, pts[4].x, pts[4].y);
 105     bezierVertex(pts[4].x, pts[4].y, pts[9].x, pts[9].y, pts[2].x, pts[2].y);
 106     bezierVertex(pts[2].x, pts[2].y, pts[10].x, pts[10].y, pts[5].x, pts[5].y);
 107     bezierVertex(pts[5].x, pts[5].y, pts[11].x, pts[11].y, pts[0].x, pts[0].y);
 108     endShape(CLOSE);
 109     // set color and render small hexagon 
 110     fill(250);  
 111     drawHexagon(x0 + 5, y0, sz * 0.23, 0); // +5 aesthetic adjustment
 112     fill(tcolor[col % 2]);                 // using modulo 2 to yield only the first two colors in array
 113     drawHexagram(x0 - sz/2 - 5, y0 - sz * sqrt(3)/6, sz * 0.23, 0); // -5 aesthetic adjustment
 114   }
 115 
 116   void adjustBezier(PVector base, float theta, float disp){
 117     base.add(new PVector(cos(theta)*disp, sin(theta)*disp));
 118   }
 119 
 120   PVector getMidPoint(PVector a, PVector b){
 121     PVector mid = PVector.add(a, b);
 122     mid.div(2);
 123     return mid;
 124   }
 125 }
 

 

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