OSDN Git Service

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