1 ///+ Prefix linkto BasicCode1
\r
2 //// Lines for set up Psychlops environment
\r
5 namespace PsychlopsSilverlightApp
\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
28 var img = new Image("logo.png");
\r
31 ///+ 1 linkto BasicCode3_1a
\r
33 for (int i = 0; i < rectnum; i++)
\r
36 ////set positions and sizes
\r
37 rect[i].set(rectsize, rectsize); //Set a size of rectangles.
\r
38 rect[i].centering();
\r
39 rect[i].shift((i - 0.5 * rectnum) * rectsize * 1.5,
\r
40 (i - 0.5 * rectnum) * rectsize * 1.5); //Move Rectangles to initial positions
\r
44 rectcolorR[i] = Math.random(1.0) * 0.5; //Set R values. Note that "i" is converted to double-type.
\r
45 rectcolorG[i] = Math.random(1.0) * 0.5; //Set G values. Note that "i" is converted to double-type.
\r
46 rectcolorB[i] = Math.random(1.0) * 0.5; //Set B values. Note that "i" is converted to double-type.
\r
49 ///- 1 linkto BasicCode3_1a
\r
53 ///+ 2.1 linkto BasicCode3_2a
\r
54 ////Prepare variables for movie control;
\r
57 double Horizontal_shift, Vertical_shift;
\r
58 ///- 2.1 linkto BasicCode3_2a
\r
60 while (!Keyboard.esc.pushed())
\r
62 window.clear(Color.black);
\r
63 for (int i = 0; i < rectnum; i++)
\r
66 ////set positions and sizes
\r
68 Horizontal_shift = Math.sin(2 * Math.PI * ((double)frame / 30.0)) * motion_dir * 100.0; //Calculate horizontal displacement from the center.
\r
69 Vertical_shift = Math.sin(2 * Math.PI * ((double)frame / 30.0)) * motion_dir * 0.0;//Calculate vertical displacement from the center.
\r
70 rect[i].resize(rectsize, rectsize); //Resize rectangles.
\r
71 rect[i].centering(); //Rectangles are moved to the center...
\r
72 rect[i].shift(Horizontal_shift + (i - 0.5 * rectnum) * rectsize * 1.5,
\r
73 Vertical_shift + (i - 0.5 * rectnum) * rectsize * 1.5); //and then move to designated positions
\r
76 ///+ 2.3 linkto BasicCode3_2a
\r
78 rectcolorR[i] = Math.random(1.0) * 0.5; //Set R values. Note that "i" is converted to double-type.
\r
79 rectcolorG[i] = Math.random(1.0) * 0.5; //Set G values. Note that "i" is converted to double-type.
\r
80 rectcolorB[i] = Math.random(1.0) * 0.5; //Set B values. Note that "i" is converted to double-type.
\r
81 ///- 2.3 linkto BasicCode3_2a
\r
84 ///+ 2.4 linkto BasicCode3_1a
\r
85 for (int i = 0; i < rectnum; i++)
\r
87 rect[i].draw(new Color(rectcolorR[i], rectcolorG[i], rectcolorB[i])); //draw objects by designated colors.
\r
90 ///- 2.4 linkto BasicCode3_1a
\r
110 namespace PsychlopsSilverlight4test
\r
113 public class PsychlopsMain
\r
115 void RectLuminance()
\r
117 Canvas display = new Canvas(Canvas.window);
\r
118 Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);
\r
119 Letters le = new Letters("Reload to restart");
\r
120 le.fill = Color.black;
\r
121 le.align = Letters.HorizontalAlign.center;
\r
123 while (!Keyboard.esc.pushed())
\r
125 Display.clear(Color.white);
\r
126 le.centering().shift(-200,-10).draw();
\r
133 public void psychlops_main()
\r
156 namespace PsychlopsSilverlight4test
\r
159 public class PsychlopsMain
\r
162 Psychlops.Canvas cnvs;
\r
164 double x, y, z, t, p, temp, xx, yy;
\r
166 //Set Target Initial Value
\r
167 double TargetEcce = 100.0, TargetSize = 5.0, TargetNumber = 5, Rotate = 0.0;
\r
169 //Set Background Initial Value
\r
170 double Axis = 0.0, BGRadii = 150, BGSize = 5.0;
\r
171 Psychlops.Widgets.Slider thetaSpeed, DotNumber;
\r
176 public void psychlops_main()
\r
178 cnvs = new Canvas(500, 500);
\r
180 Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);
\r
183 img = new Image("Resources/logo.png");
\r
185 Interval rng = new Interval();
\r
186 thetaSpeed = new Psychlops.Widgets.Slider("Label", -10 <= rng <= 10, 3.0);
\r
187 DotNumber = new Psychlops.Widgets.Slider("DotNum", 0 <= rng <= 100, 50.0);
\r
189 //Declare background dots and target
\r
190 Rectangle[] BGDot = new Rectangle[2048];
\r
191 for(int i=0; i<2048; i++){
\r
192 BGDot[i]=new Rectangle();
\r
194 Rectangle[] Target= new Rectangle[10];
\r
195 for(int i=0; i<10; i++){
\r
196 Target[i]=new Rectangle();
\r
200 //Declare Matrix to keep back ground dots' coordinate value
\r
201 double[] DotX=new double[2048];
\r
202 double[] DotY = new double[2048];
\r
205 //Set Independent variables to manipulate
\r
208 //Initialize positions of background dots
\r
209 for(int i=0; i<2048; i++){
\r
210 t=2.0*Math.PI*Math.random(1.0);
\r
211 p=2.0*Math.PI*Math.random(1.0);
\r
215 x=BGRadii*Math.cos(t)*Math.cos(p);
\r
216 y=BGRadii*Math.sin(t)*Math.cos(p);
\r
217 BGDot[i].set(BGSize, BGSize);
\r
218 BGDot[i].centering().shift(x,y);
\r
221 //Initialize positions of targets
\r
222 for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize);
\r
226 //Main stimulus loop
\r
228 //Clear the main window
\r
232 temp=Axis/360*2*Math.PI;
\r
233 COS=Math.cos(temp);
\r
234 SIN=Math.sin(temp);
\r
236 //Calculate positions of background dots and set them
\r
237 for(int i=0; i<DotNumber; i++){
\r
238 //Calculate in polar coordinate
\r
239 t=DotX[i]+2.0*Math.PI*thetaSpeed/360.0;
\r
242 //Save current position
\r
245 //Convert to Decartes coordinate
\r
246 x=BGRadii*Math.cos(t)*Math.cos(p);
\r
247 y=BGRadii*Math.sin(t)*Math.cos(p);
\r
248 z=BGRadii*Math.sin(p);
\r
252 //Set Dotsize and Draw them
\r
253 BGDot[i].set(BGSize, BGSize);
\r
254 BGDot[i].centering().shift(xx,yy);
\r
255 BGDot[i].draw( Color.blue );
\r
258 //Calculate positions of targets and set them
\r
259 temp=Rotate*2*Math.PI/360.0;
\r
260 for (int i = 0; i < 5; i++)
\r
262 t = 2.0 * Math.PI/TargetNumber;
\r
263 x = TargetEcce*Math.cos(i*t+temp);
\r
264 y = TargetEcce*Math.sin(i*t+temp);
\r
265 Target[i].centering().shift(x,y);
\r
266 Target[i].fill = Color.yellow;
\r
270 img.centering(Mouse.position).draw();
\r
272 cnvs.var(Mouse.position.x, 100, 100);
\r
273 cnvs.var(Mouse.position.y, 100, 140);
\r
275 //Reflect drawing at the next frame;
\r
287 namespace PsychlopsSilverlight4test
\r
289 public class PsychlopsMain
\r
291 public void psychlops_main()
\r
293 var figure_type = Psychlops.Widgets.Browser.Element.byID("FIGURE");
\r
294 var size_x = Psychlops.Widgets.Browser.Element.byID("SIZE_X");
\r
295 var size_y = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");
\r
296 var shift_x = Psychlops.Widgets.Browser.Element.byID("SHIFT_X");
\r
297 var shift_y = Psychlops.Widgets.Browser.Element.byID("SHIFT_Y");
\r
298 var color_r = Psychlops.Widgets.Browser.Element.byID("COLOR_R");
\r
299 var color_g = Psychlops.Widgets.Browser.Element.byID("COLOR_G");
\r
300 var color_b = Psychlops.Widgets.Browser.Element.byID("COLOR_B");
\r
302 Canvas window = new Canvas(300, 300);
\r
304 var figure_r = new Rectangle();
\r
305 var figure_e = new Ellipse();
\r
306 Shape figure = figure_r;
\r
308 while (!Keyboard.esc.pushed())
\r
310 if (System.String.Compare(figure_type, "Rectangle") == 0)
\r
312 figure_r.set(size_x, size_y);
\r
317 figure_e.set(size_x, size_y);
\r
320 figure.fill = new Color(color_r, color_g, color_b);
\r
322 window.clear(Color.black);
\r
323 figure.centering().shift(shift_x, shift_y).draw();
\r
337 namespace Psychlops
\r
340 public class RandomDots
\r
343 public Point[] cood;
\r
344 public RandomDots()
\r
346 cood = new Point[250];
\r
347 dot = new Rectangle(5, 5);
\r
351 dot.fill = Color.white;
\r
352 foreach (Point p in cood)
\r
354 dot.centering(p).draw();
\r
363 namespace PsychlopsSilverlight4test
\r
366 public class PsychlopsMain
\r
379 public void psychlops_main()
\r
381 cnvs = new Canvas(500, 500);
\r
383 img = new Image(isize * 2, isize * 2);
\r
384 Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);
\r
387 fixation = new Ellipse(10, 10);
\r
388 fixation.fill = Color.red;
\r
389 //var poly = new Rectangle(100, 100);
\r
390 var poly = new Letters("日本語");
\r
391 //var poly = new Polygon(); poly.append(0, 100); poly.append(-100, 0); poly.append(0, -100); poly.append(100, 0);
\r
392 //var poly = new Ellipse(100, 100);
\r
393 //var poly = new Line(0,0,100, 0);
\r
394 poly.fill = Color.red;
\r
395 poly.stroke = new Stroke { color = Color.yellow, thick = 1 };
\r
398 var rng = new Interval();
\r
399 var slider = new Psychlops.Widgets.Slider("tesrt", -100 <= rng <= 100);
\r
401 dots = new RandomDots();
\r
409 cnvs.clear(new Color(Mouse.left.pressed() ? 0.75 : 0.5));
\r
410 col.set(Math.random(1.0));
\r
412 /*if (frames % 2 == 0)
\r
414 fixation.centering().shift(100, 100);
\r
415 fixation.draw(new Stroke(Color.blue, 3));
\r
418 fixation.centering().shift(slider, 0);
\r
419 fixation.draw(Color.red);
\r
421 //Figures.drawGabor(ref img, 20, 100, 1, 0, frames * 2.0 * Math.PI / tfreq / 60);
\r
422 //Figures.drawGaussian(ref img, 20, 1);
\r
423 //Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);
\r
424 //img.centering(Mouse.position);
\r
426 g.centering(Mouse.position).draw();
\r
429 shape.centering(Mouse.position).shift(100, 0);
\r
431 if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100);
\r
433 cnvs.var(frames, 0, 20);
\r
434 //slider.value = frames / 100.0;
\r
436 /*if (frames % 2 != 0)
\r
438 fixation.shift(100, 100);
\r
439 fixation.draw(new Stroke(Color.green, 3));
\r
442 for (int i = 0; i < dots.cood.Length; i++)
\r
444 dots.cood[i].set(Math.random(500), Math.random(500));
\r
446 cnvs.var((double)slider, 200, 200);
\r
461 namespace PsychlopsSilverlight4test
\r
464 public class PsychlopsMain
\r
470 public void psychlops_main()
\r
473 cnvs = new Canvas(500, 500);
\r
474 rect = new Rectangle[n];
\r
475 for (int i = 0; i < n; i++)
\r
477 rect[i] = new Rectangle(10, 10);
\r
478 rect[i].fill = Color.red;
\r
480 Interval rng = new Interval();
\r
481 var slider = new Psychlops.Widgets.Slider("Label", -100 <= rng <= 100);
\r
486 for (int i = 0; i < n; i++)
\r
488 rect[i].centering().shift(slider * i*3, i*3).draw();
\r