OSDN Git Service

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