OSDN Git Service

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