Add Bubble sort graphic demo. 09/8909/1
Bruno JOFRET [Mon, 3 Sep 2012 08:57:26 +0000 (10:57 +0200)]
Change-Id: I40f5585a831cb6437daa7521ee3b5e9bab0346bd

scilab/modules/graphics/demos/anim/anim.dem.gateway.sce
scilab/modules/graphics/demos/anim/bubbleSort/bubbleSort.sci [new file with mode: 0644]
scilab/modules/graphics/demos/anim/bubbleSort/bubbleSort_gateway.sce [new file with mode: 0644]

index 77a3cf6..73796b2 100644 (file)
@@ -13,11 +13,9 @@ subdemolist=[ ..
     "Rotation of a 3D contour"           ,"anim4/anim4_gateway.sce"; ..
     "Evolution of a 3D surface (plot3d)" ,"anim5/anim5_gateway.sce"; ..
     "N link pendulum movement"           ,"anim6/anim6_gateway.sce"; ..
-    "Shell"                              ,"anim7/anim7_gateway.sce"];
-
-if ~ usecanvas() then
-    subdemolist = [ subdemolist ; "Riemann surface","anim8/anim8_gateway.sce" ];
-end
+    "Shell"                              ,"anim7/anim7_gateway.sce"; ..
+    "Riemann surface"                    ,"anim8/anim8_gateway.sce"; ..
+    "Bubble Sort"                        ,"bubbleSort/bubbleSort_gateway.sce"];
 
 subdemolist(:,2) = demopath + subdemolist(:,2);
 clear demopath;
\ No newline at end of file
diff --git a/scilab/modules/graphics/demos/anim/bubbleSort/bubbleSort.sci b/scilab/modules/graphics/demos/anim/bubbleSort/bubbleSort.sci
new file mode 100644 (file)
index 0000000..45e8b2a
--- /dev/null
@@ -0,0 +1,36 @@
+//
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012-2012 - Scilab Enterprises - Bruno JOFRET
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+//
+//
+function demo_bubbleSort()
+    function res=bubbleSort(in, polyline)
+        for (i = 1:size(in, '*'))
+            for (j = 1:i)
+                if (in(i) < in(j))
+                    tmp = in(j);
+                    in(j) = in(i);
+                    in(i) = tmp;
+                    polyline.data(:,2) = in';
+                end
+            end
+        end
+        res = in;
+    endfunction
+
+    nbValues = 200;
+    x = floor(rand(1, nbValues) * nbValues);
+    scf()
+    demo_viewCode(SCI+"/modules/graphics/demos/anim/bubbleSort/bubbleSort.sci");
+    plot(x, "diamond-");
+    a = gca();
+    e = a.children(1).children(1);
+    x = bubbleSort(x, e);
+    delete(gcf())
+endfunction
diff --git a/scilab/modules/graphics/demos/anim/bubbleSort/bubbleSort_gateway.sce b/scilab/modules/graphics/demos/anim/bubbleSort/bubbleSort_gateway.sce
new file mode 100644 (file)
index 0000000..1698a8e
--- /dev/null
@@ -0,0 +1,14 @@
+//
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) INRIA
+//
+// This file is distributed under the same license as the Scilab package.
+//
+
+// =============================================================================
+// Demonstrate animation based on the dynamic of a chain
+// =============================================================================
+
+exec("SCI/modules/graphics/demos/anim/bubbleSort/bubbleSort.sci");
+demo_bubbleSort();
+clear demo_bubbleSort;