1 ///+ Prefix linkto BasicCode1
\r
2 //// Lines for set up Psychlops environment
\r
5 namespace PsychlopsSilverlight4test
\r
8 public class PsychlopsMain
\r
9 {///- Prefix linkto BasicCode1
\r
13 //// Psychlops runs at the first line of this function psychlops_main().
\r
14 public void psychlops_main()
\r
16 ///+ 0 linkto BasicCode3_1a
\r
17 ////Prepare global parameters
\r
18 int maxrectnum = 200;
\r
20 double rectsize = 5.0;
\r
21 Rectangle[] rect = StaticFunctions.NewArray<Rectangle>(maxrectnum);
\r
22 double[] rectcolorR = new double[maxrectnum];
\r
23 double[] rectcolorG = new double[maxrectnum];
\r
24 double[] rectcolorB = new double[maxrectnum];
\r
25 ///- 0 linkto BasicCode3_1a
\r
27 Canvas window = new Canvas(Canvas.window);
\r
29 ///+ 1 linkto BasicCode3_1a
\r
31 for (int i = 0; i < rectnum; i++)
\r
34 ////set positions and sizes
\r
35 rect[i].set(rectsize, rectsize); //Set a size of rectangles.
\r
36 rect[i].centering();
\r
37 rect[i].shift((i - 0.5 * rectnum) * rectsize * 1.5,
\r
38 (i - 0.5 * rectnum) * rectsize * 1.5); //Move Rectangles to initial positions
\r
42 rectcolorR[i] = Math.random(1.0) * 0.5; //Set R values. Note that "i" is converted to double-type.
\r
43 rectcolorG[i] = Math.random(1.0) * 0.5; //Set G values. Note that "i" is converted to double-type.
\r
44 rectcolorB[i] = Math.random(1.0) * 0.5; //Set B values. Note that "i" is converted to double-type.
\r
47 ///- 1 linkto BasicCode3_1a
\r
51 ///+ 2.1 linkto BasicCode3_2a
\r
52 ////Prepare variables for movie control;
\r
55 double Horizontal_shift, Vertical_shift;
\r
56 ///- 2.1 linkto BasicCode3_2a
\r
58 while (!Keyboard.esc.pushed())
\r
60 window.clear(Color.black);
\r
61 for (int i = 0; i < rectnum; i++)
\r
64 ////set positions and sizes
\r
66 Horizontal_shift = Math.sin(2 * Math.PI * ((double)frame / 30.0)) * motion_dir * 100.0; //Calculate horizontal displacement from the center.
\r
67 Vertical_shift = Math.sin(2 * Math.PI * ((double)frame / 30.0)) * motion_dir * 0.0;//Calculate vertical displacement from the center.
\r
68 rect[i].resize(rectsize, rectsize); //Resize rectangles.
\r
69 rect[i].centering(); //Rectangles are moved to the center...
\r
70 rect[i].shift(Horizontal_shift + (i - 0.5 * rectnum) * rectsize * 1.5,
\r
71 Vertical_shift + (i - 0.5 * rectnum) * rectsize * 1.5); //and then move to designated positions
\r
74 ///+ 2.3 linkto BasicCode3_2a
\r
76 rectcolorR[i] = Math.random(1.0) * 0.5; //Set R values. Note that "i" is converted to double-type.
\r
77 rectcolorG[i] = Math.random(1.0) * 0.5; //Set G values. Note that "i" is converted to double-type.
\r
78 rectcolorB[i] = Math.random(1.0) * 0.5; //Set B values. Note that "i" is converted to double-type.
\r
79 ///- 2.3 linkto BasicCode3_2a
\r
82 ///+ 2.4 linkto BasicCode3_1a
\r
83 for (int i = 0; i < rectnum; i++)
\r
85 rect[i].draw(new Color(rectcolorR[i], rectcolorG[i], rectcolorB[i])); //draw objects by designated colors.
\r
88 ///- 2.4 linkto BasicCode3_1a
\r
108 namespace PsychlopsSilverlight4test
\r
111 public class PsychlopsMain
\r
113 void RectLuminance()
\r
115 Canvas display = new Canvas(Canvas.window);
\r
116 Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);
\r
117 Letters le = new Letters("Reload to restart");
\r
118 le.fill = Color.black;
\r
119 le.align = Letters.HorizontalAlign.center;
\r
121 while (!Keyboard.esc.pushed())
\r
123 Display.clear(Color.white);
\r
124 le.centering().shift(-200,-10).draw();
\r
131 public void psychlops_main()
\r
154 namespace PsychlopsSilverlight4test
\r
157 public class PsychlopsMain
\r
160 Psychlops.Canvas cnvs;
\r
162 double x, y, z, t, p, temp, xx, yy;
\r
164 //Set Target Initial Value
\r
165 double TargetEcce = 100.0, TargetSize = 5.0, TargetNumber = 5, Rotate = 0.0;
\r
167 //Set Background Initial Value
\r
168 double Axis = 0.0, BGRadii = 150, BGSize = 5.0;
\r
169 Psychlops.Widgets.Slider thetaSpeed, DotNumber;
\r
174 public void psychlops_main()
\r
176 cnvs = new Canvas(500, 500);
\r
178 Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);
\r
181 img = new Image("Resources/logo.png");
\r
183 Interval rng = new Interval();
\r
184 thetaSpeed = new Psychlops.Widgets.Slider("Label", -10 <= rng <= 10, 3.0);
\r
185 DotNumber = new Psychlops.Widgets.Slider("DotNum", 0 <= rng <= 100, 50.0);
\r
187 //Declare background dots and target
\r
188 Rectangle[] BGDot = new Rectangle[2048];
\r
189 for(int i=0; i<2048; i++){
\r
190 BGDot[i]=new Rectangle();
\r
192 Rectangle[] Target= new Rectangle[10];
\r
193 for(int i=0; i<10; i++){
\r
194 Target[i]=new Rectangle();
\r
198 //Declare Matrix to keep back ground dots' coordinate value
\r
199 double[] DotX=new double[2048];
\r
200 double[] DotY = new double[2048];
\r
203 //Set Independent variables to manipulate
\r
206 //Initialize positions of background dots
\r
207 for(int i=0; i<2048; i++){
\r
208 t=2.0*Math.PI*Math.random(1.0);
\r
209 p=2.0*Math.PI*Math.random(1.0);
\r
213 x=BGRadii*Math.cos(t)*Math.cos(p);
\r
214 y=BGRadii*Math.sin(t)*Math.cos(p);
\r
215 BGDot[i].set(BGSize, BGSize);
\r
216 BGDot[i].centering().shift(x,y);
\r
219 //Initialize positions of targets
\r
220 for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize);
\r
224 //Main stimulus loop
\r
226 //Clear the main window
\r
230 temp=Axis/360*2*Math.PI;
\r
231 COS=Math.cos(temp);
\r
232 SIN=Math.sin(temp);
\r
234 //Calculate positions of background dots and set them
\r
235 for(int i=0; i<DotNumber; i++){
\r
236 //Calculate in polar coordinate
\r
237 t=DotX[i]+2.0*Math.PI*thetaSpeed/360.0;
\r
240 //Save current position
\r
243 //Convert to Decartes coordinate
\r
244 x=BGRadii*Math.cos(t)*Math.cos(p);
\r
245 y=BGRadii*Math.sin(t)*Math.cos(p);
\r
246 z=BGRadii*Math.sin(p);
\r
250 //Set Dotsize and Draw them
\r
251 BGDot[i].set(BGSize, BGSize);
\r
252 BGDot[i].centering().shift(xx,yy);
\r
253 BGDot[i].draw( Color.blue );
\r
256 //Calculate positions of targets and set them
\r
257 temp=Rotate*2*Math.PI/360.0;
\r
258 for (int i = 0; i < 5; i++)
\r
260 t = 2.0 * Math.PI/TargetNumber;
\r
261 x = TargetEcce*Math.cos(i*t+temp);
\r
262 y = TargetEcce*Math.sin(i*t+temp);
\r
263 Target[i].centering().shift(x,y);
\r
264 Target[i].fill = Color.yellow;
\r
268 img.centering(Mouse.position).draw();
\r
270 cnvs.var(Mouse.position.x, 100, 100);
\r
271 cnvs.var(Mouse.position.y, 100, 140);
\r
273 //Reflect drawing at the next frame;
\r
285 namespace PsychlopsSilverlight4test
\r
287 public class PsychlopsMain
\r
289 public void psychlops_main()
\r
291 var figure_type = Psychlops.Widgets.Browser.Element.byID("FIGURE");
\r
292 var size_x = Psychlops.Widgets.Browser.Element.byID("SIZE_X");
\r
293 var size_y = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");
\r
294 var shift_x = Psychlops.Widgets.Browser.Element.byID("SHIFT_X");
\r
295 var shift_y = Psychlops.Widgets.Browser.Element.byID("SHIFT_Y");
\r
296 var color_r = Psychlops.Widgets.Browser.Element.byID("COLOR_R");
\r
297 var color_g = Psychlops.Widgets.Browser.Element.byID("COLOR_G");
\r
298 var color_b = Psychlops.Widgets.Browser.Element.byID("COLOR_B");
\r
300 Canvas window = new Canvas(300, 300);
\r
302 var figure_r = new Rectangle();
\r
303 var figure_e = new Ellipse();
\r
304 Shape figure = figure_r;
\r
306 while (!Keyboard.esc.pushed())
\r
308 if (System.String.Compare(figure_type, "Rectangle") == 0)
\r
310 figure_r.set(size_x, size_y);
\r
315 figure_e.set(size_x, size_y);
\r
318 figure.fill = new Color(color_r, color_g, color_b);
\r
320 window.clear(Color.black);
\r
321 figure.centering().shift(shift_x, shift_y).draw();
\r
335 namespace Psychlops
\r
338 public class RandomDots
\r
341 public Point[] cood;
\r
342 public RandomDots()
\r
344 cood = new Point[250];
\r
345 dot = new Rectangle(5, 5);
\r
349 dot.fill = Color.white;
\r
350 foreach (Point p in cood)
\r
352 dot.centering(p).draw();
\r
361 namespace PsychlopsSilverlight4test
\r
364 public class PsychlopsMain
\r
377 public void psychlops_main()
\r
379 cnvs = new Canvas(500, 500);
\r
381 img = new Image(isize * 2, isize * 2);
\r
382 Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);
\r
385 fixation = new Ellipse(10, 10);
\r
386 fixation.fill = Color.red;
\r
387 //var poly = new Rectangle(100, 100);
\r
388 var poly = new Letters("日本語");
\r
389 //var poly = new Polygon(); poly.append(0, 100); poly.append(-100, 0); poly.append(0, -100); poly.append(100, 0);
\r
390 //var poly = new Ellipse(100, 100);
\r
391 //var poly = new Line(0,0,100, 0);
\r
392 poly.fill = Color.red;
\r
393 poly.stroke = new Stroke { color = Color.yellow, thick = 1 };
\r
396 var rng = new Interval();
\r
397 var slider = new Psychlops.Widgets.Slider("tesrt", -100 <= rng <= 100);
\r
399 dots = new RandomDots();
\r
407 cnvs.clear(new Color(Mouse.left.pressed() ? 0.75 : 0.5));
\r
408 col.set(Math.random(1.0));
\r
410 /*if (frames % 2 == 0)
\r
412 fixation.centering().shift(100, 100);
\r
413 fixation.draw(new Stroke(Color.blue, 3));
\r
416 fixation.centering().shift(slider, 0);
\r
417 fixation.draw(Color.red);
\r
419 //Figures.drawGabor(ref img, 20, 100, 1, 0, frames * 2.0 * Math.PI / tfreq / 60);
\r
420 //Figures.drawGaussian(ref img, 20, 1);
\r
421 //Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);
\r
422 //img.centering(Mouse.position);
\r
424 g.centering(Mouse.position).draw();
\r
427 shape.centering(Mouse.position).shift(100, 0);
\r
429 if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100);
\r
431 cnvs.var(frames, 0, 20);
\r
432 //slider.value = frames / 100.0;
\r
434 /*if (frames % 2 != 0)
\r
436 fixation.shift(100, 100);
\r
437 fixation.draw(new Stroke(Color.green, 3));
\r
440 for (int i = 0; i < dots.cood.Length; i++)
\r
442 dots.cood[i].set(Math.random(500), Math.random(500));
\r
444 cnvs.var((double)slider, 200, 200);
\r
459 namespace PsychlopsSilverlight4test
\r
462 public class PsychlopsMain
\r
468 public void psychlops_main()
\r
471 cnvs = new Canvas(500, 500);
\r
472 rect = new Rectangle[n];
\r
473 for (int i = 0; i < n; i++)
\r
475 rect[i] = new Rectangle(10, 10);
\r
476 rect[i].fill = Color.red;
\r
478 Interval rng = new Interval();
\r
479 var slider = new Psychlops.Widgets.Slider("Label", -100 <= rng <= 100);
\r
484 for (int i = 0; i < n; i++)
\r
486 rect[i].centering().shift(slider * i*3, i*3).draw();
\r