OSDN Git Service

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