OSDN Git Service

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