1//
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) INRIA
4// Copyright (C) DIGITEO - 2010 - Allan CORNET
5//
6// This file is distributed under the same license as the Scilab package.
7//
8
9funcprot(0);
10
11function demo_riemann()
12
13    global quit_var;
14    global pause_var;
15
16    quit_var  = 0;
17    pause_var = 0;
18
19    // Figure creation
20    // =========================================================================
21    my_handle = scf(100001);
22    clf(my_handle, "reset");
23
24    // Add "see code" menu item
25    // =========================================================================
26    demo_viewCode(SCI+"/modules/graphics/demos/anim/anim8/anim8.sci");
27
28    // Drawlater
29    // =========================================================================
30    my_handle.immediate_drawing = "off";
31
32    // Colormap
33    // =========================================================================
34    my_handle.color_map = rainbowcolormap(128);
35
36    // Compute
37    // =========================================================================
38    [z,s]               = cplxroot(4,35);
39
40    // Draw
41    // =========================================================================
42    cplxmap(z,s,163,69);  //draw
43
44    // Adjust some graphical parameters
45    // =========================================================================
46    my_axe               = gca();
47    my_fac3d             = gce();
48
49    // my_handle.axes_size  = [ 600 650 ];
50
51    my_handle.background = -2;                 // white
52    my_axe.background    = -1;                 // gray
53    my_axe.foreground    = 14;                 // white
54    my_fac3d.color_mode  =  1;                 // no lines
55
56    // Drawnow
57    // =========================================================================
58    my_handle.immediate_drawing = "on";
59
60    // Stop => Pushbutton
61    // =========================================================================
62
63    my_quit_button = uicontrol( ..
64    "parent"              , my_handle, ..
65    "style"               , "pushbutton", ..
66    "string"              , "QUIT", ..
67    "units"               , "pixels", ..
68    "position"            , [ 350 15 100 30 ], ..
69    "background"          , [0.9 0.9 0.9], ..
70    "Relief"              , "groove", ..
71    "callback"            , "quit_riemann", ..
72    "callback_type"       , 10, ..
73    "tag"                 , "pushbutton_bac" ..
74    );
75
76    my_pause_button = uicontrol( ..
77    "parent"              , my_handle, ..
78    "style"               , "pushbutton", ..
79    "string"              , "PAUSE", ..
80    "units"               , "pixels", ..
81    "position"            , [ 150 15 100 30 ], ..
82    "background"          , [0.9 0.9 0.9], ..
83    "Relief"              , "groove", ..
84    "callback_type"       , 10, ..
85    "callback"            , "pause_riemann", ..
86    "tag"                 , "my_pause_button" ..
87    );
88
89    my_play_button = uicontrol( ..
90    "parent"              , my_handle, ..
91    "style"               , "pushbutton", ..
92    "string"              , "PLAY", ..
93    "units"               , "pixels", ..
94    "position"            , [ 150 15 100 30 ], ..
95    "background"          , [0.9 0.9 0.9], ..
96    "callback"            , "play_riemann", ..
97    "callback_type"       , 10, ..
98    "Relief"              , "groove", ..
99    "visible"             , "off", ..
100    "tag"                 , "my_play_button" ..
101    );
102
103    realtimeinit(0.01);
104
105    my_rotation_dir = [0 1];
106    my_counter      = 0;
107
108    for k = 1:10000
109
110        if quit_var == 1 then
111            if isHandleExistAndValid("my_handle") then
112                delete(my_handle);
113            end
114            return;
115        end
116
117        if pause_var == 1 & ~isHandleExistAndValid("my_handle") then
118            return;
119        end
120
121        realtime(k);
122
123        if isHandleExistAndValid("my_pause_button") & ..
124            isHandleExistAndValid("my_pause_button") & ..
125            isHandleExistAndValid("my_quit_button") & ..
126            isHandleExistAndValid("my_handle") then
127
128            if pause_var == 1 then
129                my_play_button.visible = "on";
130                my_pause_button.visible = "off";
131            end
132
133            if pause_var == 0 then
134                if my_pause_button.visible == "off" then
135                    my_play_button.visible   = "off";
136                    my_pause_button.visible  = "on";
137                end
138
139                my_axe.rotation_angles = my_axe.rotation_angles + my_rotation_dir;
140                my_counter = my_counter + 1;
141            end
142
143            if modulo(my_counter,720) == 0 then
144                my_rotation_dir = [0 1];
145            elseif modulo(my_counter,360) == 0 then
146                my_rotation_dir = [1 0];
147            end
148        else
149            quit_var = 1;
150        end
151    end
152
153endfunction
154
155
156function cplxmap(z, w, varargin)
157
158    //cplxmap(z,w,T,A,leg,flags,ebox)
159    //cplxmap Plot a function of a complex variable.
160    //       cplxmap(z,f(z))
161
162    x            = real(z);
163    y            = imag(z);
164    u            = real(w);
165    v            = imag(w);
166
167    my_handle    = gcf();
168    my_color_map = my_handle.color_map;
169    ncols        = size(my_color_map, "r");
170
171    [X, Y, U]    = nf3d(x, y, u);
172    [X, Y, V]    = nf3d(x, y, v);
173    Colors       = sum(V, "r");
174    Colors       = Colors - min(Colors);
175    Colors       = int((ncols-1) * Colors / max(Colors) + 1);
176
177    plot3d(X, Y, list(U, Colors), varargin(:));
178
179endfunction
180
181function [z, s] = cplxroot(n, m)
182
183    //cplxroot(n,m,T,A,leg,flags,ebox)
184    //CPLXROOT Riemann surface for the n-th root.
185    //       CPLXROOT(n) renders the Riemann surface for the n-th root.
186    //       CPLXROOT, by itself, renders the Riemann surface for the cube root.
187    //       CPLXROOT(n,m) uses an m-by-m grid.  Default m = 20.
188    // Use polar coordinates, (r,theta).
189    // Cover the unit disc n times.
190    // Copyright INRIA
191
192    [lhs, rhs] = argn(0);
193
194    if rhs  < 1, n = 3; end
195    if rhs  < 2, m = 20; end
196
197    r = (0:m)'/m;
198    theta = - %pi*(-n*m:n*m)/m;
199    z = r * exp(%i*theta);
200    s = r.^(1/n) * exp(%i * theta/n);
201
202endfunction
203
204function quit_riemann
205    global quit_var;
206    quit_var = 1;
207endfunction
208
209function pause_riemann
210    global pause_var;
211    pause_var = 1;
212endfunction
213
214function play_riemann
215    global pause_var;
216    pause_var = 0;
217endfunction
218
219function bOK = isHandleExistAndValid(handleName)
220    bOK = is_handle_valid(evstr(handleName)) & (type(evstr(handleName)) == 9) & exists(handleName);
221endfunction
222
223funcprot(1);
224