OSDN Git Service

132132
[psychlops/silverlight.git] / test4 / PsychlopsMain.cs
1 ///+ Prefix linkto BasicCode1\r
2 //// Lines for set up Psychlops environment\r
3 using Psychlops;\r
4 \r
5 namespace PsychlopsSilverlight4test\r
6 {\r
7 \r
8         public class PsychlopsMain\r
9         {///- Prefix linkto BasicCode1\r
10 \r
11 \r
12                 ///+ Main Routine\r
13                 //// Psychlops runs at the first line of this function psychlops_main().\r
14                 public void psychlops_main() {\r
15     ///+ 0 linkto BasicCode3_1a\r
16     ////Prepare global parameters\r
17      const int maxrectnum = 200;\r
18      int rectnum = 100/*ID:rectnumber 25.0 200.0 25.0*/;\r
19      double rectsize = 5.0/*ID:dotsize 1.0 10.0 1.0*/;\r
20      Rectangle[] rect = Rectangle.Array(maxrectnum);\r
21      double[] rectcolorR = new double[maxrectnum];\r
22      double[] rectcolorG = new double[maxrectnum];\r
23      double[] rectcolorB = new double[maxrectnum];\r
24     ///- 0 linkto BasicCode3_1a\r
25 \r
26          Canvas window = new Canvas(Canvas.window);\r
27 \r
28      ///+ 1 linkto BasicCode3_1a\r
29      ////Initialize\r
30      for(int i=0; i < rectnum; i++){\r
31          ///+ 1.1 set1\r
32          ////set positions and sizes\r
33          rect[i].set(rectsize, rectsize); //Set a size of rectangles.\r
34          rect[i].centering();\r
35          rect[i].shift((i - 0.5  *rectnum) * rectsize* 1.5/*ID:RectHGap 1.0 3.0 0.5*/,\r
36                                         (i-0.5*rectnum) * rectsize * 1.5/*ID:RectVGap 1.0 3.0 0.5*/); //Move Rectangles to initial positions\r
37          ///- 1.1 set1\r
38          ///+ 1.2 set2\r
39          ////set colors\r
40                  rectcolorR[i] = Math.random(1.0) * 0.5/*ID:RGain 0.0 1.0 0.5*/; //Set R values. Note that "i" is converted to double-type.\r
41                  rectcolorG[i] = Math.random(1.0) * 0.5/*ID:GGain 0.0 1.0 0.5*/; //Set G values. Note that "i" is converted to double-type.\r
42                  rectcolorB[i] = Math.random(1.0) * 0.5/*ID:BGain 0.0 1.0 0.5*/; //Set B values. Note that "i" is converted to double-type.\r
43          ///- 1.2 set2\r
44          }\r
45     ///- 1 linkto BasicCode3_1a\r
46 \r
47     ///+ 2 drawing\r
48     ////drawing objects\r
49     ///+ 2.1 linkto BasicCode3_2a\r
50     ////Prepare variables for movie control;\r
51     int frame=0;\r
52     int motion_dir=1;\r
53     double Horizontal_shift, Vertical_shift;\r
54     ///- 2.1 linkto BasicCode3_2a\r
55 \r
56     while(!Keyboard.esc.pushed()){\r
57         window.clear(Color.black);\r
58         for(int i=0; i < rectnum; i++){\r
59          ///+ 2.2 loopset1\r
60          ////set positions and sizes\r
61 \r
62          Horizontal_shift=Math.sin(2 * Math.PI * ((double)frame / 30.0/*ID:Period_HPosition 30 240 30*/))*motion_dir * 100.0/*ID:HSpeed 0.0 100.0 10.0*/; //Calculate horizontal displacement from the center.\r
63          Vertical_shift=Math.sin(2 * Math.PI * ((double)frame / 30.0/*ID:Period_HPosition 30 240 30*/))*motion_dir * 0.0/*ID:VSpeed 0.0 100.0 10.0*/;//Calculate vertical displacement from the center.\r
64          rect[i].resize(rectsize, rectsize); //Resize rectangles.\r
65          rect[i].centering(); //Rectangles are moved to the center...\r
66          rect[i].shift(Horizontal_shift + (i-0.5*rectnum) * rectsize * 1.5/*ID:RectHGap 1.0 3.0 0.5*/,\r
67                        Vertical_shift + (i-0.5*rectnum)  *rectsize * 1.5/*ID:RectVGap 1.0 3.0 0.5*/); //and then move to designated positions\r
68          ///- 2.2 loopset1\r
69 \r
70          ///+ 2.3 linkto BasicCode3_2a\r
71          ////set colors \r
72                  rectcolorR[i] = Math.random(1.0) * 0.5/*ID:RGain 0.0 1.0 0.5*/; //Set R values. Note that "i" is converted to double-type.\r
73                  rectcolorG[i] = Math.random(1.0) * 0.5/*ID:GGain 0.0 1.0 0.5*/; //Set G values. Note that "i" is converted to double-type.\r
74                  rectcolorB[i] = Math.random(1.0) * 0.5/*ID:BGain 0.0 1.0 0.5*/; //Set B values. Note that "i" is converted to double-type.\r
75          ///- 2.3 linkto BasicCode3_2a\r
76 \r
77          }\r
78                 ///+ 2.4 linkto BasicCode3_1a\r
79         for(int i=0; i < rectnum; i++){\r
80             rect[i].draw(new Color(rectcolorR[i], rectcolorG[i], rectcolorB[i])); //draw objects by designated colors.\r
81         }\r
82         window.flip();\r
83         ///- 2.4 linkto BasicCode3_1a\r
84         frame++;\r
85     }\r
86     ///- 2 drawing\r
87 \r
88 }\r
89                 ///- Main Routine\r
90 \r
91 \r
92 \r
93         }\r
94 \r
95 }\r
96 \r
97 \r
98 \r
99 /*\r
100 using Psychlops;\r
101 \r
102 namespace PsychlopsSilverlight4test\r
103 {\r
104 \r
105         public class PsychlopsMain\r
106         {\r
107                 void RectLuminance()\r
108                 {\r
109                         Canvas display = new Canvas(Canvas.window);\r
110                         Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);\r
111                         Letters le = new Letters("Reload to restart");\r
112                         le.fill = Color.black;\r
113                         le.align = Letters.HorizontalAlign.center;\r
114 \r
115                         while (!Keyboard.esc.pushed())\r
116                         {\r
117                                 Display.clear(Color.white);\r
118                                 le.centering().shift(-200,-10).draw();\r
119                                 Display.flip();\r
120                         }\r
121 \r
122                 }\r
123 \r
124 \r
125                 public void psychlops_main()\r
126                 {\r
127                         RectLuminance();\r
128                 }\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 \r
143 \r
144 \r
145 /*\r
146  using Psychlops;\r
147 \r
148 namespace PsychlopsSilverlight4test\r
149 {\r
150 \r
151         public class PsychlopsMain\r
152         {\r
153 \r
154                 Psychlops.Canvas cnvs;\r
155                 int i;\r
156                 double x, y, z, t, p, temp, xx, yy;\r
157 \r
158                 //Set Target Initial Value\r
159                 double TargetEcce = 100.0, TargetSize = 5.0, TargetNumber = 5, Rotate = 0.0;\r
160 \r
161                 //Set Background Initial Value\r
162                 double Axis = 0.0, BGRadii = 150, BGSize = 5.0;\r
163                 Psychlops.Widgets.Slider thetaSpeed, DotNumber;\r
164                 Image img;\r
165 \r
166 \r
167 \r
168                 public void psychlops_main()\r
169                 {\r
170                         cnvs = new Canvas(500, 500);\r
171 \r
172                         Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);\r
173 \r
174 \r
175                         img = new Image("Resources/logo.png");\r
176 \r
177                         Interval rng = new Interval();\r
178                         thetaSpeed = new Psychlops.Widgets.Slider("Label", -10 <= rng <= 10, 3.0);\r
179                         DotNumber  = new Psychlops.Widgets.Slider("DotNum",   0 <= rng <= 100, 50.0);\r
180 \r
181                         //Declare background dots and target\r
182                         Rectangle[] BGDot = new Rectangle[2048];\r
183                         for(int i=0; i<2048; i++){\r
184                                 BGDot[i]=new Rectangle();\r
185                         }\r
186                         Rectangle[] Target= new Rectangle[10];\r
187                         for(int i=0; i<10; i++){\r
188                                 Target[i]=new Rectangle();\r
189                         }\r
190 \r
191 \r
192                         //Declare Matrix to keep back ground dots' coordinate value\r
193                         double[] DotX=new double[2048];\r
194                         double[] DotY = new double[2048];\r
195 \r
196 \r
197                         //Set Independent variables to manipulate\r
198 \r
199 \r
200                         //Initialize positions of background dots\r
201                         for(int i=0; i<2048; i++){\r
202                                 t=2.0*Math.PI*Math.random(1.0);\r
203                                 p=2.0*Math.PI*Math.random(1.0);\r
204                                 DotX[i]=t;\r
205                                 DotY[i]=p;\r
206 \r
207                                 x=BGRadii*Math.cos(t)*Math.cos(p);\r
208                                 y=BGRadii*Math.sin(t)*Math.cos(p);\r
209                                 BGDot[i].set(BGSize, BGSize);\r
210                                 BGDot[i].centering().shift(x,y);\r
211                         }\r
212 \r
213                         //Initialize positions of targets\r
214                         for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize);\r
215 \r
216                         double COS, SIN;\r
217                         //DotNumber = 200;\r
218                         //Main stimulus loop\r
219                         while(true){\r
220                                 //Clear the main window\r
221                                 cnvs.clear();\r
222 \r
223 \r
224                                 temp=Axis/360*2*Math.PI;\r
225                                 COS=Math.cos(temp);\r
226                                 SIN=Math.sin(temp);\r
227 \r
228                                 //Calculate positions of background dots and set them\r
229                                 for(int i=0; i<DotNumber; i++){\r
230                                         //Calculate in polar coordinate\r
231                                         t=DotX[i]+2.0*Math.PI*thetaSpeed/360.0;\r
232                                         p=DotY[i];\r
233 \r
234                                         //Save current position\r
235                                         DotX[i]=t;\r
236 \r
237                                         //Convert to Decartes coordinate\r
238                                         x=BGRadii*Math.cos(t)*Math.cos(p);\r
239                                         y=BGRadii*Math.sin(t)*Math.cos(p);\r
240                                         z=BGRadii*Math.sin(p);\r
241                                         xx=x;\r
242                                         yy=SIN*y+COS*z;\r
243 \r
244                                         //Set Dotsize and Draw them\r
245                                         BGDot[i].set(BGSize, BGSize);\r
246                                         BGDot[i].centering().shift(xx,yy);\r
247                                         BGDot[i].draw( Color.blue );\r
248                                 }\r
249 \r
250                                 //Calculate positions of targets and set them\r
251                                 temp=Rotate*2*Math.PI/360.0;\r
252                                 for (int i = 0; i < 5; i++)\r
253                                 {\r
254                                         t = 2.0 * Math.PI/TargetNumber;\r
255                                         x = TargetEcce*Math.cos(i*t+temp);\r
256                                         y = TargetEcce*Math.sin(i*t+temp);\r
257                                         Target[i].centering().shift(x,y);\r
258                                         Target[i].fill = Color.yellow;\r
259                                         Target[i].draw();\r
260                                 }\r
261 \r
262                                 img.centering(Mouse.position).draw();\r
263 \r
264                                 cnvs.var(Mouse.position.x, 100, 100);\r
265                                 cnvs.var(Mouse.position.y, 100, 140);\r
266 \r
267                                 //Reflect drawing at the next frame;\r
268                                 cnvs.flip();\r
269                         }\r
270                 }\r
271         }\r
272 \r
273 }\r
274 */\r
275 \r
276 \r
277 /*using Psychlops;\r
278 \r
279 namespace PsychlopsSilverlight4test\r
280 {\r
281         public class PsychlopsMain\r
282         {\r
283                 public void psychlops_main()\r
284                 {\r
285                         var figure_type = Psychlops.Widgets.Browser.Element.byID("FIGURE");\r
286                         var size_x = Psychlops.Widgets.Browser.Element.byID("SIZE_X");\r
287                         var size_y = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");\r
288                         var shift_x = Psychlops.Widgets.Browser.Element.byID("SHIFT_X");\r
289                         var shift_y = Psychlops.Widgets.Browser.Element.byID("SHIFT_Y");\r
290                         var color_r = Psychlops.Widgets.Browser.Element.byID("COLOR_R");\r
291                         var color_g = Psychlops.Widgets.Browser.Element.byID("COLOR_G");\r
292                         var color_b = Psychlops.Widgets.Browser.Element.byID("COLOR_B");\r
293 \r
294                         Canvas window = new Canvas(300, 300);\r
295 \r
296                         var figure_r = new Rectangle();\r
297                         var figure_e = new Ellipse();\r
298                         Shape figure = figure_r;\r
299                         \r
300                         while (!Keyboard.esc.pushed())\r
301                         {\r
302                                 if (System.String.Compare(figure_type, "Rectangle") == 0)\r
303                                 {\r
304                                         figure_r.set(size_x, size_y);\r
305                                         figure = figure_r;\r
306                                 }\r
307                                 else\r
308                                 {\r
309                                         figure_e.set(size_x, size_y);\r
310                                         figure = figure_e;\r
311                                 }\r
312                                 figure.fill = new Color(color_r, color_g, color_b);\r
313 \r
314                                 window.clear(Color.black);\r
315                                 figure.centering().shift(shift_x, shift_y).draw();\r
316                                 window.flip();\r
317                         }\r
318                 }\r
319         }\r
320 \r
321 }\r
322 \r
323 \r
324 \r
325 \r
326 /*\r
327 using Psychlops;\r
328 \r
329 namespace Psychlops\r
330 {\r
331 \r
332         public class RandomDots\r
333         {\r
334                 Rectangle dot;\r
335                 public Point[] cood;\r
336                 public RandomDots()\r
337                 {\r
338                         cood = new Point[250];\r
339                         dot = new Rectangle(5, 5);\r
340                 }\r
341                 public void draw()\r
342                 {\r
343                         dot.fill = Color.white;\r
344                         foreach (Point p in cood)\r
345                         {\r
346                                 dot.centering(p).draw();\r
347                         }\r
348                 }\r
349         }\r
350 \r
351 }\r
352 \r
353 \r
354 \r
355 namespace PsychlopsSilverlight4test\r
356 {\r
357 \r
358         public class PsychlopsMain\r
359         {\r
360                 Canvas cnvs;\r
361                 Image img;\r
362                 Ellipse fixation;\r
363                 Shape shape;\r
364                 Color col;\r
365                 int isize = 100;\r
366                 double tfreq = 1;\r
367                 int frames;\r
368                 RandomDots dots;\r
369                 Group g;\r
370 \r
371                 public void psychlops_main()\r
372                 {\r
373                         cnvs = new Canvas(500, 500);\r
374                         g = new Group();\r
375                         img = new Image(isize * 2, isize * 2);\r
376                         Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
377                         g.append(img);\r
378                         g.rotation = 50;\r
379                         fixation = new Ellipse(10, 10);\r
380                         fixation.fill = Color.red;\r
381                         //var poly = new Rectangle(100, 100);\r
382                         var poly = new Letters("日本語");\r
383                         //var poly = new Polygon(); poly.append(0, 100); poly.append(-100, 0); poly.append(0, -100); poly.append(100, 0);\r
384                         //var poly = new Ellipse(100, 100);\r
385                         //var poly = new Line(0,0,100, 0);\r
386                         poly.fill = Color.red;\r
387                         poly.stroke = new Stroke { color = Color.yellow, thick = 1 };\r
388                         shape = poly;\r
389 \r
390                         var rng = new Interval();\r
391                         var slider = new Psychlops.Widgets.Slider("tesrt", -100 <= rng <= 100);\r
392 \r
393                         dots = new RandomDots();\r
394 \r
395 \r
396                         while (true)\r
397                         {\r
398                                 frames++;\r
399 \r
400 \r
401                                 cnvs.clear(new Color(Mouse.left.pressed() ? 0.75 : 0.5));\r
402                                 col.set(Math.random(1.0));\r
403 \r
404                                 /*if (frames % 2 == 0)\r
405                                 {\r
406                                         fixation.centering().shift(100, 100);\r
407                                         fixation.draw(new Stroke(Color.blue, 3));\r
408                                 }* /\r
409 \r
410                                 fixation.centering().shift(slider, 0);\r
411                                 fixation.draw(Color.red);\r
412 \r
413                                 //Figures.drawGabor(ref img, 20, 100, 1, 0, frames * 2.0 * Math.PI / tfreq / 60);\r
414                                 //Figures.drawGaussian(ref img, 20, 1);\r
415                                 //Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
416                                 //img.centering(Mouse.position);\r
417                                 //img.draw();\r
418                                 g.centering(Mouse.position).draw();\r
419                                 g.rotation += 1;\r
420 \r
421                                 shape.centering(Mouse.position).shift(100, 0);\r
422                                 shape.draw();\r
423                                 if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100);\r
424 \r
425                                 cnvs.var(frames, 0, 20);\r
426                                 //slider.value = frames / 100.0;\r
427 \r
428                                 /*if (frames % 2 != 0)\r
429                                 {\r
430                                         fixation.shift(100, 100);\r
431                                         fixation.draw(new Stroke(Color.green, 3));\r
432                                 }* /\r
433 \r
434                                 for (int i = 0; i < dots.cood.Length; i++)\r
435                                 {\r
436                                         dots.cood[i].set(Math.random(500), Math.random(500));\r
437                                 }\r
438                                 cnvs.var((double)slider, 200, 200);\r
439                                 dots.draw();\r
440 \r
441                                 cnvs.flip();\r
442                         }\r
443                 }\r
444         }\r
445 }\r
446 \r
447 **/\r
448 \r
449 \r
450 /*\r
451 \r
452 using Psychlops;\r
453 namespace PsychlopsSilverlight4test\r
454 {\r
455 \r
456         public class PsychlopsMain\r
457         {\r
458                 Canvas cnvs;\r
459                 Rectangle[] rect;\r
460                 int n;\r
461 \r
462                 public void psychlops_main()\r
463                 {\r
464                         n = 1;\r
465                         cnvs = new Canvas(500, 500);\r
466                         rect = new Rectangle[n];\r
467                         for (int i = 0; i < n; i++)\r
468                         {\r
469                                 rect[i] = new Rectangle(10, 10);\r
470                                 rect[i].fill = Color.red;\r
471                         }\r
472                         Interval rng = new Interval();\r
473                         var slider = new Psychlops.Widgets.Slider("Label", -100 <= rng <= 100);\r
474 \r
475                         while (true)\r
476                         {\r
477                                 cnvs.clear();\r
478                                 for (int i = 0; i < n; i++)\r
479                                 {\r
480                                         rect[i].centering().shift(slider * i*3, i*3).draw();\r
481                                 }\r
482                                 cnvs.flip();\r
483                         }\r
484                 }\r
485         }\r
486 }\r
487 \r
488 */