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

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 }

No comments:

Post a Comment

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