OSDN Git Service

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