OSDN Git Service

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