OSDN Git Service

Merge branch 'master' of git.sourceforge.jp:/gitroot/psychlops/silverlight
[psychlops/silverlight.git] / test4 / PsychlopsMain.cs
1 \r
2 using Psychlops;\r
3 \r
4 namespace PsychlopsSilverlight4test\r
5 {\r
6 \r
7         public class PsychlopsMain\r
8         {\r
9 \r
10                 Psychlops.Widgets.Slider rect_size;\r
11                 Psychlops.Widgets.Slider rect_lum;\r
12                 Psychlops.Widgets.Slider bg_lum;\r
13 \r
14 \r
15                 void RectLuminance()\r
16                 {\r
17                         Canvas display = new Canvas(Canvas.window);\r
18                         Interval rng = new Interval();\r
19                         rect_size = new Psychlops.Widgets.Slider("Rect Size", 1 < rng < 500, 10.0);\r
20                         rect_lum = new Psychlops.Widgets.Slider("Rect Luminance", 0.0 <= rng <= 1.0, 0.1);\r
21                         bg_lum = new Psychlops.Widgets.Slider("BG Luminance", 0.0 <= rng <= 1.0, 0.1);\r
22                         Ellipse drawee = new Ellipse(100, 100);\r
23                         display.showFPS();\r
24                         display.watchFPS();\r
25 \r
26                         Rectangle rect = new Rectangle(rect_size, rect_size);\r
27                         rect.centering();\r
28 \r
29 \r
30                         Clock before = new Clock(), after = new Clock();\r
31                         while (!Keyboard.esc.pushed())\r
32                         {\r
33                                 Display.clear(bg_lum);\r
34                                 rect.resize(rect_size, rect_size).draw(rect_lum);\r
35                                 after.update();\r
36                                 display.var((after - before).at_msec(), 100, 100, Color.green);\r
37                                 display.var((after - before).at_msec(), 100, 200, Color.green);\r
38                                 drawee.centering().shift(Math.random(100), 0);\r
39                                 drawee.draw(Color.black);\r
40                                 Display.flip();\r
41                         }\r
42 \r
43                 }\r
44 \r
45 \r
46                 public void psychlops_main()\r
47                 {\r
48                         RectLuminance();\r
49                 }\r
50 \r
51 \r
52         }\r
53 \r
54 }\r
55 \r
56 \r
57 \r
58 \r
59 \r
60 \r
61 \r
62 \r
63 \r
64 \r
65 \r
66 /*\r
67  using Psychlops;\r
68 \r
69 namespace PsychlopsSilverlight4test\r
70 {\r
71 \r
72         public class PsychlopsMain\r
73         {\r
74 \r
75                 Psychlops.Canvas cnvs;\r
76                 int i;\r
77                 double x, y, z, t, p, temp, xx, yy;\r
78 \r
79                 //Set Target Initial Value\r
80                 double TargetEcce = 100.0, TargetSize = 5.0, TargetNumber = 5, Rotate = 0.0;\r
81 \r
82                 //Set Background Initial Value\r
83                 double Axis = 0.0, BGRadii = 150, BGSize = 5.0;\r
84                 Psychlops.Widgets.Slider thetaSpeed, DotNumber;\r
85                 Image img;\r
86 \r
87 \r
88 \r
89                 public void psychlops_main()\r
90                 {\r
91                         cnvs = new Canvas(500, 500);\r
92 \r
93                         Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);\r
94 \r
95 \r
96                         img = new Image("Resources/logo.png");\r
97 \r
98                         Interval rng = new Interval();\r
99                         thetaSpeed = new Psychlops.Widgets.Slider("Label", -10 <= rng <= 10, 3.0);\r
100                         DotNumber  = new Psychlops.Widgets.Slider("DotNum",   0 <= rng <= 100, 50.0);\r
101 \r
102                         //Declare background dots and target\r
103                         Rectangle[] BGDot = new Rectangle[2048];\r
104                         for(int i=0; i<2048; i++){\r
105                                 BGDot[i]=new Rectangle();\r
106                         }\r
107                         Rectangle[] Target= new Rectangle[10];\r
108                         for(int i=0; i<10; i++){\r
109                                 Target[i]=new Rectangle();\r
110                         }\r
111 \r
112 \r
113                         //Declare Matrix to keep back ground dots' coordinate value\r
114                         double[] DotX=new double[2048];\r
115                         double[] DotY = new double[2048];\r
116 \r
117 \r
118                         //Set Independent variables to manipulate\r
119 \r
120 \r
121                         //Initialize positions of background dots\r
122                         for(int i=0; i<2048; i++){\r
123                                 t=2.0*Math.PI*Math.random(1.0);\r
124                                 p=2.0*Math.PI*Math.random(1.0);\r
125                                 DotX[i]=t;\r
126                                 DotY[i]=p;\r
127 \r
128                                 x=BGRadii*Math.cos(t)*Math.cos(p);\r
129                                 y=BGRadii*Math.sin(t)*Math.cos(p);\r
130                                 BGDot[i].set(BGSize, BGSize);\r
131                                 BGDot[i].centering().shift(x,y);\r
132                         }\r
133 \r
134                         //Initialize positions of targets\r
135                         for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize);\r
136 \r
137                         double COS, SIN;\r
138                         //DotNumber = 200;\r
139                         //Main stimulus loop\r
140                         while(true){\r
141                                 //Clear the main window\r
142                                 cnvs.clear();\r
143 \r
144 \r
145                                 temp=Axis/360*2*Math.PI;\r
146                                 COS=Math.cos(temp);\r
147                                 SIN=Math.sin(temp);\r
148 \r
149                                 //Calculate positions of background dots and set them\r
150                                 for(int i=0; i<DotNumber; i++){\r
151                                         //Calculate in polar coordinate\r
152                                         t=DotX[i]+2.0*Math.PI*thetaSpeed/360.0;\r
153                                         p=DotY[i];\r
154 \r
155                                         //Save current position\r
156                                         DotX[i]=t;\r
157 \r
158                                         //Convert to Decartes coordinate\r
159                                         x=BGRadii*Math.cos(t)*Math.cos(p);\r
160                                         y=BGRadii*Math.sin(t)*Math.cos(p);\r
161                                         z=BGRadii*Math.sin(p);\r
162                                         xx=x;\r
163                                         yy=SIN*y+COS*z;\r
164 \r
165                                         //Set Dotsize and Draw them\r
166                                         BGDot[i].set(BGSize, BGSize);\r
167                                         BGDot[i].centering().shift(xx,yy);\r
168                                         BGDot[i].draw( Color.blue );\r
169                                 }\r
170 \r
171                                 //Calculate positions of targets and set them\r
172                                 temp=Rotate*2*Math.PI/360.0;\r
173                                 for (int i = 0; i < 5; i++)\r
174                                 {\r
175                                         t = 2.0 * Math.PI/TargetNumber;\r
176                                         x = TargetEcce*Math.cos(i*t+temp);\r
177                                         y = TargetEcce*Math.sin(i*t+temp);\r
178                                         Target[i].centering().shift(x,y);\r
179                                         Target[i].fill = Color.yellow;\r
180                                         Target[i].draw();\r
181                                 }\r
182 \r
183                                 img.centering(Mouse.position).draw();\r
184 \r
185                                 cnvs.var(Mouse.position.x, 100, 100);\r
186                                 cnvs.var(Mouse.position.y, 100, 140);\r
187 \r
188                                 //Reflect drawing at the next frame;\r
189                                 cnvs.flip();\r
190                         }\r
191                 }\r
192         }\r
193 \r
194 }\r
195 */\r
196 \r
197 \r
198 /*using Psychlops;\r
199 \r
200 namespace PsychlopsSilverlight4test\r
201 {\r
202         public class PsychlopsMain\r
203         {\r
204                 public void psychlops_main()\r
205                 {\r
206                         var figure_type = Psychlops.Widgets.Browser.Element.byID("FIGURE");\r
207                         var size_x = Psychlops.Widgets.Browser.Element.byID("SIZE_X");\r
208                         var size_y = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");\r
209                         var shift_x = Psychlops.Widgets.Browser.Element.byID("SHIFT_X");\r
210                         var shift_y = Psychlops.Widgets.Browser.Element.byID("SHIFT_Y");\r
211                         var color_r = Psychlops.Widgets.Browser.Element.byID("COLOR_R");\r
212                         var color_g = Psychlops.Widgets.Browser.Element.byID("COLOR_G");\r
213                         var color_b = Psychlops.Widgets.Browser.Element.byID("COLOR_B");\r
214 \r
215                         Canvas window = new Canvas(300, 300);\r
216 \r
217                         var figure_r = new Rectangle();\r
218                         var figure_e = new Ellipse();\r
219                         Shape figure = figure_r;\r
220                         \r
221                         while (!Keyboard.esc.pushed())\r
222                         {\r
223                                 if (System.String.Compare(figure_type, "Rectangle") == 0)\r
224                                 {\r
225                                         figure_r.set(size_x, size_y);\r
226                                         figure = figure_r;\r
227                                 }\r
228                                 else\r
229                                 {\r
230                                         figure_e.set(size_x, size_y);\r
231                                         figure = figure_e;\r
232                                 }\r
233                                 figure.fill = new Color(color_r, color_g, color_b);\r
234 \r
235                                 window.clear(Color.black);\r
236                                 figure.centering().shift(shift_x, shift_y).draw();\r
237                                 window.flip();\r
238                         }\r
239                 }\r
240         }\r
241 \r
242 }\r
243 \r
244 \r
245 \r
246 \r
247 /*\r
248 using Psychlops;\r
249 \r
250 namespace Psychlops\r
251 {\r
252 \r
253         public class RandomDots\r
254         {\r
255                 Rectangle dot;\r
256                 public Point[] cood;\r
257                 public RandomDots()\r
258                 {\r
259                         cood = new Point[250];\r
260                         dot = new Rectangle(5, 5);\r
261                 }\r
262                 public void draw()\r
263                 {\r
264                         dot.fill = Color.white;\r
265                         foreach (Point p in cood)\r
266                         {\r
267                                 dot.centering(p).draw();\r
268                         }\r
269                 }\r
270         }\r
271 \r
272 }\r
273 \r
274 \r
275 \r
276 namespace PsychlopsSilverlight4test\r
277 {\r
278 \r
279         public class PsychlopsMain\r
280         {\r
281                 Canvas cnvs;\r
282                 Image img;\r
283                 Ellipse fixation;\r
284                 Shape shape;\r
285                 Color col;\r
286                 int isize = 100;\r
287                 double tfreq = 1;\r
288                 int frames;\r
289                 RandomDots dots;\r
290                 Group g;\r
291 \r
292                 public void psychlops_main()\r
293                 {\r
294                         cnvs = new Canvas(500, 500);\r
295                         g = new Group();\r
296                         img = new Image(isize * 2, isize * 2);\r
297                         Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
298                         g.append(img);\r
299                         g.rotation = 50;\r
300                         fixation = new Ellipse(10, 10);\r
301                         fixation.fill = Color.red;\r
302                         //var poly = new Rectangle(100, 100);\r
303                         var poly = new Letters("日本語");\r
304                         //var poly = new Polygon(); poly.append(0, 100); poly.append(-100, 0); poly.append(0, -100); poly.append(100, 0);\r
305                         //var poly = new Ellipse(100, 100);\r
306                         //var poly = new Line(0,0,100, 0);\r
307                         poly.fill = Color.red;\r
308                         poly.stroke = new Stroke { color = Color.yellow, thick = 1 };\r
309                         shape = poly;\r
310 \r
311                         var rng = new Interval();\r
312                         var slider = new Psychlops.Widgets.Slider("tesrt", -100 <= rng <= 100);\r
313 \r
314                         dots = new RandomDots();\r
315 \r
316 \r
317                         while (true)\r
318                         {\r
319                                 frames++;\r
320 \r
321 \r
322                                 cnvs.clear(new Color(Mouse.left.pressed() ? 0.75 : 0.5));\r
323                                 col.set(Math.random(1.0));\r
324 \r
325                                 /*if (frames % 2 == 0)\r
326                                 {\r
327                                         fixation.centering().shift(100, 100);\r
328                                         fixation.draw(new Stroke(Color.blue, 3));\r
329                                 }* /\r
330 \r
331                                 fixation.centering().shift(slider, 0);\r
332                                 fixation.draw(Color.red);\r
333 \r
334                                 //Figures.drawGabor(ref img, 20, 100, 1, 0, frames * 2.0 * Math.PI / tfreq / 60);\r
335                                 //Figures.drawGaussian(ref img, 20, 1);\r
336                                 //Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
337                                 //img.centering(Mouse.position);\r
338                                 //img.draw();\r
339                                 g.centering(Mouse.position).draw();\r
340                                 g.rotation += 1;\r
341 \r
342                                 shape.centering(Mouse.position).shift(100, 0);\r
343                                 shape.draw();\r
344                                 if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100);\r
345 \r
346                                 cnvs.var(frames, 0, 20);\r
347                                 //slider.value = frames / 100.0;\r
348 \r
349                                 /*if (frames % 2 != 0)\r
350                                 {\r
351                                         fixation.shift(100, 100);\r
352                                         fixation.draw(new Stroke(Color.green, 3));\r
353                                 }* /\r
354 \r
355                                 for (int i = 0; i < dots.cood.Length; i++)\r
356                                 {\r
357                                         dots.cood[i].set(Math.random(500), Math.random(500));\r
358                                 }\r
359                                 cnvs.var((double)slider, 200, 200);\r
360                                 dots.draw();\r
361 \r
362                                 cnvs.flip();\r
363                         }\r
364                 }\r
365         }\r
366 }\r
367 \r
368 **/\r
369 \r
370 \r
371 /*\r
372 \r
373 using Psychlops;\r
374 namespace PsychlopsSilverlight4test\r
375 {\r
376 \r
377         public class PsychlopsMain\r
378         {\r
379                 Canvas cnvs;\r
380                 Rectangle[] rect;\r
381                 int n;\r
382 \r
383                 public void psychlops_main()\r
384                 {\r
385                         n = 1;\r
386                         cnvs = new Canvas(500, 500);\r
387                         rect = new Rectangle[n];\r
388                         for (int i = 0; i < n; i++)\r
389                         {\r
390                                 rect[i] = new Rectangle(10, 10);\r
391                                 rect[i].fill = Color.red;\r
392                         }\r
393                         Interval rng = new Interval();\r
394                         var slider = new Psychlops.Widgets.Slider("Label", -100 <= rng <= 100);\r
395 \r
396                         while (true)\r
397                         {\r
398                                 cnvs.clear();\r
399                                 for (int i = 0; i < n; i++)\r
400                                 {\r
401                                         rect[i].centering().shift(slider * i*3, i*3).draw();\r
402                                 }\r
403                                 cnvs.flip();\r
404                         }\r
405                 }\r
406         }\r
407 }\r
408 \r
409 */