OSDN Git Service

792f0641cef5f1d4e66dfbcfa6b60fa822a46287
[psychlops/silverlight.git] / test5 / PsychlopsMain.cs
1 /*\r
2 // Lilac Chaser.\r
3 // Zaidi Q, Ennis R, Cao D, Lee B (2012)\r
4 // Neural locus of color after-image.\r
5 // Current Biology, 22, 220-224\r
6 ///+ Prefix\r
7 //// Include Psychlops Package\r
8 using Psychlops;\r
9 \r
10 namespace PsychlopsSilverlightApp\r
11 {\r
12 \r
13         public class PsychlopsMain\r
14                 {\r
15 ///- Prefix\r
16 \r
17 \r
18                 ///+ Stimulus drawing function\r
19                 //// A function for stimulus drawing (main body)\r
20                 public void psychlops_main() {\r
21 \r
22                         ///+ Preperation\r
23                         //// Declare and initialize local variables\r
24                         Canvas cnvs = new Canvas(Canvas.window); //Prepare drawing window\r
25                         double dotsize = 100;\r
26                         double dot_lum  = 1;\r
27                         double bg_lum    = 0.5;\r
28                         double duration = 8.0;\r
29                         int stroke = 0;\r
30                         bool draw_base_position = false;\r
31 \r
32                         var fixate = new Rectangle();\r
33                         Image dot = new Image();\r
34                         Color col = new Color();\r
35                         double xp, yp, radius, a;\r
36 \r
37                         Psychlops.Widgets.Slider hue, value;\r
38                         ///- Preperation\r
39 \r
40                         ///+ set Independent\r
41                         //// set variables and value ranges for interaction\r
42                         Interval rng = new Interval();\r
43                         hue = new Psychlops.Widgets.Slider("Hue", 0.0 <= rng < 360.0, 1, 12);\r
44                         hue.setValue(300.0);\r
45                         value = new Psychlops.Widgets.Slider("Lightness", 0 <= rng <= 1.0, 0.1, 0.05);\r
46                         value.setValue(0.7);\r
47                         ///- set Independent\r
48 \r
49                         dot.set(dotsize, dotsize);\r
50                         double width = dotsize, height = dotsize, sigma = (width / 6.0);\r
51 \r
52                         fixate.set(11,11);\r
53 \r
54                         int frame = 0;\r
55 \r
56                         while (!Keyboard.esc.pushed())\r
57                         {\r
58                                 ///+ reflesh dot\r
59                                 if (hue.changed)\r
60                                 {\r
61                                         Psychlops.ColorSpaces.HSV hsv = new Psychlops.ColorSpaces.HSV();\r
62                                         hsv.H = Math.mod( hue.getValue(), 360);\r
63                                         hsv.S = 1.0;\r
64                                         hsv.V = value.getValue();\r
65                                         dot.each((x, y) =>\r
66                                         {\r
67                                                 yp = y - height / 2.0;\r
68                                                 xp = x - width / 2.0;\r
69                                                 radius = Math.sqrt(xp * xp + yp * yp);\r
70                                                 hsv.A = Math.exp(-(radius * radius) / (2.0 * sigma * sigma));\r
71                                                 return hsv.toRGB();\r
72                                         });\r
73                                 }\r
74                                 ///+ reflesh dot\r
75 \r
76 \r
77                                 ///+ stroke count\r
78                                 if(frame%((int)duration)==0) {\r
79                                         stroke++; stroke %= 8;\r
80                                 }\r
81                                 ///- stroke count\r
82 \r
83                                 cnvs.clear(new Color(bg_lum)); //Clear window\r
84 \r
85 \r
86                                 ///+ Draw dots\r
87                                 //// Draw dots at a desinated position.\r
88                                 for(int i=0; i<8; i++) {\r
89                                         if(i!=stroke) {\r
90                                                 dot.centering().shift(dotsize*1.3*Math.cos(i/8.0*2*Math.PI), dotsize*1.3*Math.sin(i/8.0*2*Math.PI)).draw();\r
91                                         }\r
92                                 }\r
93                                 ///- Draw dots\r
94 \r
95                                 fixate.centering().draw();\r
96 \r
97                                 cnvs.flip(); // Flip frame buffers\r
98                                 frame++;\r
99                         }\r
100 \r
101                 }\r
102                 ///- Stimulus drawing function\r
103 \r
104         }\r
105 \r
106 }\r
107 */\r
108 \r
109 \r
110 // Motion with glass patterns.\r
111 // Ross, J., Badcock, D. R., and Hayes, A. (2000)\r
112 // Coherent global motion in the absence of coherent velocity signals.\r
113 // Current Biology, 10, 679-682.\r
114 ///+ Prefix\r
115 //// Include Psychlops Package\r
116 using Psychlops;\r
117 \r
118 namespace PsychlopsSilverlightApp\r
119 {\r
120 \r
121         public class PsychlopsMain\r
122         {\r
123                 Psychlops.Widgets.Slider distance, duration, stimulus_type;\r
124                 ///- Prefix\r
125 \r
126                 public void psychlops_main()\r
127                 {\r
128                         GlassPattern();\r
129                 }\r
130 \r
131                 readonly int DOTNUM = 512;\r
132 \r
133                 ///+ Stimulus drawing function\r
134                 //// A function for stimulus drawing (main body)\r
135                 void GlassPattern() {\r
136 \r
137                         ///+ Preperation\r
138                         //// Declare and initialize local variables\r
139                         Canvas cnvs = new Canvas(400,400); //Prepare drawing window\r
140                         double dotsize = 2;\r
141                         double dot_lum  = 1.0;\r
142                         double bg_lum    = 0.2;\r
143                         double fieldsize = 300;\r
144                         double[] orientation = new double[DOTNUM];\r
145                         Rectangle dots = new Rectangle(dotsize, dotsize);\r
146                         Ellipse dot = new Ellipse(dotsize*3, dotsize*3);\r
147                         ///+ prepare dots position\r
148                         //// prepare dots position and paired orientation\r
149                         Matrix positionmat = Matrix.gen(DOTNUM,2);\r
150                         //Math.random(positionmat, -0.5*fieldsize, 0.5*fieldsize);\r
151                         positionmat.each( (v) => Math.random(-0.5*fieldsize, 0.5*fieldsize) );\r
152 \r
153                         \r
154                         for(int i=0; i<DOTNUM; i++){orientation[i] = Math.atan2(positionmat[i+1,2], positionmat[i+1,1]);}\r
155                         ///- prepare dots position\r
156 \r
157 \r
158                         ///+ Draw Gaussian Envelope\r
159                         ////Draw offscreen Gaussian Envelope\r
160                         Image envelope = new Image(fieldsize+100, fieldsize+100);\r
161                         envelope.clear(new Color(bg_lum)); //clear offscreen image\r
162                         double _x, _y;\r
163                         for(int i=0; i<fieldsize+100; i++){\r
164                                 _x=i-0.5*fieldsize-50;\r
165                                 for(int j=0; j<fieldsize+100; j++){\r
166                                         _y=j-0.5*fieldsize-50;\r
167                                         envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*Math.pow(fieldsize/4.0, 2.0) ))));\r
168                                 }\r
169                         }\r
170                         envelope.cache();\r
171                         ///- Draw Gaussian Envelope\r
172                         ///+ set Independent\r
173                         //// set variables and value ranges for interaction\r
174                         Interval rng = new Interval();\r
175                         stimulus_type = new Psychlops.Widgets.Slider("Stimulus Type", 0.0 <= rng <= 5.0, 1, 1);\r
176                         stimulus_type.setValue(0);\r
177                         distance = new Psychlops.Widgets.Slider("distance between pairs", 1 <= rng <= 10, 1, 1);\r
178                         distance.setValue(4.0);\r
179                         duration = new Psychlops.Widgets.Slider("Refresh", 0.0 <= rng <= 30.0, 1, 1);\r
180                         duration.setValue(5);\r
181                         ///- set Independent\r
182 \r
183                         int frame = 0;\r
184                         int stroke = 0;\r
185                         bool draw_base_position = false;\r
186                         Color col = new Color();\r
187 \r
188 \r
189                         ///+ initialize position\r
190                         //// Re-randomize position with a desingated interval\r
191                         //Math.random(positionmat, -0.5 * fieldsize, 0.5 * fieldsize);\r
192                         positionmat.each((v) => Math.random(-0.5 * fieldsize, 0.5 * fieldsize));\r
193                         for (int i = 0; i < DOTNUM; i++) { orientation[i] = Math.atan2(positionmat[i + 1, 2], positionmat[i + 1, 1]); }\r
194                         frame = 0;\r
195                         ///- initialize position\r
196 \r
197                         while (!Keyboard.esc.pushed())\r
198                         {\r
199                                 ///+ stroke count\r
200                                 if (frame % duration == 0)\r
201                                 {\r
202                                         stroke++; stroke %= 4;\r
203                                         if (stroke < 2) col.set(dot_lum);\r
204                                         else col.set(1 - dot_lum);\r
205                                         draw_base_position = (stroke % 2 == 0);\r
206                                 }\r
207                                 ///- stroke count\r
208 \r
209                                 Display.clear(new Color(bg_lum)); //Clear window\r
210 \r
211                                 if ((int)stimulus_type <= 1)\r
212                                 {\r
213                                         for (int i = -10; i < 11; i++)\r
214                                         {\r
215                                                 if (stroke % 2 == 0)\r
216                                                         dot.centering().shift((stimulus_type * 2 - 1) * -distance / 2.0, i * 20);\r
217                                                 else\r
218                                                         dot.centering().shift((stimulus_type * 2 - 1) * distance / 2.0, i * 20);\r
219                                                 dot.draw(col);\r
220                                         }\r
221 \r
222                                 } else {\r
223                                         //// Draw DOTNUM pairs of dots\r
224                                         for (int i = 0; i < DOTNUM; i++)\r
225                                         {\r
226                                                 ///+ draw first dots\r
227 \r
228                                                 ///+ switch stimulus type\r
229                                                 //// draw the second dots to generate selected stimulu type.\r
230                                                 switch ((int)stimulus_type)\r
231                                                 {\r
232                                                         ///+ case rotation\r
233                                                         //// Rotation\r
234                                                         case 2:\r
235                                                                 dots.centering().shift(positionmat[i + 1, 1], positionmat[i + 1, 2]); // move to center position\r
236                                                                 dots.shift(-0.5 * distance * Math.cos(orientation[i] + 0.5 * Math.PI), -0.5 * distance * Math.sin(orientation[i] + 0.5 * Math.PI));// move to the first position\r
237                                                                 if (draw_base_position) dots.draw(col); // draw first dot\r
238                                                                 dots.shift(distance * Math.cos(orientation[i] + 0.5 * Math.PI), distance * Math.sin(orientation[i] + 0.5 * Math.PI));// move to the second position\r
239                                                                 //cnvs.msg("Rotation", cnvs.getCenter().x, cnvs.getHeight() - 20);\r
240                                                                 break;\r
241                                                         ///- case rotation\r
242                                                         ///+ case diversion\r
243                                                         ////Diversion\r
244                                                         case 3:\r
245                                                                 dots.centering().shift(positionmat[i + 1, 1], positionmat[i + 1, 2]);// move to center position\r
246                                                                 dots.shift(-0.5 * distance * Math.cos(orientation[i] + 0.5 * Math.PI), -0.5 * distance * Math.sin(orientation[i] + 0.5 * Math.PI));// move to the first position\r
247                                                                 if (draw_base_position) dots.draw(col); // draw first dot\r
248                                                                 dots.shift(distance * Math.cos(orientation[i]), distance * Math.sin(orientation[i]));// move to the second position\r
249                                                                 break;\r
250                                                         ///- case diversion\r
251                                                         ///+ case spiral\r
252                                                         //// Spiral\r
253                                                         case 4:\r
254                                                                 dots.centering().shift(positionmat[i + 1, 1], positionmat[i + 1, 2]);// move to center position\r
255                                                                 dots.shift(-0.5 * distance * Math.cos(orientation[i] + 0.5 * Math.PI), -0.5 * distance * Math.sin(orientation[i] + 0.5 * Math.PI));// move to the first position\r
256                                                                 if (draw_base_position) dots.draw(col); // draw first dot\r
257                                                                 dots.shift(distance * Math.cos(orientation[i] + 0.25 * Math.PI), distance * Math.sin(orientation[i] + 0.25 * Math.PI));// move to the second position\r
258                                                                 break;\r
259                                                         ///- case spiral\r
260                                                 }\r
261                                                 ///- switch stimulus type\r
262 \r
263                                                 ///- draw first dots\r
264 \r
265 \r
266                                                 ///+ draw second dots\r
267                                                 if (!draw_base_position) dots.draw(col); // Draw dots at a desinated position.\r
268                                                 ///- draw second dots\r
269 \r
270                                         }\r
271                                         ///- Draw dots\r
272                                 }\r
273                                 envelope.centering().draw();\r
274                                 Display.flip(); // Flip frame buffers\r
275                                 frame++;\r
276                         }\r
277                 }\r
278         }\r
279 }\r
280 \r
281 */\r
282 \r
283 \r
284 /*\r
285 //Psychlops Code Template\r
286 //    Please visit following web site to get sample codes.\r
287 //    http://psychlops.sourceforge.jp/ja/?StartCode\r
288 //    CodeDresser at following address is also available to view the code.\r
289 //    http://visitope.org/Tools/codedresser.html\r
290 \r
291 ///+ 0 Setup Psychlops Circumstances\r
292 //// 0 Setup Psychlops Circumstances\r
293 using Psychlops;\r
294 \r
295 namespace PsychlopsSilverlightApp\r
296 {\r
297 \r
298         public class PsychlopsMain\r
299         {\r
300                 // Psychlops Win32 1.5.5 / 20110927\r
301                 ///- 0 Setup Psychlops Circumstances\r
302 \r
303                 Psychlops.Widgets.Slider SOAFrames, gap, wavelength, contrast;\r
304 \r
305                 public void psychlops_main() {\r
306 \r
307                         ///+ 1 Declaration /////////////////////////////////////////////////////////////\r
308                         //// 1 Declaration\r
309                         // declare default window and variables for its parameters\r
310                         Canvas cnvs = new Canvas(600,600, Canvas.window, Display.primary);\r
311                         double CANVAS_FRAMENUM;\r
312                         int CANVAS_REFRESHRATE;\r
313                         Color DEFAULT_BG_COLOR = new Color();\r
314 \r
315                         int gratingwidth = 500, gratingheight = 100;\r
316                         double shift=0.0;\r
317                         Color color = new Color(0.0,0.0,0.0);\r
318                         Rectangle grating = new Rectangle();\r
319 \r
320 \r
321                         Interval rng = new Interval();\r
322 \r
323                         //declare local variables around here\r
324 \r
325                         ///- 1 Declaration /////////////////////////////////////////////////////////////\r
326 \r
327                         ///+ 2 Initialization //////////////////////////////////////////////////////////\r
328                         //// 2 Initialization\r
329 \r
330                         // Set initial values for local variables\r
331                         CANVAS_REFRESHRATE = (int)cnvs.getRefreshRate();\r
332                         CANVAS_FRAMENUM = 0;\r
333                         DEFAULT_BG_COLOR.set(127.0/255.0,127.0/255.0,127.0/255.0,1.0); // default background color is 127/255 mid-gray\r
334 \r
335 \r
336                         SOAFrames = new Psychlops.Widgets.Slider("SOA Frames", 1  <=rng<=20  ,  1   , 1);\r
337                         SOAFrames.value = 5;\r
338                         gap = new Psychlops.Widgets.Slider("Grating gap" , 0  <=rng<=200 ,  1   , 10);\r
339                         gap.value = 20;\r
340                         wavelength = new Psychlops.Widgets.Slider("Wave Length", 1 <= rng <= 50, 1, 10);\r
341                         wavelength.value = 30.0;\r
342                         contrast = new Psychlops.Widgets.Slider("Contrast"    , 0.0<=rng<=1.0 ,  0.1 , 0.01);\r
343                         contrast.value = 0.1;\r
344 \r
345                         // Draw Offline images around here\r
346 \r
347                         // Offline Movie calculation using Image array around here\r
348 \r
349                         ///- 2 Initialization //////////////////////////////////////////////////////////\r
350 \r
351                         ///+ 3 Drawing /////////////////////////////////////////////////////////////////\r
352                         //// 3 Drawing\r
353                         while(!Keyboard.esc.pushed()) {\r
354                         cnvs.clear(DEFAULT_BG_COLOR);\r
355 \r
356                         //Write draw commands for realtime figure calculation and drawing around here\r
357 \r
358 \r
359                         if(Math.mod(CANVAS_FRAMENUM,SOAFrames) == 0){shift += 1;}\r
360 \r
361                         grating.set(1,gratingheight).centering().shift(-gratingwidth/2, 0);\r
362                         for(int i=0; i<gratingwidth; i++) {\r
363                                 color.set(\r
364                                                         + 0.25*contrast*Math.sin(2*Math.PI*(i*2.0/wavelength + 0.50 * shift))\r
365                                                         + 0.25*contrast*Math.sin(2*Math.PI*(i*3.0/wavelength + 0.75 * shift))\r
366                                                         +0.5\r
367                                                         );\r
368                                 grating.shift(1, 0);\r
369                                 grating.draw(color);\r
370                         }\r
371 \r
372                         grating.set(1,gratingheight).centering().shift(-gratingwidth/2, -gratingheight-gap);\r
373                         for(int i=0; i<gratingwidth; i++) {\r
374                                 color.set(\r
375                                                         + 0.25*contrast*Math.sin(2.0*Math.PI*(i*2.0/wavelength + 0.50 * shift))\r
376                                                         +0.5\r
377                                                         );\r
378                                 grating.shift(1,0);\r
379                                 grating.draw(color);\r
380                         }\r
381 \r
382                         grating.set(1,gratingheight).centering().shift(-gratingwidth/2, gratingheight+gap);\r
383                         for(int i=0; i<gratingwidth; i++) {\r
384                                 color.set(\r
385                                                         + 0.25*contrast*Math.sin(2.0*Math.PI*(i*3.0/wavelength + 0.75 * shift))\r
386                                                         +0.5\r
387                                                         );\r
388                                 grating.shift(1,0);\r
389                                 grating.draw(color);\r
390                         }\r
391 \r
392                         cnvs.flip();\r
393                         CANVAS_FRAMENUM++;\r
394                         }\r
395                         ///- 3 Drawing /////////////////////////////////////////////////////////////////\r
396 \r
397                 }\r
398 \r
399 \r
400         }\r
401 \r
402 }\r
403 */\r
404 \r
405 \r
406 /*\r
407                 public void psychlops_main() {\r
408 \r
409        Canvas display = new Canvas(768,768);\r
410 \r
411        double rect_size = 100;\r
412        double rect_lum  = 0.5;\r
413        double bg_lum    = 0.5;\r
414        double size = 250.0;\r
415    double sigma;\r
416    sigma = size/6.0;\r
417    double lambda;\r
418    lambda = 6*sigma;\r
419    int envelopemode = 0;\r
420    double refresh = display.getRefreshRate();\r
421    double[] SF=new double[2];\r
422 \r
423    SF[0]=4.0;\r
424    SF[1]=4.0;\r
425 \r
426    double phase=0;\r
427 \r
428    double[] initphase = new double[2];\r
429    double _i, _j, _x, _y, _x2, _y2, col;\r
430    double amplitude = 1.0;\r
431 \r
432        Rectangle fixation1 = new Rectangle(3,9);\r
433    Rectangle fixation2 = new Rectangle(9,3);\r
434        fixation1.centering();\r
435        fixation2.centering();\r
436    Rectangle contrastrect = new Rectangle();\r
437    contrastrect.set(760,760);\r
438 \r
439    Image envelope = new Image();\r
440    Psychlops.Color bglum= new Color(0.5,0.5,0.5);\r
441    Psychlops.Color masklum = new Color(0.5,0.5,0.5,0.5);\r
442 \r
443        Interval rng = new Interval();\r
444 \r
445 \r
446        Psychlops.Widgets.Slider TF;\r
447        TF = new Psychlops.Widgets.Slider("TF", 0.25<=rng<=2.0 , 0.1);\r
448    TF.value=0.75;\r
449 \r
450 \r
451 \r
452        Psychlops.Widgets.Slider SFs;\r
453        SFs = new Psychlops.Widgets.Slider("SF", 4.0<=rng<=16.0 ,  4.0);\r
454        SFs.value = 4.0;\r
455 \r
456    Psychlops.Widgets.Slider contrast;\r
457        contrast= new Psychlops.Widgets.Slider("Contrast", 0.0<=rng<=1.0 ,  0.1);\r
458        contrast.value = 0.1;\r
459 \r
460 \r
461        var element =  StaticFunctions.NewArray<Figures.ShaderGabor>(2);\r
462     for (int i = 0; i < element.Length; i++){\r
463            element[i].setSigma(sigma); // set a size of patch as a halfwidth of Gaussian\r
464            element[i].orientation = Math.PI/4.0+Math.PI/2.0*(1-i);//Math.PI/2*(rand()%2);// //set orientations\r
465            initphase[i]=0;\r
466   }\r
467 \r
468 \r
469 \r
470       envelope.set(size, size);\r
471       envelope.clear(bglum);\r
472 \r
473    for(int i=0; i<size; i++){\r
474        for(int j=0; j<size; j++){\r
475            _i=i-size*0.5;\r
476            _j=j-size*0.5;\r
477            _x=_i*Math.cos(-Math.PI/4.0)+_j*Math.sin(-Math.PI/4.0);\r
478            _y=-_i*Math.sin(-Math.PI/4.0)+_j*Math.cos(-Math.PI/4.0);\r
479            col=Math.exp(-(_x*_x)/(2*Math.pow(sigma*2/6.0,2.0))-(_y*_y)/(2*Math.pow(sigma*2,2.0)));\r
480            envelope.alpha(i,j,1.0-col);\r
481 \r
482            }\r
483        }\r
484 \r
485 \r
486        while(!Keyboard.esc.pushed()) {\r
487            if(Keyboard.spc.pushed())envelopemode++; envelopemode%=2;\r
488        Display.clear(bglum);\r
489        phase ++;\r
490        //phase = fmod(phase,60);\r
491 \r
492        for(int i=0; i<2; i++) {\r
493            element[i].phase =(SF[i]/SF[0])*amplitude*\r
494 Math.PI*Math.sin(Math.PI/2*i+2*Math.PI*phase*TF/refresh);\r
495            element[i].wavelength = lambda/SF[i];\r
496            element[i].contrast = contrast;\r
497        }\r
498 \r
499 \r
500        element[0].centering().shift(-size * 0.6, -size * 0.6);\r
501        element[0].draw();\r
502        element[1].centering().shift(size*0.6,-size*0.6);\r
503        element[1].draw();\r
504                element[1].centering().shift(-size*0.6,size*0.6);\r
505        element[1].draw();\r
506                element[0].centering().shift(size*0.6,size*0.6);\r
507        element[0].draw();\r
508 \r
509 \r
510                if(envelopemode>0){\r
511                    envelope.centering().shift(size*0.6,-size*0.6).draw();\r
512                    envelope.centering().shift(-size*0.6,size*0.6).draw();\r
513                    }\r
514        masklum.set(bg_lum, bg_lum, bg_lum, 1-contrast);\r
515        contrastrect.centering();\r
516        contrastrect.draw(masklum);\r
517        fixation1.centering().shift(size*2,0.0);\r
518        fixation1.draw(Color.red);\r
519        fixation2.centering().shift(size*2,0.0);\r
520        fixation2.draw(Color.red);\r
521 \r
522            Display.var(Mouse.x, 300, 300);\r
523            Display.var(Mouse.y, 300, 320);\r
524 \r
525                Display.flip();\r
526 \r
527 \r
528        }\r
529 \r
530 }\r
531 \r
532         }\r
533 \r
534 }\r
535 */\r
536 \r
537 \r
538 /*\r
539 \r
540 using Psychlops;\r
541 //Position Bias Program\r
542 namespace PsychlopsSilverlightApp\r
543 {\r
544 \r
545         public class PsychlopsMain\r
546         {\r
547                 Canvas cnvs;\r
548                 Image img, img2, img3;\r
549                 int isize = 40;\r
550                 int frames;\r
551                 Psychlops.Widgets.Slider tfreq;\r
552                 Psychlops.Widgets.Slider contrast;\r
553                 Psychlops.Widgets.Slider lambda;\r
554 \r
555 \r
556 \r
557                 public void psychlops_main()\r
558                 {\r
559                         cnvs = new Canvas(300, 600);\r
560                         Interval rng = new Interval();\r
561                         tfreq = new Psychlops.Widgets.Slider("Temporal Frequency(Hz)", -5 <= rng <= 5, 3.0);\r
562                         contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.25);\r
563                         lambda = new Psychlops.Widgets.Slider("Wave Length", 10.0 <= rng <= 120.0, 30);\r
564 \r
565                         img = new Image(isize * 2, isize * 2);\r
566                         img2 = new Image(isize * 2, isize * 2);\r
567                         img3 = new Image(isize * 2, isize * 2);\r
568 \r
569                         var gabor1 = StaticFunctions.NewArray<Figures.ShaderGabor>(100);\r
570                         foreach (var g in gabor1)\r
571                         {\r
572                                 g.setSigma(isize/8).centering().shift(Math.random(300) - 150, Math.random(600) - 300);\r
573                                 //g.setSize(isize).centering().shift(Math.random(300) - 150, Math.random(600) - 300);\r
574                                 g.orientation = Math.random(2 * Math.PI);\r
575                                 //g.orientation2 = Math.random(2 * Math.PI);\r
576                         }\r
577 \r
578                         while (true)\r
579                         {\r
580                                 cnvs.clear(new Color(0.5));\r
581 \r
582                                 Figures.drawGabor(ref img, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);\r
583                                 Figures.drawGabor(ref img2, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * -tfreq / 60);\r
584                                 Figures.drawGabor(ref img3, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);\r
585 \r
586 \r
587                                 //img.centering().shift(0, -isize * 1.5).draw();\r
588                                 //img2.centering().draw();\r
589                                 //img3.centering().shift(0, isize * 1.5).draw();\r
590 \r
591 \r
592                                 //foreach (var g in gabor1)\r
593                                 for (int i = 0; i < gabor1.Length; i++)\r
594                                 {\r
595                                         gabor1[i].wavelength = lambda;\r
596                                         gabor1[i].phase = (double)frames * 2.0 * Math.PI * tfreq / 60;\r
597                                         gabor1[i].contrast = contrast;\r
598                                         //g.wavelength2 = lambda * 2;\r
599                                         //g.phase2 = (double)frames * 2.0 * Math.PI * tfreq / 60;\r
600                                         //g.contrast2 = contrast / 2;\r
601                                         gabor1[i].draw();\r
602                                 }\r
603 \r
604                                 if (!Mouse.left.pressed()) frames++;\r
605 \r
606                                 cnvs.flip();\r
607                         }\r
608                 }\r
609         }\r
610 }\r
611 \r
612 \r
613 /*\r
614 ///+ Prefix linkto BasicCode1\r
615 //// Lines for set up Psychlops environment\r
616 using Psychlops;\r
617 \r
618 namespace PsychlopsSilverlightApp\r
619 {\r
620 \r
621         public class PsychlopsMain\r
622         {\r
623                 ///- Prefix linkto BasicCode1\r
624 \r
625 \r
626                 ///+ Main Routine\r
627                 //// Psychlops runs at the first line of this function psychlops_main().\r
628                 public void psychlops_main()\r
629                 {\r
630 \r
631                         ///+ 0 SetGlobal\r
632                         ////Prepare global parameters\r
633                         Rectangle p1 = new Rectangle(1,1);\r
634                         Color col1 = new Color();\r
635                         double width=50;\r
636                         double height=10;\r
637                         double lambda=60;\r
638                         double lmean=0.25, contrast = 0.5;\r
639                         double x0 = 0;\r
640                         double y0 = 0;\r
641                     double pitch = 1;\r
642                         Canvas disp = new Canvas(Canvas.window, Display.secondary);\r
643                         \r
644                         var fieldW_ = Psychlops.Widgets.Browser.Element.byID("fieldW");\r
645                         var fieldH_ = Psychlops.Widgets.Browser.Element.byID("fieldH");\r
646                         var wL_     = Psychlops.Widgets.Browser.Element.byID("wL");\r
647                         var Cont_   = Psychlops.Widgets.Browser.Element.byID("Cont");\r
648                         var ix_     = Psychlops.Widgets.Browser.Element.byID("ix");\r
649                         var iy_     = Psychlops.Widgets.Browser.Element.byID("iy");\r
650                         var gap_    = Psychlops.Widgets.Browser.Element.byID("gap");\r
651                         ///- 0 SetGlobal\r
652 \r
653                         ///+ 1 Initialize\r
654                         ////initialize\r
655                         p1.centering().shift(-width*0.5 + x0, -height*0.5 + y0); //Move a point to the initial position.\r
656                         ///- 1 Initialize\r
657 \r
658                         ///+ 2 Drawing\r
659                          ////drawing objects\r
660                         for(int i=0; i < width; i++)\r
661                         {\r
662                                 col1.set(lmean*((contrast*Math.sin((2*Math.PI*i/lambda)))+1)); //Set a color.\r
663 \r
664                                 ///+ 2.1 Drawing a column\r
665                                 ////drawing a column\r
666                                 for(int j=0;j < height; j++)\r
667                                 {\r
668                                         p1.draw(col1);\r
669                                         p1.shift(0, pitch);\r
670                                 }\r
671                                 ///- 2.1 Drawing a column\r
672 \r
673                                 p1.shift(1, -height * pitch); //back to vertical intitial point after drawing one column.\r
674                         }\r
675                         disp.flip();\r
676                         ///- 2 Drawing\r
677 \r
678                         while (!Keyboard.spc.pushed()) { }; //Wait until space key is pressed.\r
679                 }\r
680 \r
681 \r
682         }\r
683 \r
684 }\r
685  * */\r
686 \r
687 \r
688 /*\r
689 ///+ Prefix\r
690 //// Lines for set up Psychlops environment\r
691 using Psychlops;\r
692 \r
693 namespace PsychlopsSilverlightApp\r
694 {\r
695 \r
696         public class PsychlopsMain\r
697         {///- Prefix\r
698 \r
699 \r
700 \r
701                 ///+ Main Routine\r
702                 //// Psychlops runs at the first line of this function psychlops_main().\r
703                 public void psychlops_main()\r
704                 {\r
705                         Canvas window = new Canvas(300, 300); //Create a window. Here, window variables are preset mode.\r
706 \r
707                         var FIGURE = Psychlops.Widgets.Browser.Element.byID("FIGURE");\r
708                         var SIZE_X_ = Psychlops.Widgets.Browser.Element.byID("SIZE_X");\r
709                         var SIZE_Y_ = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");\r
710                         var COLOR_R = Psychlops.Widgets.Browser.Element.byID("COLOR_R");\r
711                         var COLOR_G = Psychlops.Widgets.Browser.Element.byID("COLOR_G");\r
712                         var COLOR_B = Psychlops.Widgets.Browser.Element.byID("COLOR_B");\r
713                         var COLOR_BG = Psychlops.Widgets.Browser.Element.byID("COLOR_BG");\r
714                         var Period_Size = Psychlops.Widgets.Browser.Element.byID("Period_Size");\r
715                         var Period_Position = Psychlops.Widgets.Browser.Element.byID("Period_Position");\r
716                         var Speed_HSize_ = Psychlops.Widgets.Browser.Element.byID("Speed_HSize");\r
717                         var Speed_VSize = Psychlops.Widgets.Browser.Element.byID("Speed_VSize");\r
718                         var Speed_VMotion = Psychlops.Widgets.Browser.Element.byID("Speed_VMotion");\r
719                         double SIZE_X = SIZE_X_, SIZE_Y = SIZE_Y_;\r
720 \r
721                         ///+ 2\r
722                         ////  Set a figure size, position and color.\r
723                         Rectangle figure = new Rectangle();\r
724                         Ellipse figure2 = new Ellipse();\r
725                         figure.set(SIZE_X_, SIZE_Y_); // Set the size of figure.\r
726                         figure2.set(SIZE_X_, SIZE_Y_); // Set the size of figure.\r
727                         figure.centering().shift(0, 0); // Move the figure to the starting point.\r
728                         figure2.centering().shift(0, 0); // Move the figure to the starting point.\r
729                         ///- 2\r
730 \r
731                         int frame = 0;\r
732                         int looming_direction = 1, motion_dir = 1;\r
733                         double direction = 1.0;\r
734                         //looming_direction is a variable for size change.\r
735                         //motion_dir is a variable for motion direction.\r
736                         ///+ 3 Drawing loop\r
737                         //// Draw each frames in a "while loop".\r
738                         while (!Keyboard.esc.pushed())\r
739                         { //exit a program when the escape key is pressed down.\r
740                                 window.clear(COLOR_BG); // Clear the window with a designated gray-scale level.\r
741 \r
742                                 ///+ 3.1\r
743                                 //// Calculate object's position and size for each frame.\r
744 \r
745                                 if (frame % Period_Size == 0)\r
746                                 { // a direction of size change will reverse at designated frames.\r
747                                         looming_direction = looming_direction * -1;\r
748                                 }\r
749 \r
750                                 if (frame % Period_Position == 0)\r
751                                 { // motion direction will reverse at designated frames.\r
752                                         motion_dir *= -1;\r
753                                 }\r
754 \r
755                                 ///- 3.1\r
756 \r
757                                 ///+ 3.2 \r
758                                 //// Settting figure's properties\r
759                                 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
760                                                                  figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".\r
761                                 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
762                                 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
763                                                                 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".\r
764                                 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
765                                 /*\r
766                                 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
767                                                          figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".\r
768                                 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
769                                 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
770                                                                 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".\r
771                                 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
772                                  * * /\r
773                                 ///- 3.2\r
774 \r
775                                 ///+ 3.3 \r
776                                 ////Drawing\r
777                                 if ("Rectangle".Equals(FIGURE))\r
778                                 {\r
779                                         figure.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.\r
780                                 }\r
781                                 else\r
782                                 {\r
783                                         figure2.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.\r
784                                 }\r
785                                 window.flip(); // Reflect the drawing for the display by flipping frame buffers.\r
786                                 ///- 3.3\r
787 \r
788                                 ///+ 3.4\r
789                                 ////make a step for next frames \r
790                                 frame++;\r
791                                 ///- 3.4\r
792                         }\r
793                         ///- 3 Drawing loop\r
794 \r
795                 }\r
796                 ///- Main Routine\r
797 \r
798 \r
799         }\r
800 \r
801 }\r
802 \r
803 \r
804 \r
805 /*\r
806 //The reversed-phi motion.\r
807 //Anstis (1970)\r
808 //Phi movement as a subtraction process. Vision Res 10:1411?1430\r
809 \r
810 ///+ Prefix\r
811 //// Include Psychlops Package\r
812 using Psychlops;\r
813 \r
814 namespace PsychlopsSilverlightApp\r
815 {\r
816 \r
817         public class PsychlopsMain\r
818         {\r
819 \r
820                 ///- Prefix\r
821 \r
822                 ///+ Stimulus drawing function\r
823                 //// A function for stimulus drawing (main body)\r
824                 void RectLuminance()\r
825                 {\r
826 \r
827                         ///+ Preperation\r
828                         //// Declare and initialize local variables\r
829                         double rect_size = 20;\r
830 \r
831                         double bg_lum = 0.5;\r
832                         double radii = 200;\r
833                         double rect_lum;\r
834                         int element_number = 25;\r
835                         int radial_row = 5;\r
836 \r
837                         double rotation_tf = 0.2;\r
838                         double polarity = 1;\r
839                         double rotation;\r
840 \r
841                         double contrastflag = 1;\r
842                         int period = 3;\r
843                         double refresh;\r
844 \r
845                         Canvas display = new Canvas(Canvas.window); //Prepare drawing window\r
846                         refresh = Display.getRefreshRate();\r
847 \r
848                         Ellipse rect = new Ellipse();\r
849                         rect.set(rect_size, rect_size);\r
850 \r
851                         Ellipse fixation = new Ellipse(5, 5);\r
852                         fixation.centering();\r
853 \r
854                         Letters let1 = new Letters("Press Space key to change stimulus type");\r
855                         let1.centering().shift(-180, 220);\r
856                         Letters let2 = new Letters("Phi");\r
857                         let2.centering().shift(-10, 200);\r
858                         Letters let3 = new Letters("Reversed-Phi");\r
859                         let3.centering().shift(-60, 200);\r
860 \r
861                         rotation = Math.random(2 * Math.PI);\r
862 \r
863                         ///+ user interface\r
864                         ////register variables to demo circumstances\r
865                         Interval rng = new Interval();\r
866 \r
867                         Psychlops.Widgets.Slider rect_contrast;\r
868                         rect_contrast = new Psychlops.Widgets.Slider("Contrast", 0.1 <= rng <= 1.0, 0.1);\r
869                         rect_contrast.value = 0.5;\r
870                         ///- user interface\r
871                         ///- Preperation\r
872 \r
873                         ///+ Main loop\r
874                         ////Main loop\r
875                         int frame = 0;\r
876                         //AppState::setThreadPriority(AppState::HIGH);\r
877                         while (true)\r
878                         {\r
879                                 frame++;\r
880                                 if (Keyboard.spc.pushed()) contrastflag = -contrastflag;\r
881                                 if (contrastflag < 0) polarity = -polarity;\r
882                                 rotation = 2 * Math.PI * rotation_tf * frame * period / refresh;\r
883 \r
884                                 for (int frame_now = 0; frame_now < period; frame_now++)\r
885                                 {\r
886                                         Display.clear(new Color(bg_lum));\r
887                                         for (int j = 0; j < radial_row; j++)\r
888                                         {\r
889                                                 rect.resize(rect_size * (j + radial_row) / 10.0, rect_size * (j + radial_row) / 10.0);\r
890                                                 for (double i = 0; i < element_number; i++)\r
891                                                 {\r
892                                                         rect_lum = bg_lum * (1.0 + polarity * rect_contrast);\r
893                                                         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
894                                                         rect.draw(rect_lum);\r
895                                                 }\r
896                                         }\r
897                                         fixation.draw(Color.red);\r
898                                         let1.draw();\r
899                                         if (contrastflag > 0) let2.draw();\r
900                                         else let3.draw();\r
901                                         Display.flip();\r
902                                 }\r
903                         }\r
904                         ///- Main loop\r
905                         //AppState::setThreadPriority(AppState::NORMAL);\r
906                 }\r
907                 ///- Stimulus drawing function\r
908 \r
909                 ///+ Main function for demo circumstances\r
910                 //// Psychlops Main function\r
911                 public void psychlops_main()\r
912                 {\r
913                         ///+ Demo circumstances\r
914                         //// Spells for run demonstration circumstances\r
915                         Procedure p = new Procedure();\r
916                         //p.setDesign(Procedure::DEMO); //Designate that this is a demo.\r
917                         p.setProcedure(RectLuminance);  //The argument name is a name of drawing function.\r
918                         p.run();\r
919                         ///- Demo circumstances\r
920                 }\r
921                 ///- Main function for demo circumstances\r
922 \r
923         }\r
924 \r
925 }\r
926 \r
927 \r
928 \r
929 /*\r
930 //Two types of plaid motion\r
931 //E. H. Adelson and J. A. Movshon (1982).\r
932 //Phenomenal coherence of moving visual patterns. Nature 300, 523-525\r
933 \r
934 ///+ Prefix\r
935 //// Include Psychlops Package\r
936 using Psychlops;\r
937 \r
938         namespace PsychlopsSilverlightApp\r
939         {\r
940 \r
941                 public class PsychlopsMain\r
942                 {\r
943                         ///- Prefix\r
944 \r
945                         ///+ Global\r
946                         // Struct for component paremeters\r
947                         struct component\r
948                         {\r
949                                 public double contrast;\r
950                                 public double orientation;\r
951                                 public double lambda;\r
952                                 public double tf;\r
953                         }\r
954                         ///- Global\r
955 \r
956                         ///+ Stimulus drawing function\r
957                         //// A function for stimulus drawing (main body)\r
958                         void drawgratingmovie(Image[] img, component c1, component c2, double contrast, int start, int maxframe, double bg_lum, double alpha)\r
959                         {\r
960                                 double _xp, _xp2, col1, col2;\r
961                                 double contrast1, contrast2;\r
962                                 double imageheight, imagewidth;\r
963 \r
964                                 contrast1 = contrast*c1.contrast/(c1.contrast+c2.contrast);\r
965                                 contrast2 = contrast*c2.contrast/(c1.contrast+c2.contrast);\r
966 \r
967                                 imageheight = img[0].getHeight();\r
968                                 imagewidth = img[0].getWidth();\r
969 \r
970                                 for(int frame=start; frame<start+maxframe+1; frame++){\r
971                                         //Display.progressbar(frame, maxframe+1);\r
972                                         //img[frame].convert(Image::RGBA);\r
973                                         for(int i=0; i<imagewidth; i++){\r
974                                                 for(int j=0; j<imageheight; j++){\r
975                                                         _xp = Math.sin(c1.orientation)*(i-imagewidth*0.5) + Math.cos(c1.orientation) * (j-imageheight *0.5);\r
976                                                         _xp2 = Math.sin(c2.orientation)*(i-imagewidth*0.5) + Math.cos(c2.orientation) * (j-imageheight *0.5);\r
977                                                         col1 = bg_lum*contrast1*Math.sin(2*Math.PI*_xp/c1.lambda + 2*Math.PI*c1.tf*frame/(double)refresh);\r
978                                                         col2 = bg_lum*contrast2*Math.sin(2*Math.PI*_xp2/c2.lambda + 2*Math.PI*c2.tf*frame/(double)refresh);\r
979                                                         img[frame].pix(i,j,new Color(col1+col2+bg_lum));\r
980                                                         img[frame].alpha(i,j,alpha);\r
981                                                 }\r
982                                         }\r
983                                         //img[frame].cache();\r
984                                 }\r
985                         }\r
986 \r
987                         ///+ Stimulus drawing function\r
988                         //// A function for stimulus drawing (main body)\r
989                         void drawplaid() {\r
990                                 Canvas display = new Canvas(Canvas.window);\r
991                                 ///+ Preperation\r
992                                 //// Declare and initialize local variables\r
993                                 int rect_size = 150;\r
994                                 double rect_lum  = 0.5;\r
995                                 double bg_lum    = 0.2;\r
996                                 double duration = 400;\r
997 \r
998                                 double[] lambda = new double[2], contrast = new double[2], tf = new double[2];\r
999                                 double center_orientation = 0.0;\r
1000                                 Image[,] movie = StaticFunctions.NewArray<Image>(2, 120);\r
1001                                 Image[,] component_movie = StaticFunctions.NewArray<Image>(4, 120);\r
1002                                 Image envelope = new Image(), envelope_small = new Image();\r
1003 \r
1004                                 for(int i=0; i<120; i++)\r
1005                                 {\r
1006                                         movie[0, i].set(rect_size, rect_size);\r
1007                                         movie[1, i].set(rect_size, rect_size);\r
1008                                         component_movie[0, i].set(rect_size/2, rect_size/2);\r
1009                                         component_movie[1, i].set(rect_size/2, rect_size/2);\r
1010                                         component_movie[2, i].set(rect_size/2, rect_size/2);\r
1011                                         component_movie[3, i].set(rect_size/2, rect_size/2);\r
1012                                 }\r
1013                                 envelope.set(rect_size, rect_size);\r
1014                                 envelope_small.set(rect_size/2, rect_size/2);\r
1015 \r
1016                                 Letters let1 = new Letters(), let2 = new Letters(), let3 = new Letters();\r
1017                                 let1.str = "Component1";\r
1018                                 let2.str = "Component2";\r
1019                                 let3.str = "Superposition";\r
1020                                 let1.centering().shift(-rect_size*1.25, -rect_size);\r
1021                                 //let1.cache();\r
1022                                 let2.centering().shift(rect_size*1.25, -rect_size);\r
1023                                 //let2.cache();\r
1024                                 let3.centering().shift(0.0, rect_size*0.75);\r
1025                                 //let3.cache();\r
1026 \r
1027                                 component c1, c2, c0;\r
1028                                 c0 = new component{ 0.0,0.0,1.0,1.0 }; //dummy for component movie\r
1029                                 ///+ type-I\r
1030                                 // Prepare Type-I plaid movie\r
1031                                 center_orientation = 0.0;\r
1032                                 orientation_offset = Math.PI/6;\r
1033                                 contrast[0] = 1.0, contrast[1] = 1.0;\r
1034                                 lambda[0] = 30.0, lambda[1] = 30.0;\r
1035                                 tf[0] = 1.0; tf[1] = 1.0;\r
1036 \r
1037                                 c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};\r
1038                                 c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};\r
1039 \r
1040                         drawgratingmovie(movie[0],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
1041                         drawgratingmovie(component_movie[0],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
1042                         drawgratingmovie(component_movie[1],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);\r
1043                         ///- type-I\r
1044 \r
1045                         ///+ type-II\r
1046                         // Prepare Type-II plaid movie\r
1047                         center_orientation = -0.0, orientation_offset = Math.PI/12;\r
1048                         contrast[0] = 1.0, contrast[1] = 1.0;\r
1049                         lambda[0] = 30.0, lambda[1] = 30.0;\r
1050                         tf[0] = 1.0; tf[1] = 4.0;\r
1051 \r
1052                         c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};\r
1053                         c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};\r
1054 \r
1055                         drawgratingmovie(movie[1],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
1056                         drawgratingmovie(component_movie[2],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
1057                         drawgratingmovie(component_movie[3],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);\r
1058                         ///- type-II\r
1059 \r
1060                         ///+ gaussian\r
1061                         //draw Gaussian envelopes\r
1062                         envelope.clear(new Color(bg_lum)); //clear offscreen image\r
1063                         double _x, _y;\r
1064                         for(int i=0; i<rect_size; i++){\r
1065                         _x=i-0.5*rect_size;\r
1066                         for(int j=0; j<rect_size; j++){\r
1067                         _y=j-0.5*rect_size;\r
1068                         envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/6.0, 2.0) ))));\r
1069                         }\r
1070                         }\r
1071 \r
1072                         envelope_small.clear(new Color(bg_lum)); //clear offscreen image\r
1073                         for(int i=0; i<rect_size*0.5; i++){\r
1074                         _x=i-0.25*rect_size;\r
1075                         for(int j=0; j<rect_size*0.5; j++){\r
1076                         _y=j-0.25*rect_size;\r
1077                         envelope_small.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/12.0, 2.0) ))));\r
1078                         }\r
1079                         }\r
1080                         envelope.cache(); //send offscreen image from main memory to GPU\r
1081                         envelope_small.cache(); //send offscreen image from main memory to GPU\r
1082                         ///- gaussian\r
1083 \r
1084                         ///+ user interface\r
1085                         // Draw user interface\r
1086                         Widgets::SelectBox stimulus_type;\r
1087                         stimulus_type.area.set(120, 20);\r
1088                         stimulus_type.append(L"TypeI");\r
1089                         stimulus_type.append(L"TypeII");\r
1090                         stimulus_type.centering().shift(-120.0,250.0);\r
1091 \r
1092                         Psychlops::Widgets::SelectBox stimulus_type2;\r
1093                         stimulus_type2.area.set(120, 20);\r
1094                         stimulus_type2.append(L"Continuous");\r
1095                         stimulus_type2.append(L"Periodic");\r
1096                         stimulus_type2.centering().shift(120.0,250.0);\r
1097 \r
1098                         Psychlops::Widgets::Slider duration_slider;\r
1099                         duration_slider.area.set(100,20);\r
1100                         duration_slider.centering().shift(120,280.0);\r
1101                         Interval rng = new Interval();\r
1102                         duration_slider.link(duration, 50<=rng<=950, 50.0, 50.0);\r
1103                         ///- user interface\r
1104                         ///- Preperation\r
1105 \r
1106                         ///+ Main loop\r
1107                         int frame = 0;\r
1108                         int period = refresh_int;\r
1109                         int movienum;\r
1110                         while(!Keyboard.esc.pushed()) {\r
1111                         Display.clear(new Color(bg_lum));\r
1112                         movienum = stimulus_type.getSelected(); //if "Type-I" is selected, 0, else frame refresh per sec\r
1113 \r
1114                         in;\r
1115                         else period = refresh_int;\r
1116 \r
1117                         if(frame>0){\r
1118                         movie[movienum, frame].centering().draw();\r
1119                         envelope.centering().draw();\r
1120                         component_movie[movienum*2, frame].centering().shift(-rect_size*0.5, -rect_size).draw();\r
1121                         envelope_small.centering().shift(-rect_size*0.5, -rect_size).draw();\r
1122                         component_movie[movienum*2+1, frame].centering().shift(rect_size*0.5, -rect_size).draw();\r
1123                         envelope_small.centering().shift(rect_size*0.5, -rect_size).draw();\r
1124                         }\r
1125 \r
1126                         ///+ draw user interface\r
1127                         let1.draw(0.75);\r
1128                         let2.draw(0.75);\r
1129                         let3.draw(0.75);\r
1130                         stimulus_type.draw();\r
1131                         stimulus_type2.draw();\r
1132                         if(stimulus_type2.getSelected())duration_slider.draw();\r
1133                         ///- draw user interface\r
1134                         Display.flip();\r
1135                         if(frame++ >= period) frame -= refresh_int;\r
1136                         }\r
1137                         ///- Main loop\r
1138 \r
1139                         }\r
1140                         ///- Stimulus drawing function\r
1141 \r
1142                 ///+ Main function for demo circumstances\r
1143                 public void psychlops_main() {\r
1144                         ///+ Demo circumstances\r
1145                         //// Spells for run demonstration circumstances\r
1146                         Procedure p = new Procedure();\r
1147                         //p.setDesign(Procedure::DEMO); //Designate that this is a demo.\r
1148                         p.setProcedure(drawplaid);  //The argument name is a name of drawing function.\r
1149                         p.run();\r
1150                         ///- Demo circumstances\r
1151                 }\r
1152         }\r
1153 }\r
1154 */\r