OSDN Git Service

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