OSDN Git Service

5e19dfb4acfc28ad82b2d27ff101177f5b1724df
[psychlops/silverlight.git] / test4 / PsychlopsMain.cs
1 using Psychlops;\r
2 \r
3 namespace PsychlopsSilverlight4test\r
4 {\r
5 \r
6         public class PsychlopsMain\r
7         {\r
8 \r
9                 Psychlops.Canvas cnvs;\r
10                 int i;\r
11                 double x, y, z, t, p, temp, xx, yy;\r
12 \r
13                 //Set Target Initial Value\r
14                 double TargetEcce = 100.0, TargetSize = 5.0, TargetNumber = 5, Rotate = 0.0;\r
15 \r
16                 //Set Background Initial Value\r
17                 double Axis = 0.0, BGRadii = 150, BGSize = 5.0;\r
18                 Psychlops.Widgets.Slider thetaSpeed, DotNumber;\r
19                 Image img;\r
20 \r
21 \r
22 \r
23                 public void psychlops_main()\r
24                 {\r
25                         cnvs = new Canvas(500, 500);\r
26 \r
27                         Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);\r
28 \r
29 \r
30                         img = new Image("Resources/logo.png");\r
31 \r
32                         Interval rng = new Interval();\r
33                         thetaSpeed = new Psychlops.Widgets.Slider("Label", -10 <= rng <= 10, 3.0);\r
34                         DotNumber  = new Psychlops.Widgets.Slider("DotNum",   0 <= rng <= 100, 50.0);\r
35 \r
36                         //Declare background dots and target\r
37                         Rectangle[] BGDot = new Rectangle[2048];\r
38                         for(int i=0; i<2048; i++){\r
39                                 BGDot[i]=new Rectangle();\r
40                         }\r
41                         Rectangle[] Target= new Rectangle[10];\r
42                         for(int i=0; i<10; i++){\r
43                                 Target[i]=new Rectangle();\r
44                         }\r
45 \r
46 \r
47                         //Declare Matrix to keep back ground dots' coordinate value\r
48                         double[] DotX=new double[2048];\r
49                         double[] DotY = new double[2048];\r
50 \r
51 \r
52                         //Set Independent variables to manipulate\r
53 \r
54 \r
55                         //Initialize positions of background dots\r
56                         for(int i=0; i<2048; i++){\r
57                                 t=2.0*Math.PI*Math.random(1.0);\r
58                                 p=2.0*Math.PI*Math.random(1.0);\r
59                                 DotX[i]=t;\r
60                                 DotY[i]=p;\r
61 \r
62                                 x=BGRadii*Math.cos(t)*Math.cos(p);\r
63                                 y=BGRadii*Math.sin(t)*Math.cos(p);\r
64                                 BGDot[i].set(BGSize, BGSize);\r
65                                 BGDot[i].centering().shift(x,y);\r
66                         }\r
67 \r
68                         //Initialize positions of targets\r
69                         for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize);\r
70 \r
71                         double COS, SIN;\r
72                         //DotNumber = 200;\r
73                         //Main stimulus loop\r
74                         while(true){\r
75                                 //Clear the main window\r
76                                 cnvs.clear();\r
77 \r
78 \r
79                                 temp=Axis/360*2*Math.PI;\r
80                                 COS=Math.cos(temp);\r
81                                 SIN=Math.sin(temp);\r
82 \r
83                                 //Calculate positions of background dots and set them\r
84                                 for(int i=0; i<DotNumber; i++){\r
85                                         //Calculate in polar coordinate\r
86                                         t=DotX[i]+2.0*Math.PI*thetaSpeed/360.0;\r
87                                         p=DotY[i];\r
88 \r
89                                         //Save current position\r
90                                         DotX[i]=t;\r
91 \r
92                                         //Convert to Decartes coordinate\r
93                                         x=BGRadii*Math.cos(t)*Math.cos(p);\r
94                                         y=BGRadii*Math.sin(t)*Math.cos(p);\r
95                                         z=BGRadii*Math.sin(p);\r
96                                         xx=x;\r
97                                         yy=SIN*y+COS*z;\r
98 \r
99                                         //Set Dotsize and Draw them\r
100                                         BGDot[i].set(BGSize, BGSize);\r
101                                         BGDot[i].centering().shift(xx,yy);\r
102                                         BGDot[i].draw( Color.blue );\r
103                                 }\r
104 \r
105                                 //Calculate positions of targets and set them\r
106                                 temp=Rotate*2*Math.PI/360.0;\r
107                                 for (int i = 0; i < 5; i++)\r
108                                 {\r
109                                         t = 2.0 * Math.PI/TargetNumber;\r
110                                         x = TargetEcce*Math.cos(i*t+temp);\r
111                                         y = TargetEcce*Math.sin(i*t+temp);\r
112                                         Target[i].centering().shift(x,y);\r
113                                         Target[i].fill = Color.yellow;\r
114                                         Target[i].draw();\r
115                                 }\r
116 \r
117                                 img.centering(Mouse.position).draw();\r
118 \r
119                                 cnvs.var(Mouse.position.x, 100, 100);\r
120                                 cnvs.var(Mouse.position.y, 100, 140);\r
121 \r
122                                 //Reflect drawing at the next frame;\r
123                                 cnvs.flip();\r
124                         }\r
125                 }\r
126         }\r
127 \r
128 }\r
129 \r
130 \r
131 \r
132 /*using Psychlops;\r
133 \r
134 namespace PsychlopsSilverlight4test\r
135 {\r
136         public class PsychlopsMain\r
137         {\r
138                 public void psychlops_main()\r
139                 {\r
140                         var figure_type = Psychlops.Widgets.Browser.Element.byID("FIGURE");\r
141                         var size_x = Psychlops.Widgets.Browser.Element.byID("SIZE_X");\r
142                         var size_y = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");\r
143                         var shift_x = Psychlops.Widgets.Browser.Element.byID("SHIFT_X");\r
144                         var shift_y = Psychlops.Widgets.Browser.Element.byID("SHIFT_Y");\r
145                         var color_r = Psychlops.Widgets.Browser.Element.byID("COLOR_R");\r
146                         var color_g = Psychlops.Widgets.Browser.Element.byID("COLOR_G");\r
147                         var color_b = Psychlops.Widgets.Browser.Element.byID("COLOR_B");\r
148 \r
149                         Canvas window = new Canvas(300, 300);\r
150 \r
151                         var figure_r = new Rectangle();\r
152                         var figure_e = new Ellipse();\r
153                         Shape figure = figure_r;\r
154                         \r
155                         while (!Keyboard.esc.pushed())\r
156                         {\r
157                                 if (System.String.Compare(figure_type, "Rectangle") == 0)\r
158                                 {\r
159                                         figure_r.set(size_x, size_y);\r
160                                         figure = figure_r;\r
161                                 }\r
162                                 else\r
163                                 {\r
164                                         figure_e.set(size_x, size_y);\r
165                                         figure = figure_e;\r
166                                 }\r
167                                 figure.fill = new Color(color_r, color_g, color_b);\r
168 \r
169                                 window.clear(Color.black);\r
170                                 figure.centering().shift(shift_x, shift_y).draw();\r
171                                 window.flip();\r
172                         }\r
173                 }\r
174         }\r
175 \r
176 }\r
177 \r
178 \r
179 \r
180 \r
181 /*\r
182 using Psychlops;\r
183 \r
184 namespace Psychlops\r
185 {\r
186 \r
187         public class RandomDots\r
188         {\r
189                 Rectangle dot;\r
190                 public Point[] cood;\r
191                 public RandomDots()\r
192                 {\r
193                         cood = new Point[250];\r
194                         dot = new Rectangle(5, 5);\r
195                 }\r
196                 public void draw()\r
197                 {\r
198                         dot.fill = Color.white;\r
199                         foreach (Point p in cood)\r
200                         {\r
201                                 dot.centering(p).draw();\r
202                         }\r
203                 }\r
204         }\r
205 \r
206 }\r
207 \r
208 \r
209 \r
210 namespace PsychlopsSilverlight4test\r
211 {\r
212 \r
213         public class PsychlopsMain\r
214         {\r
215                 Canvas cnvs;\r
216                 Image img;\r
217                 Ellipse fixation;\r
218                 Shape shape;\r
219                 Color col;\r
220                 int isize = 100;\r
221                 double tfreq = 1;\r
222                 int frames;\r
223                 RandomDots dots;\r
224                 Group g;\r
225 \r
226                 public void psychlops_main()\r
227                 {\r
228                         cnvs = new Canvas(500, 500);\r
229                         g = new Group();\r
230                         img = new Image(isize * 2, isize * 2);\r
231                         Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
232                         g.append(img);\r
233                         g.rotation = 50;\r
234                         fixation = new Ellipse(10, 10);\r
235                         fixation.fill = Color.red;\r
236                         //var poly = new Rectangle(100, 100);\r
237                         var poly = new Letters("日本語");\r
238                         //var poly = new Polygon(); poly.append(0, 100); poly.append(-100, 0); poly.append(0, -100); poly.append(100, 0);\r
239                         //var poly = new Ellipse(100, 100);\r
240                         //var poly = new Line(0,0,100, 0);\r
241                         poly.fill = Color.red;\r
242                         poly.stroke = new Stroke { color = Color.yellow, thick = 1 };\r
243                         shape = poly;\r
244 \r
245                         var rng = new Interval();\r
246                         var slider = new Psychlops.Widgets.Slider("tesrt", -100 <= rng <= 100);\r
247 \r
248                         dots = new RandomDots();\r
249 \r
250 \r
251                         while (true)\r
252                         {\r
253                                 frames++;\r
254 \r
255 \r
256                                 cnvs.clear(new Color(Mouse.left.pressed() ? 0.75 : 0.5));\r
257                                 col.set(Math.random(1.0));\r
258 \r
259                                 /*if (frames % 2 == 0)\r
260                                 {\r
261                                         fixation.centering().shift(100, 100);\r
262                                         fixation.draw(new Stroke(Color.blue, 3));\r
263                                 }* /\r
264 \r
265                                 fixation.centering().shift(slider, 0);\r
266                                 fixation.draw(Color.red);\r
267 \r
268                                 //Figures.drawGabor(ref img, 20, 100, 1, 0, frames * 2.0 * Math.PI / tfreq / 60);\r
269                                 //Figures.drawGaussian(ref img, 20, 1);\r
270                                 //Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
271                                 //img.centering(Mouse.position);\r
272                                 //img.draw();\r
273                                 g.centering(Mouse.position).draw();\r
274                                 g.rotation += 1;\r
275 \r
276                                 shape.centering(Mouse.position).shift(100, 0);\r
277                                 shape.draw();\r
278                                 if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100);\r
279 \r
280                                 cnvs.var(frames, 0, 20);\r
281                                 //slider.value = frames / 100.0;\r
282 \r
283                                 /*if (frames % 2 != 0)\r
284                                 {\r
285                                         fixation.shift(100, 100);\r
286                                         fixation.draw(new Stroke(Color.green, 3));\r
287                                 }* /\r
288 \r
289                                 for (int i = 0; i < dots.cood.Length; i++)\r
290                                 {\r
291                                         dots.cood[i].set(Math.random(500), Math.random(500));\r
292                                 }\r
293                                 cnvs.var((double)slider, 200, 200);\r
294                                 dots.draw();\r
295 \r
296                                 cnvs.flip();\r
297                         }\r
298                 }\r
299         }\r
300 }\r
301 \r
302 **/\r
303 \r
304 \r
305 /*\r
306 \r
307 using Psychlops;\r
308 namespace PsychlopsSilverlight4test\r
309 {\r
310 \r
311         public class PsychlopsMain\r
312         {\r
313                 Canvas cnvs;\r
314                 Rectangle[] rect;\r
315                 int n;\r
316 \r
317                 public void psychlops_main()\r
318                 {\r
319                         n = 1;\r
320                         cnvs = new Canvas(500, 500);\r
321                         rect = new Rectangle[n];\r
322                         for (int i = 0; i < n; i++)\r
323                         {\r
324                                 rect[i] = new Rectangle(10, 10);\r
325                                 rect[i].fill = Color.red;\r
326                         }\r
327                         Interval rng = new Interval();\r
328                         var slider = new Psychlops.Widgets.Slider("Label", -100 <= rng <= 100);\r
329 \r
330                         while (true)\r
331                         {\r
332                                 cnvs.clear();\r
333                                 for (int i = 0; i < n; i++)\r
334                                 {\r
335                                         rect[i].centering().shift(slider * i*3, i*3).draw();\r
336                                 }\r
337                                 cnvs.flip();\r
338                         }\r
339                 }\r
340         }\r
341 }\r
342 \r
343 */