OSDN Git Service

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