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, 19 June 2011

A recursive spiral in pyprocessing

Get pyprocessing here.

   1 """
   2  spiral.py pyprocessing sketch
   3  features fairly extreme recursion fot
   4  python hence need to increase limit
   5 """
   6 
   7 from pyprocessing import *
   8 
   9 MAX_RECURSION = 3451
  10 
  11 def setup():
  12     """
  13     processing setup
  14     """
  15     size(400, 400) 
  16     translate(100, 330) 
  17     rotate(0.3)
  18     fill(255, 0, 0, 0)
  19     background(0)
  20     noStroke()   
  21     smooth()
  22     fill(255, 0, 0, 20)# transparency makes for almost '3d' look
  23     import sys         # increase recursion limit or sketch will fail 
  24     sys.setrecursionlimit(MAX_RECURSION)
  25     try:               # handle potential index error
  26         shell(-0.008, 1.5, 25)
  27     except IndexError:
  28         print "Sketch exceeds set recursion limit"
  29     else:
  30         pass # Sketch finishes before recursion limit is reached
  31   
  32 def shell(rot, disp, sz):
  33     """
  34     Recursive shell shape limited by sz
  35     """
  36     REDUCE = 0.999  
  37     MIN_SIZE = 0.8   # about right for processing
  38     if (sz > MIN_SIZE):
  39         sz *= REDUCE 
  40         disp *= REDUCE
  41         translate(disp, 0)
  42         rotate(rot)
  43         ellipse(disp, 0, sz, sz)
  44         return shell(rot, disp, sz) # recursive call
  45     else: return # break recursive loop on size  
  46  
  47 run()

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