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, 6 March 2011

Alhambra Tiling in processing.py (Version 4) using lerp in a python module

I was just messing with my Alhambra sketch and found that rather surprisingly (to me but I'm no python buff so easily surprised) I had access to processing functions (notably lerp here) in a module (ie similar to the inner class access in vanilla processing). This contrasts somewhat with ruby-processing where Jeremy Ashkenas came up with a Processing::Proxy mixin to achieve the same type of access. You will find that if you substitute the following tpoint module in place of the one in my version 3, you get the same result. Or change the ratio in the Alhambra sketch to distort the tiles somewhat.

   1 """
   2 tpoint.py is module that contains my lighweight TPoint class
   3 avoids accessors by having public attributes (as python default)
   4 """
   5 
   6 class TPoint(object):
   7     """
   8     A lightweight convenience class to store triangle point data
   9     With a function to return new instance a the mid point between 
  10     two TPoint objects
  11     """
  12     
  13     def __init__(self, x = 0, y = 0):
  14         """
  15         Initialise the new TPoint object
  16         """
  17         self.x = x
  18         self.y = y 
  19        
  20         
  21     def mid_point(self, tvector, ratio = 0.5):
  22         """
  23         Returns a linear interpolation point where ratio of length from current point to
  24         input point is a ratio, default yields the mid point (lerp is a processing function)
  25         To make sense the ratio value should be less than 1.0 in practice you can use bigger
  26         values, it just skews the point in a different way.
  27         """
  28         return TPoint(lerp(self.x, tvector.x, ratio), lerp(self.y, tvector.y, ratio))
  29 
  30         
  31     def add(self, tvector):
  32         """
  33         Adds tvector TPoints to self
  34         """
  35         self.x += tvector.x
  36         self.y += tvector.y

Of course when you run the sketch you will find that your tpoint module has been compiled to tpoint$py.class, so I guess this is treated as an "inner class"? My feeble attempts at decompiling the code with jode heven't worked yet...
I suppose I need to find the enclosing class (wherever that gets stored, I should check tmp? Actually there is jffi***.tmp file produced but that's not much use).

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