[arrayfire] 14/84: Cleaning up graphics examples

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Mon Jan 4 23:22:15 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch master
in repository arrayfire.

commit 687167b97202542bc1ab7bb0ab58c119d3c04edb
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Wed Dec 9 16:40:02 2015 -0500

    Cleaning up graphics examples
---
 examples/graphics/conway_pretty.cpp |  3 +--
 examples/graphics/fractal.cpp       |  8 ++------
 examples/graphics/plot3.cpp         |  6 ++----
 examples/graphics/surface.cpp       | 21 +++++++++------------
 4 files changed, 14 insertions(+), 24 deletions(-)

diff --git a/examples/graphics/conway_pretty.cpp b/examples/graphics/conway_pretty.cpp
index 5b40990..6a22189 100644
--- a/examples/graphics/conway_pretty.cpp
+++ b/examples/graphics/conway_pretty.cpp
@@ -84,7 +84,7 @@ int main(int argc, char *argv[])
             // Update state
             state = state * C0 + C1;
 
-            double fps = 5;
+            double fps = 30;
             while(timer::stop(delay) < (1 / fps)) { }
         }
     } catch (af::exception& e) {
@@ -101,4 +101,3 @@ int main(int argc, char *argv[])
     #endif
     return 0;
 }
-
diff --git a/examples/graphics/fractal.cpp b/examples/graphics/fractal.cpp
index a06084e..9ac5a86 100644
--- a/examples/graphics/fractal.cpp
+++ b/examples/graphics/fractal.cpp
@@ -22,12 +22,8 @@ array complex_grid(int width, int height, float zoom, float center[2])
 {
 
     // Generate sequences of length width, height
-    array x = (seq(double(height)) - double(height) / 2.0);
-    array y = (seq(double(width )) - double(width)  / 2.0);
-
-    // Tile the sequences to generate grid of image size
-    array X = tile(x.T(), y.elements(), 1) / zoom + center[0];
-    array Y = tile(y    , 1, x.elements()) / zoom + center[1];
+    array X = (iota(dim4(1, height), dim4(width , 1)) -  (float)height / 2.0) / zoom + center[0];
+    array Y = (iota(dim4(width , 1), dim4(1, height)) -  (float)width  / 2.0) / zoom + center[1];
 
     // Return the locations as a complex grid
     return complex(X, Y);
diff --git a/examples/graphics/plot3.cpp b/examples/graphics/plot3.cpp
index ea2ca8d..93b8b8d 100644
--- a/examples/graphics/plot3.cpp
+++ b/examples/graphics/plot3.cpp
@@ -25,13 +25,12 @@ int main(int argc, char *argv[])
 
         static float t=0.1;
         array Z = seq( 0.1f, 10.f, PRECISION);
-        array bounds = constant(1, Z.dims());
 
         do{
             array Y = sin((Z*t) + t) / Z;
             array X = cos((Z*t) + t) / Z;
-            X = max(min(X, bounds),-bounds);
-            Y = max(min(Y, bounds),-bounds);
+            X = max(min(X, 1), -1);
+            Y = max(min(Y, 1), -1);
 
             array Pts = join(1, X, Y, Z);
             //Pts can be passed in as a matrix in the form n x 3, 3 x n
@@ -55,4 +54,3 @@ int main(int argc, char *argv[])
     #endif
     return 0;
 }
-
diff --git a/examples/graphics/surface.cpp b/examples/graphics/surface.cpp
index 92d5185..d59c66c 100644
--- a/examples/graphics/surface.cpp
+++ b/examples/graphics/surface.cpp
@@ -13,8 +13,8 @@
 
 using namespace af;
 
-static const int ITERATIONS = 30;
-static const float PRECISION = 1.0f/ITERATIONS;
+static const int POINTS = 30;
+static const int N = 2 * POINTS;
 
 int main(int argc, char *argv[])
 {
@@ -23,19 +23,17 @@ int main(int argc, char *argv[])
         af::info();
         af::Window myWindow(800, 800, "3D Surface example: ArrayFire");
 
-        array X = seq(-1, 1, PRECISION);
-        array Y = seq(-1, 1, PRECISION);
-        array Z = randn(X.dims(0), Y.dims(0));
+        // Creates grid of between [-1 1] with precision of 1 / POINTS
+        const array x = iota(dim4(N, 1), dim4(1, N)) / POINTS - 1;
+        const array y = iota(dim4(1, N), dim4(N, 1)) / POINTS - 1;
+
+        std::cout << x.dims()  << y.dims() << std::endl;
 
         static float t=0;
         while(!myWindow.close()) {
             t+=0.07;
-            //Z = sin(tile(X,1, Y.dims(0))*t + t) + cos(transpose(tile(Y, 1, X.dims(0)))*t + t);
-            array x = tile(X,1, Y.dims(0));
-            array y = transpose(tile(Y, 1, X.dims(0)));
-            Z = 10*x*-abs(y) * cos(x*x*(y+t))+sin(y*(x+t))-1.5;
-
-            myWindow.surface(X, Y, Z, NULL);
+            array z = 10*x*-abs(y) * cos(x*x*(y+t))+sin(y*(x+t))-1.5;
+            myWindow.surface(x, y, z);
         }
 
     } catch (af::exception& e) {
@@ -52,4 +50,3 @@ int main(int argc, char *argv[])
     #endif
     return 0;
 }
-

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git



More information about the debian-science-commits mailing list