OSDN Git Service

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