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

Sunday, 20 September 2009

Philip Sutton RA

My old mate Phil (could be thought of as a colourist in the Fauvist tradition) is having a bit of clear-out of some of his posters http://www.philipsuttonra.co.uk.
There is also a potted biography and chronology of his solo exhibitions.

Thursday, 17 September 2009

When Terminals Don't Matter (A Simpler Koch flake)

   1 //simpler hexaflake.pde
   2 float X1 = 0.5;
   3 float X2 = 0.25;
   4 float Y1 = sqrt(3)/4;
   5 float Y2 = 0;
   6 float REDUCE = 0.3333;
   7 void setup(){
   8   size(1000, 1000);
   9   smooth(); 
  10   background(0);
  11   fill(255);
  12   noStroke();
  13   drawHexaflake(width/2, height/2, height/1.5);
  14 }
  15 
  16 void drawHexaflake(float cx, float cy, float sz){
  17   if (sz < 1){
  18     ellipse(cx, cy, sz, sz);
  19     noLoop();   
  20   }
  21   else{     
  22     float x0 = cx - (X1 * sz);
  23     float y0 = cy;
  24     float x1 = cx - (X2 * sz);
  25     float y1 = cy  - (Y1 *sz);
  26     float x2 = cx + (X2 * sz);
  27     float y2 = cy  - (Y1 *sz);
  28     float x3 =  cx + (X1 * sz); 
  29     float y3 = cy;
  30     float x4 = cx + (X2 * sz);
  31     float y4 = cy + (Y1 * sz);
  32     float x5 = cx - (X2 * sz);
  33     float y5 = cy + (Y1 * sz);
  34     drawHexaflake(x0, y0, sz*REDUCE);
  35     drawHexaflake(x1, y1, sz*REDUCE);
  36     drawHexaflake(x2, y2, sz*REDUCE);
  37     drawHexaflake(x3, y3, sz*REDUCE);
  38     drawHexaflake(x4, y4, sz*REDUCE);
  39     drawHexaflake(x5, y5, sz*REDUCE);
  40   }
  41 }

Terminals don't really matter at this resolution.

Koch flake, the hard way

   1 // hexaflake.pde
   2 float X1 = 0.5;
   3 float X2 = 0.25;
   4 float Y1 = sqrt(3)/4;
   5 float Y2 = 0;
   6 float REDUCE = 0.3333;
   7 void setup(){
   8   size(500, 500);
   9   smooth(); 
  10   background(0);
  11   fill(255);
  12   noStroke();
  13   drawHexaflake(width/2, height/2, height/1.5);
  14 }
  15 
  16 void drawHexaflake(float cx, float cy, float sz){
  17   if (sz < 5){
  18     noLoop();   
  19   }
  20   else{
  21      drawHexagon(cx, cy, sz);
  22     float x0 = cx - (X1 * sz);
  23     float y0 = cy;
  24     float x1 = cx - (X2 * sz);
  25     float y1 = cy  - (Y1 *sz);
  26     float x2 = cx + (X2 * sz);
  27     float y2 = cy  - (Y1 *sz);
  28     float x3 =  cx + (X1 * sz); 
  29     float y3 = cy;
  30     float x4 = cx + (X2 * sz);
  31     float y4 = cy + (Y1 * sz);
  32     float x5 = cx - (X2 * sz);
  33     float y5 = cy + (Y1 * sz);
  34     drawHexaflake(x0, y0, sz*REDUCE);
  35     drawHexaflake(x1, y1, sz*REDUCE);
  36     drawHexaflake(x2, y2, sz*REDUCE);
  37     drawHexaflake(x3, y3, sz*REDUCE);
  38     drawHexaflake(x4, y4, sz*REDUCE);
  39     drawHexaflake(x5, y5, sz*REDUCE);
  40   }
  41 }
  42 void drawHexagon(float cx, float cy, float sz){
  43   beginShape();
  44   vertex(cx - (X1 * sz), cy);
  45   vertex(cx - (X2 * sz), cy  - (Y1 *sz));
  46   vertex(cx + (X2 * sz), cy  - (Y1 *sz));
  47   vertex(cx + (X1 * sz), cy);
  48   vertex(cx + (X2 * sz), cy + (Y1 * sz));
  49   vertex(cx - (X2 * sz), cy + (Y1 * sz));
  50   endShape(CLOSE);
  51 }

Hexaflake based on hexagons (much more work than when implemented in context free when based on triangles)

However with a few changes to the code above it is easier to render the intermediate structure, using different colors/saturation/transparency (changing these with differing threshold sizes), best using HSB color mode.

Wednesday, 16 September 2009

Pentaflake Implemented in Processing

   1 // pentaflake.pde
   2 float X1 = 0.125*sqrt(10 + 2*sqrt(5));
   3 float X2 = 0.125*sqrt(10 - 2*sqrt(5));
   4 float Y1 = 0.125*(sqrt(5) - 1);
   5 float Y2 = 0.125*(sqrt(5) + 1);
   6 float REDUCE = 0.385;
   7 void setup(){
   8   size(500, 500);
   9   smooth();
  10   fill(255);
  11   background(0);
  12   noStroke();
  13   drawPentaflake(width/2, height*0.55, height*0.55);
  14 }
  15 
  16 void drawPentaflake(float cx, float cy, float sz){
  17   if (sz < 6)
  18   {
  19     drawPentagon(cx, cy, sz);
  20     noLoop();
  21   }
  22   else{
  23     float x0 = cx;
  24     float y0 = cy - (0.5 * sz);
  25     float x1 = cx - (X1 * sz);
  26     float y1 = cy  -(Y1 *sz);
  27     float x2 = cx - (X2 * sz);
  28     float y2 = cy + (Y2 * sz);
  29     float x3 = cx + (X2 * sz);
  30     float y3 = cy + (Y2 * sz);
  31     float x4 = cx + (X1 * sz);
  32     float y4 = cy - (Y1 * sz);
  33     drawPentaflake(x0, y0, sz*REDUCE);
  34     drawPentaflake(x1, y1, sz*REDUCE);
  35     drawPentaflake(x2, y2, sz*REDUCE);
  36     drawPentaflake(x3, y3, sz*REDUCE);
  37     drawPentaflake(x4, y4, sz*REDUCE);
  38   }
  39 }
  40 
  41 void drawPentagon(float cx, float cy, float sz){
  42   beginShape();
  43   vertex(cx, cy - (0.5 * sz));
  44   vertex(cx - (X1 * sz),cy  -(Y1 *sz));
  45   vertex(cx - (X2 * sz), cy + (Y2 * sz));
  46   vertex(cx + (X2 * sz), cy + (Y2 * sz));
  47   vertex(cx + (X1 * sz), cy - (Y1 * sz));
  48   endShape(CLOSE);
  49 }

Tuesday, 15 September 2009

Emergent Structure in Context Free

The following rules can produce quite weak output just a few hexagons, on the other hand more complex structure can emerge, it is just a question of chance (to avoid over long recursion I have included one empty rule so the recursion could terminate very quickly, however it could still take a long time for some shapes to render).
   1 startshape begin
   2   
   3 tile { s 10 (10*sqrt(3)) }
   4 background{b -1}
   5 
   6 rule begin {hextiles{ h 240 sat 1 b 1 } }
   7  rule hextiles 1{ 
   8  hexagon {} 
   9  }
  10 rule hextiles 10{ 
  11 hexagon {} 
  12 hextiles { y (sqrt(3)) z 1 h 1 } 
  13 }
  14 rule hextiles 1.5{ 
  15 hextiles {flip 60}
  16 hextiles {flip 180}
  17 }
  18 rule hextiles 0.5{}
  19 
  20 path hexagon{
  21 MOVETO{x .25 y (sqrt(3)/4)}
  22 LINETO{x .5 y 0}
  23 LINETO{x .25 y (-sqrt(3)/4)}
  24 LINETO{x -.25 y (-sqrt(3)/4)}
  25 LINETO{x -.5 y 0}
  26 LINETO{x -.25 y (sqrt(3)/4)}
  27 CLOSEPOLY{}
  28 STROKE{width 0.01 b -1}
  29 FILL{}
  30 } 
 
With the exception of the mainly pale green image, the other images rendered pretty quickly, as did those that produced a disappointing number of shapes (2, 4 etc). I prefer the outer two, where there are clearly emergent star, and larger pentagon structures emerging. Just for good measure here are four more images  generated with these rules.

Monday, 14 September 2009

One Liners in cfdg

   1 startshape S rule S{TRIANGLE{}TRIANGLE{r 180}8*{r 45}S[s .2 .5 y .5 b .3]}
 
Potent one liner in cfdg a variant of acorns.cfdg by kipling 

Sunday, 13 September 2009

Carpet Surprise

   1 startshape carpet
   2 
   3 background{b -.7}
   4 
   5 rule carpet{
   6 patch{sat .2 b .7 h -20}
   7 carpet{s .3333 y .3333}
   8 carpet{s .3333 x .3333 y .3333}
   9 carpet{s .3333 x .3333}
  10 carpet{s .3333 x .3333 y -.3333}
  11 carpet{s .3333 y -.3333}
  12 carpet{s .3333 x -.3333 y -.3333}
  13 carpet{s .3333 x -.3333}
  14 carpet{s .3333 x -.3333 y .3333}
  15 }
  16 
  17 rule patch{
  18 SQUARE{b -.1 s .3333 h 360 sat .3}
  19 }
  20 rule patch{
  21 hexagon{b .1 s .3333 h 220 sat .5}
  22 }
  23 rule patch{
  24 CIRCLE{b .1 s .3333 h 60 sat .8}
  25 }
  26 
  27 path hexagon{
  28 MOVETO{x .25 y (sqrt(3)/4)}
  29 LINETO{x .5 y 0}
  30 LINETO{x .25 y (-sqrt(3)/4)}
  31 LINETO{x -.25 y (-sqrt(3)/4)}
  32 LINETO{x -.5 y 0}
  33 LINETO{x -.25 y (sqrt(3)/4)}
  34 CLOSEPOLY{}
  35 STROKE{width 0.01 b -1}
  36 FILL{}
  37 }

Friday, 11 September 2009

Higher order polygons using paths in cfdg, and random tiling

   1 startshape test
   2 
   3 background{b -1}
   4 
   5 rule test{
   6 CIRCLE{s 1 b 1 hue 360 sat 1}
   7 hexagon{}
   8 }
   9 
  10 path hexagon{
  11 MOVETO{x .25 y (sqrt(3)/4)}
  12 LINETO{x .5 y 0}
  13 LINETO{x .25 y (-sqrt(3)/4)}
  14 LINETO{x -.25 y (-sqrt(3)/4)}
  15 LINETO{x -.5 y 0}
  16 LINETO{x -.25 y (sqrt(3)/4)}
  17 CLOSEPOLY{}
  18 STROKE{width 0.01 b -1}
  19 FILL{b .8 h 60 sat 1}
  20 } 

The use of expressions in the path allow us to define the points of the regular polygon on the unit circle, a further benefit of using path (you can achieve similar result using rule is the ability close the polygon, set the fill/stroke and decide how to join points bevel/roundjoin/miterjoin.






















Using the above path for a hexagon (not repeated below) you can create more complex patterns with tiling (the simplest here is just edge to edge, I also intend to try linking squares/triangle)
 1 startshape tiled
 2 tile {s 20 (10*sqrt(3))}
 3 background{b -.5}
 4 
 5 rule tiled{
 6 20*{x 1}{
 7 20*{y (sqrt(3)/2)}{
 8 hextile{}
 9 }
10 }
11 }
12 
13 rule hextile 1 {
14 hexagon{h 220}
15 }
16 
17 rule hextile 3 {
18 hexagon{h 360}
19 }
20 
21 rule hextile 6 {
22 hexagon{h 60}
23 }
 

 















In this case there is 10% probability of a blue hexagon, a 30% probability of a red hexagon and a 60% probability of a yellow hexagon (the numbers after the rule name give the probability weighting).

For a neater packing we need to create some new rules:-

 1 startshape tiled
 2 
 3 background{b -.5}
 4 rule tiled{
 5 15*{y (sqrt(3)/2)}{
 6 10*{x 1.5}{
 7 hextile{}
 8 hextile{x 1.5}
 9 }
10 }
11 }
12 
13 rule hextile {
14 hex{}
15 hex{x .75 y (sqrt(3)/4)}
16 }
17 
18 rule hex{
19 hexagon{h 60}
20 }
21 rule hex{
22 hexagon{h 220}
23 }
24 rule hex{
25 hexagon{h 360}
26 }

NB: I have omitted hexagon path which remains the same.


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