OSDN Git Service

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