OSDN Git Service

111
[psychlops/silverlight.git] / test4 / PsychlopsMain.cs
1 \r
2 ///+ Prefix linkto BasicCode1\r
3 //// Lines for set up Psychlops environment\r
4 using Psychlops;\r
5 \r
6 namespace PsychlopsSilverlightApp\r
7 {\r
8 \r
9         public class PsychlopsMain\r
10         {\r
11                 ///- Prefix linkto BasicCode1\r
12 \r
13 \r
14                 ///+ Main Routine\r
15                 //// Psychlops runs at the first line of this function psychlops_main().\r
16                 public void psychlops_main()\r
17                 {\r
18 \r
19                         ///+ 0 SetGlobal\r
20                         ////Prepare global parameters\r
21                         Rectangle p1 = new Rectangle(1,1);\r
22                         Color col1 = new Color();\r
23                         double width=50;\r
24                         double height=10;\r
25                         double lambda=60;\r
26                         double lmean=0.25, contrast = 0.5;\r
27                         double x0 = 0;\r
28                         double y0 = 0;\r
29                     double pitch = 1;\r
30                         Canvas disp = new Canvas(Canvas.window, Display.secondary);\r
31                         \r
32                         var fieldW_ = Psychlops.Widgets.Browser.Element.byID("fieldW");\r
33                         var fieldH_ = Psychlops.Widgets.Browser.Element.byID("fieldH");\r
34                         var wL_     = Psychlops.Widgets.Browser.Element.byID("wL");\r
35                         var Cont_   = Psychlops.Widgets.Browser.Element.byID("Cont");\r
36                         var ix_     = Psychlops.Widgets.Browser.Element.byID("ix");\r
37                         var iy_     = Psychlops.Widgets.Browser.Element.byID("iy");\r
38                         var gap_    = Psychlops.Widgets.Browser.Element.byID("gap");\r
39                         ///- 0 SetGlobal\r
40 \r
41                         ///+ 1 Initialize\r
42                         ////initialize\r
43                         p1.centering().shift(-width*0.5 + x0, -height*0.5 + y0); //Move a point to the initial position.\r
44                         ///- 1 Initialize\r
45 \r
46                         ///+ 2 Drawing\r
47                          ////drawing objects\r
48                         for(int i=0; i < width; i++)\r
49                         {\r
50                                 col1.set(lmean*((contrast*Math.sin((2*Math.PI*i/lambda)))+1)); //Set a color.\r
51 \r
52                                 ///+ 2.1 Drawing a column\r
53                                 ////drawing a column\r
54                                 for(int j=0;j < height; j++)\r
55                                 {\r
56                                         p1.draw(col1);\r
57                                         p1.shift(0, pitch);\r
58                                 }\r
59                                 ///- 2.1 Drawing a column\r
60 \r
61                                 p1.shift(1, -height * pitch); //back to vertical intitial point after drawing one column.\r
62                         }\r
63                         disp.flip();\r
64                         ///- 2 Drawing\r
65 \r
66                         while (!Keyboard.spc.pushed()) { }; //Wait until space key is pressed.\r
67                 }\r
68 \r
69 \r
70         }\r
71 \r
72 }\r
73 \r
74 \r
75 /*\r
76 ///+ Prefix\r
77 //// Lines for set up Psychlops environment\r
78 using Psychlops;\r
79 \r
80 namespace PsychlopsSilverlightApp\r
81 {\r
82 \r
83         public class PsychlopsMain\r
84         {///- Prefix\r
85 \r
86 \r
87 \r
88                 ///+ Main Routine\r
89                 //// Psychlops runs at the first line of this function psychlops_main().\r
90                 public void psychlops_main()\r
91                 {\r
92                         Canvas window = new Canvas(300, 300); //Create a window. Here, window variables are preset mode.\r
93 \r
94                         var FIGURE = Psychlops.Widgets.Browser.Element.byID("FIGURE");\r
95                         var SIZE_X_ = Psychlops.Widgets.Browser.Element.byID("SIZE_X");\r
96                         var SIZE_Y_ = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");\r
97                         var COLOR_R = Psychlops.Widgets.Browser.Element.byID("COLOR_R");\r
98                         var COLOR_G = Psychlops.Widgets.Browser.Element.byID("COLOR_G");\r
99                         var COLOR_B = Psychlops.Widgets.Browser.Element.byID("COLOR_B");\r
100                         var COLOR_BG = Psychlops.Widgets.Browser.Element.byID("COLOR_BG");\r
101                         var Period_Size = Psychlops.Widgets.Browser.Element.byID("Period_Size");\r
102                         var Period_Position = Psychlops.Widgets.Browser.Element.byID("Period_Position");\r
103                         var Speed_HSize_ = Psychlops.Widgets.Browser.Element.byID("Speed_HSize");\r
104                         var Speed_VSize = Psychlops.Widgets.Browser.Element.byID("Speed_VSize");\r
105                         var Speed_VMotion = Psychlops.Widgets.Browser.Element.byID("Speed_VMotion");\r
106                         double SIZE_X = SIZE_X_, SIZE_Y = SIZE_Y_;\r
107 \r
108                         ///+ 2\r
109                         ////  Set a figure size, position and color.\r
110                         Rectangle figure = new Rectangle();\r
111                         Ellipse figure2 = new Ellipse();\r
112                         figure.set(SIZE_X_, SIZE_Y_); // Set the size of figure.\r
113                         figure2.set(SIZE_X_, SIZE_Y_); // Set the size of figure.\r
114                         figure.centering().shift(0, 0); // Move the figure to the starting point.\r
115                         figure2.centering().shift(0, 0); // Move the figure to the starting point.\r
116                         ///- 2\r
117 \r
118                         int frame = 0;\r
119                         int looming_direction = 1, motion_dir = 1;\r
120                         double direction = 1.0;\r
121                         //looming_direction is a variable for size change.\r
122                         //motion_dir is a variable for motion direction.\r
123                         ///+ 3 Drawing loop\r
124                         //// Draw each frames in a "while loop".\r
125                         while (!Keyboard.esc.pushed())\r
126                         { //exit a program when the escape key is pressed down.\r
127                                 window.clear(COLOR_BG); // Clear the window with a designated gray-scale level.\r
128 \r
129                                 ///+ 3.1\r
130                                 //// Calculate object's position and size for each frame.\r
131 \r
132                                 if (frame % Period_Size == 0)\r
133                                 { // a direction of size change will reverse at designated frames.\r
134                                         looming_direction = looming_direction * -1;\r
135                                 }\r
136 \r
137                                 if (frame % Period_Position == 0)\r
138                                 { // motion direction will reverse at designated frames.\r
139                                         motion_dir *= -1;\r
140                                 }\r
141 \r
142                                 ///- 3.1\r
143 \r
144                                 ///+ 3.2 \r
145                                 //// Settting figure's properties\r
146                                 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
147                                                                  figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".\r
148                                 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
149                                 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
150                                                                 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".\r
151                                 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
152                                 /*\r
153                                 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
154                                                          figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".\r
155                                 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
156                                 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
157                                                                 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".\r
158                                 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
159                                  * * /\r
160                                 ///- 3.2\r
161 \r
162                                 ///+ 3.3 \r
163                                 ////Drawing\r
164                                 if ("Rectangle".Equals(FIGURE))\r
165                                 {\r
166                                         figure.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.\r
167                                 }\r
168                                 else\r
169                                 {\r
170                                         figure2.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.\r
171                                 }\r
172                                 window.flip(); // Reflect the drawing for the display by flipping frame buffers.\r
173                                 ///- 3.3\r
174 \r
175                                 ///+ 3.4\r
176                                 ////make a step for next frames \r
177                                 frame++;\r
178                                 ///- 3.4\r
179                         }\r
180                         ///- 3 Drawing loop\r
181 \r
182                 }\r
183                 ///- Main Routine\r
184 \r
185 \r
186         }\r
187 \r
188 }\r
189 \r
190 \r
191 \r
192 /*\r
193 //The reversed-phi motion.\r
194 //Anstis (1970)\r
195 //Phi movement as a subtraction process. Vision Res 10:1411?1430\r
196 \r
197 ///+ Prefix\r
198 //// Include Psychlops Package\r
199 using Psychlops;\r
200 \r
201 namespace PsychlopsSilverlightApp\r
202 {\r
203 \r
204         public class PsychlopsMain\r
205         {\r
206 \r
207                 ///- Prefix\r
208 \r
209                 ///+ Stimulus drawing function\r
210                 //// A function for stimulus drawing (main body)\r
211                 void RectLuminance()\r
212                 {\r
213 \r
214                         ///+ Preperation\r
215                         //// Declare and initialize local variables\r
216                         double rect_size = 20;\r
217 \r
218                         double bg_lum = 0.5;\r
219                         double radii = 200;\r
220                         double rect_lum;\r
221                         int element_number = 25;\r
222                         int radial_row = 5;\r
223 \r
224                         double rotation_tf = 0.2;\r
225                         double polarity = 1;\r
226                         double rotation;\r
227 \r
228                         double contrastflag = 1;\r
229                         int period = 3;\r
230                         double refresh;\r
231 \r
232                         Canvas display = new Canvas(Canvas.window); //Prepare drawing window\r
233                         refresh = Display.getRefreshRate();\r
234 \r
235                         Ellipse rect = new Ellipse();\r
236                         rect.set(rect_size, rect_size);\r
237 \r
238                         Ellipse fixation = new Ellipse(5, 5);\r
239                         fixation.centering();\r
240 \r
241                         Letters let1 = new Letters("Press Space key to change stimulus type");\r
242                         let1.centering().shift(-180, 220);\r
243                         Letters let2 = new Letters("Phi");\r
244                         let2.centering().shift(-10, 200);\r
245                         Letters let3 = new Letters("Reversed-Phi");\r
246                         let3.centering().shift(-60, 200);\r
247 \r
248                         rotation = Math.random(2 * Math.PI);\r
249 \r
250                         ///+ user interface\r
251                         ////register variables to demo circumstances\r
252                         Interval rng = new Interval();\r
253 \r
254                         Psychlops.Widgets.Slider rect_contrast;\r
255                         rect_contrast = new Psychlops.Widgets.Slider("Contrast", 0.1 <= rng <= 1.0, 0.1);\r
256                         rect_contrast.value = 0.5;\r
257                         ///- user interface\r
258                         ///- Preperation\r
259 \r
260                         ///+ Main loop\r
261                         ////Main loop\r
262                         int frame = 0;\r
263                         //AppState::setThreadPriority(AppState::HIGH);\r
264                         while (true)\r
265                         {\r
266                                 frame++;\r
267                                 if (Keyboard.spc.pushed()) contrastflag = -contrastflag;\r
268                                 if (contrastflag < 0) polarity = -polarity;\r
269                                 rotation = 2 * Math.PI * rotation_tf * frame * period / refresh;\r
270 \r
271                                 for (int frame_now = 0; frame_now < period; frame_now++)\r
272                                 {\r
273                                         Display.clear(new Color(bg_lum));\r
274                                         for (int j = 0; j < radial_row; j++)\r
275                                         {\r
276                                                 rect.resize(rect_size * (j + radial_row) / 10.0, rect_size * (j + radial_row) / 10.0);\r
277                                                 for (double i = 0; i < element_number; i++)\r
278                                                 {\r
279                                                         rect_lum = bg_lum * (1.0 + polarity * rect_contrast);\r
280                                                         rect.centering().shift(radii * (j + radial_row) / 10.0 * Math.cos(rotation + i * 2 * Math.PI / element_number), radii * (j + radial_row) / 10.0 * Math.sin(rotation + i * 2 * Math.PI / element_number));\r
281                                                         rect.draw(rect_lum);\r
282                                                 }\r
283                                         }\r
284                                         fixation.draw(Color.red);\r
285                                         let1.draw();\r
286                                         if (contrastflag > 0) let2.draw();\r
287                                         else let3.draw();\r
288                                         Display.flip();\r
289                                 }\r
290                         }\r
291                         ///- Main loop\r
292                         //AppState::setThreadPriority(AppState::NORMAL);\r
293                 }\r
294                 ///- Stimulus drawing function\r
295 \r
296                 ///+ Main function for demo circumstances\r
297                 //// Psychlops Main function\r
298                 public void psychlops_main()\r
299                 {\r
300                         ///+ Demo circumstances\r
301                         //// Spells for run demonstration circumstances\r
302                         Procedure p = new Procedure();\r
303                         //p.setDesign(Procedure::DEMO); //Designate that this is a demo.\r
304                         p.setProcedure(RectLuminance);  //The argument name is a name of drawing function.\r
305                         p.run();\r
306                         ///- Demo circumstances\r
307                 }\r
308                 ///- Main function for demo circumstances\r
309 \r
310         }\r
311 \r
312 }\r
313 \r
314 \r
315 \r
316 /*\r
317 //Two types of plaid motion\r
318 //E. H. Adelson and J. A. Movshon (1982).\r
319 //Phenomenal coherence of moving visual patterns. Nature 300, 523-525\r
320 \r
321 ///+ Prefix\r
322 //// Include Psychlops Package\r
323 using Psychlops;\r
324 \r
325         namespace PsychlopsSilverlightApp\r
326         {\r
327 \r
328                 public class PsychlopsMain\r
329                 {\r
330                         ///- Prefix\r
331 \r
332                         ///+ Global\r
333                         // Struct for component paremeters\r
334                         struct component\r
335                         {\r
336                                 public double contrast;\r
337                                 public double orientation;\r
338                                 public double lambda;\r
339                                 public double tf;\r
340                         }\r
341                         ///- Global\r
342 \r
343                         ///+ Stimulus drawing function\r
344                         //// A function for stimulus drawing (main body)\r
345                         void drawgratingmovie(Image[] img, component c1, component c2, double contrast, int start, int maxframe, double bg_lum, double alpha)\r
346                         {\r
347                                 double _xp, _xp2, col1, col2;\r
348                                 double contrast1, contrast2;\r
349                                 double imageheight, imagewidth;\r
350 \r
351                                 contrast1 = contrast*c1.contrast/(c1.contrast+c2.contrast);\r
352                                 contrast2 = contrast*c2.contrast/(c1.contrast+c2.contrast);\r
353 \r
354                                 imageheight = img[0].getHeight();\r
355                                 imagewidth = img[0].getWidth();\r
356 \r
357                                 for(int frame=start; frame<start+maxframe+1; frame++){\r
358                                         //Display.progressbar(frame, maxframe+1);\r
359                                         //img[frame].convert(Image::RGBA);\r
360                                         for(int i=0; i<imagewidth; i++){\r
361                                                 for(int j=0; j<imageheight; j++){\r
362                                                         _xp = Math.sin(c1.orientation)*(i-imagewidth*0.5) + Math.cos(c1.orientation) * (j-imageheight *0.5);\r
363                                                         _xp2 = Math.sin(c2.orientation)*(i-imagewidth*0.5) + Math.cos(c2.orientation) * (j-imageheight *0.5);\r
364                                                         col1 = bg_lum*contrast1*Math.sin(2*Math.PI*_xp/c1.lambda + 2*Math.PI*c1.tf*frame/(double)refresh);\r
365                                                         col2 = bg_lum*contrast2*Math.sin(2*Math.PI*_xp2/c2.lambda + 2*Math.PI*c2.tf*frame/(double)refresh);\r
366                                                         img[frame].pix(i,j,new Color(col1+col2+bg_lum));\r
367                                                         img[frame].alpha(i,j,alpha);\r
368                                                 }\r
369                                         }\r
370                                         //img[frame].cache();\r
371                                 }\r
372                         }\r
373 \r
374                         ///+ Stimulus drawing function\r
375                         //// A function for stimulus drawing (main body)\r
376                         void drawplaid() {\r
377                                 Canvas display = new Canvas(Canvas.window);\r
378                                 ///+ Preperation\r
379                                 //// Declare and initialize local variables\r
380                                 int rect_size = 150;\r
381                                 double rect_lum  = 0.5;\r
382                                 double bg_lum    = 0.2;\r
383                                 double duration = 400;\r
384 \r
385                                 double[] lambda = new double[2], contrast = new double[2], tf = new double[2];\r
386                                 double center_orientation = 0.0;\r
387                                 Image[,] movie = StaticFunctions.NewArray<Image>(2, 120);\r
388                                 Image[,] component_movie = StaticFunctions.NewArray<Image>(4, 120);\r
389                                 Image envelope = new Image(), envelope_small = new Image();\r
390 \r
391                                 for(int i=0; i<120; i++)\r
392                                 {\r
393                                         movie[0, i].set(rect_size, rect_size);\r
394                                         movie[1, i].set(rect_size, rect_size);\r
395                                         component_movie[0, i].set(rect_size/2, rect_size/2);\r
396                                         component_movie[1, i].set(rect_size/2, rect_size/2);\r
397                                         component_movie[2, i].set(rect_size/2, rect_size/2);\r
398                                         component_movie[3, i].set(rect_size/2, rect_size/2);\r
399                                 }\r
400                                 envelope.set(rect_size, rect_size);\r
401                                 envelope_small.set(rect_size/2, rect_size/2);\r
402 \r
403                                 Letters let1 = new Letters(), let2 = new Letters(), let3 = new Letters();\r
404                                 let1.str = "Component1";\r
405                                 let2.str = "Component2";\r
406                                 let3.str = "Superposition";\r
407                                 let1.centering().shift(-rect_size*1.25, -rect_size);\r
408                                 //let1.cache();\r
409                                 let2.centering().shift(rect_size*1.25, -rect_size);\r
410                                 //let2.cache();\r
411                                 let3.centering().shift(0.0, rect_size*0.75);\r
412                                 //let3.cache();\r
413 \r
414                                 component c1, c2, c0;\r
415                                 c0 = new component{ 0.0,0.0,1.0,1.0 }; //dummy for component movie\r
416                                 ///+ type-I\r
417                                 // Prepare Type-I plaid movie\r
418                                 center_orientation = 0.0;\r
419                                 orientation_offset = Math.PI/6;\r
420                                 contrast[0] = 1.0, contrast[1] = 1.0;\r
421                                 lambda[0] = 30.0, lambda[1] = 30.0;\r
422                                 tf[0] = 1.0; tf[1] = 1.0;\r
423 \r
424                                 c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};\r
425                                 c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};\r
426 \r
427                         drawgratingmovie(movie[0],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
428                         drawgratingmovie(component_movie[0],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
429                         drawgratingmovie(component_movie[1],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);\r
430                         ///- type-I\r
431 \r
432                         ///+ type-II\r
433                         // Prepare Type-II plaid movie\r
434                         center_orientation = -0.0, orientation_offset = Math.PI/12;\r
435                         contrast[0] = 1.0, contrast[1] = 1.0;\r
436                         lambda[0] = 30.0, lambda[1] = 30.0;\r
437                         tf[0] = 1.0; tf[1] = 4.0;\r
438 \r
439                         c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};\r
440                         c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};\r
441 \r
442                         drawgratingmovie(movie[1],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
443                         drawgratingmovie(component_movie[2],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
444                         drawgratingmovie(component_movie[3],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);\r
445                         ///- type-II\r
446 \r
447                         ///+ gaussian\r
448                         //draw Gaussian envelopes\r
449                         envelope.clear(new Color(bg_lum)); //clear offscreen image\r
450                         double _x, _y;\r
451                         for(int i=0; i<rect_size; i++){\r
452                         _x=i-0.5*rect_size;\r
453                         for(int j=0; j<rect_size; j++){\r
454                         _y=j-0.5*rect_size;\r
455                         envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/6.0, 2.0) ))));\r
456                         }\r
457                         }\r
458 \r
459                         envelope_small.clear(new Color(bg_lum)); //clear offscreen image\r
460                         for(int i=0; i<rect_size*0.5; i++){\r
461                         _x=i-0.25*rect_size;\r
462                         for(int j=0; j<rect_size*0.5; j++){\r
463                         _y=j-0.25*rect_size;\r
464                         envelope_small.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/12.0, 2.0) ))));\r
465                         }\r
466                         }\r
467                         envelope.cache(); //send offscreen image from main memory to GPU\r
468                         envelope_small.cache(); //send offscreen image from main memory to GPU\r
469                         ///- gaussian\r
470 \r
471                         ///+ user interface\r
472                         // Draw user interface\r
473                         Widgets::SelectBox stimulus_type;\r
474                         stimulus_type.area.set(120, 20);\r
475                         stimulus_type.append(L"TypeI");\r
476                         stimulus_type.append(L"TypeII");\r
477                         stimulus_type.centering().shift(-120.0,250.0);\r
478 \r
479                         Psychlops::Widgets::SelectBox stimulus_type2;\r
480                         stimulus_type2.area.set(120, 20);\r
481                         stimulus_type2.append(L"Continuous");\r
482                         stimulus_type2.append(L"Periodic");\r
483                         stimulus_type2.centering().shift(120.0,250.0);\r
484 \r
485                         Psychlops::Widgets::Slider duration_slider;\r
486                         duration_slider.area.set(100,20);\r
487                         duration_slider.centering().shift(120,280.0);\r
488                         Interval rng = new Interval();\r
489                         duration_slider.link(duration, 50<=rng<=950, 50.0, 50.0);\r
490                         ///- user interface\r
491                         ///- Preperation\r
492 \r
493                         ///+ Main loop\r
494                         int frame = 0;\r
495                         int period = refresh_int;\r
496                         int movienum;\r
497                         while(!Keyboard.esc.pushed()) {\r
498                         Display.clear(new Color(bg_lum));\r
499                         movienum = stimulus_type.getSelected(); //if "Type-I" is selected, 0, else frame refresh per sec\r
500 \r
501                         in;\r
502                         else period = refresh_int;\r
503 \r
504                         if(frame>0){\r
505                         movie[movienum, frame].centering().draw();\r
506                         envelope.centering().draw();\r
507                         component_movie[movienum*2, frame].centering().shift(-rect_size*0.5, -rect_size).draw();\r
508                         envelope_small.centering().shift(-rect_size*0.5, -rect_size).draw();\r
509                         component_movie[movienum*2+1, frame].centering().shift(rect_size*0.5, -rect_size).draw();\r
510                         envelope_small.centering().shift(rect_size*0.5, -rect_size).draw();\r
511                         }\r
512 \r
513                         ///+ draw user interface\r
514                         let1.draw(0.75);\r
515                         let2.draw(0.75);\r
516                         let3.draw(0.75);\r
517                         stimulus_type.draw();\r
518                         stimulus_type2.draw();\r
519                         if(stimulus_type2.getSelected())duration_slider.draw();\r
520                         ///- draw user interface\r
521                         Display.flip();\r
522                         if(frame++ >= period) frame -= refresh_int;\r
523                         }\r
524                         ///- Main loop\r
525 \r
526                         }\r
527                         ///- Stimulus drawing function\r
528 \r
529                 ///+ Main function for demo circumstances\r
530                 public void psychlops_main() {\r
531                         ///+ Demo circumstances\r
532                         //// Spells for run demonstration circumstances\r
533                         Procedure p = new Procedure();\r
534                         //p.setDesign(Procedure::DEMO); //Designate that this is a demo.\r
535                         p.setProcedure(drawplaid);  //The argument name is a name of drawing function.\r
536                         p.run();\r
537                         ///- Demo circumstances\r
538                 }\r
539         }\r
540 }\r
541 */\r
542 \r
543 \r
544 /*\r
545 using Psychlops;\r
546 //Position Bias Program\r
547 namespace PsychlopsSilverlightApp\r
548 {\r
549 \r
550     public class PsychlopsMain\r
551     {\r
552         Canvas cnvs;\r
553         Image img, img2, img3;\r
554         int isize = 40;        \r
555         int frames;\r
556         Psychlops.Widgets.Slider tfreq;\r
557         Psychlops.Widgets.Slider contrast;\r
558         Psychlops.Widgets.Slider lambda;\r
559                 \r
560 \r
561                 \r
562         public void psychlops_main()\r
563         {\r
564             cnvs = new Canvas(300, 600);\r
565             Interval rng = new Interval();\r
566             tfreq = new Psychlops.Widgets.Slider("Temporal Frequency(Hz)", -5 <= rng <= 5, 3.0);\r
567             contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.25);\r
568             lambda = new Psychlops.Widgets.Slider("Wave Length", 10.0 <= rng <= 120.0, 30);\r
569 \r
570             img = new Image(isize * 2, isize * 2);\r
571             img2 = new Image(isize * 2, isize * 2);\r
572             img3 = new Image(isize * 2, isize * 2);\r
573 \r
574                         var gabor1 = StaticFunctions.NewArray<Figures.ShaderGabor>(100);\r
575                         foreach(var g in gabor1)\r
576                         {\r
577                                 g.setSigma(isize / 8).centering().shift(Math.random(300) - 150, Math.random(600) - 300);\r
578                                 g.orientation = Math.random(2*Math.PI);\r
579                         }\r
580 \r
581             while (true)\r
582                         {\r
583                 cnvs.clear(new Color(0.5));\r
584 \r
585                 Figures.drawGabor(ref img, isize / 8, 1/lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);\r
586                                 Figures.drawGabor(ref img2, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * -tfreq / 60);\r
587                                 Figures.drawGabor(ref img3, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);\r
588 \r
589 \r
590                 //img.centering().shift(0, -isize * 1.5).draw();\r
591                 //img2.centering().draw();\r
592                 //img3.centering().shift(0, isize * 1.5).draw();\r
593 \r
594 \r
595                                 foreach (var g in gabor1)\r
596                                 {\r
597                                         g.wavelength = lambda;\r
598                                         g.phase = (double)frames * 2.0 * Math.PI * tfreq / 60;\r
599                                         g.contrast = contrast;\r
600                                         g.draw();\r
601                                 }\r
602                 \r
603                 if (!Mouse.left.pressed()) frames++;\r
604 \r
605                 cnvs.flip();\r
606             }\r
607         }\r
608     }\r
609 }\r
610 */