[opengtl-commits] [636] add Caleidoscope filter

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 636
Author:   cyrille
Date:     2009-03-16 16:41:36 +0100 (Mon, 16 Mar 2009)

Log Message:
-----------
add Caleidoscope filter

Added Paths:
-----------
    trunk/shiva-collections/filters/Caleidoscope.shiva


Added: trunk/shiva-collections/filters/Caleidoscope.shiva
===================================================================
--- trunk/shiva-collections/filters/Caleidoscope.shiva	                        (rev 0)
+++ trunk/shiva-collections/filters/Caleidoscope.shiva	2009-03-16 15:41:36 UTC (rev 636)
@@ -0,0 +1,55 @@
+<
+  parameters: <
+    count: <
+      label: "Count";
+      type: int;
+      minValue:1;
+      maxValue:20;
+      defaultValue:5;
+    >;
+    direction: <
+      label: "Direction";
+      type: float;
+      minValue:0.0;
+      maxValue:6.28;
+      defaultValue:0.0.;
+    >;
+    xcenter: <
+      label: "Center x";
+      type: float;
+    >;
+    ycenter: <
+      label: "Center y";
+      type: float;
+    >;
+  >;
+>;  
+kernel Caleidoscope
+{  
+  const float width = 500.0;
+  const float height = 500.0;
+  const float2 center = { width * xcenter, height * ycenter };
+  const float pi = 3.14159265358979323846;
+  const float angle = pi / count;
+  float length( float2 v)
+  {
+    v *= v;
+    return sqrt( v[0] + v[1] );
+  }
+  void evaluatePixel(image img, out pixel result)
+  {
+    float2 vec = result.coord - center;
+    float vec_length = length( vec );
+    float vec_angle = atan2(vec.y, vec.x) - direction;
+    while( vec_angle < 0 ) { vec_angle = 6.28 + vec_angle; }
+    float angle2 = fmod(vec_angle, angle);
+    float section = floor(vec_angle/angle);
+    if (fmod(section,2.0)>0.5) angle2 = angle-angle2;
+
+    result = img.sampleNearest(center+ vec_length * float2(cos(angle2 += direction), sin(angle2)));
+  }
+  region changed(region changed_input_region, int input_index, region input_DOD[])
+  {
+    return changed_input_region;
+  }
+}


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/