OSDN Git Service

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