OSDN Git Service

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