1 ///+ Prefix linkto BasicCode1
\r
2 //// Lines for set up Psychlops environment
\r
6 namespace PsychlopsSilverlight4test
\r
9 public class PsychlopsMain
\r
10 {///- Prefix linkto BasicCode1
\r
14 //// Psychlops runs at the first line of this function psychlops_main().
\r
15 public void psychlops_main() {
\r
16 ///+ 0 linkto BasicCode3_1a
\r
17 ////Prepare global parameters
\r
18 const int maxrectnum = 200;
\r
19 int rectnum = 100/*ID:rectnumber 25.0 200.0 25.0*/;
\r
20 double rectsize = 5.0/*ID:dotsize 1.0 10.0 1.0*/;
\r
21 Rectangle[] rect = new Rectangle[maxrectnum];
\r
22 for (int i = 0; i < maxrectnum; i++) { rect[i] = new Rectangle(); }
\r
23 double[] rectcolorR = new double[maxrectnum];
\r
24 double[] rectcolorG = new double[maxrectnum];
\r
25 double[] rectcolorB = new double[maxrectnum];
\r
26 ///- 0 linkto BasicCode3_1a
\r
28 Canvas window = new Canvas(Canvas.window);
\r
30 ///+ 1 linkto BasicCode3_1a
\r
32 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/*ID:RectHGap 1.0 3.0 0.5*/,
\r
38 (i - 0.5*rectnum) * rectsize * 1.5/*ID:RectVGap 1.0 3.0 0.5*/); //Move Rectangles to initial positions
\r
42 rectcolorR[i]=Math.random(1.0) * 0.5/*ID: RGain 0.0 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/*ID: GGain 0.0 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/*ID: BGain 0.0 1.0 0.5*/; //Set B values. Note that "i" is converted to double-type.
\r
47 ///- 1 linkto BasicCode3_1a
\r
52 ////Prepare variables for movie control;
\r
55 double Horizontal_shift, Vertical_shift;
\r
58 while(!Keyboard.esc.pushed()){
\r
59 window.clear(Color.black);
\r
61 if(frame % 30/*ID:Period_Position 30 240 30*/ ==0){ // motion direction will reverse at designated frames.
\r
65 for(int i=0; i < rectnum; i++){
\r
67 ////set positions and sizes
\r
69 Horizontal_shift=motion_dir * 1.0/*ID:HSpeed 0.0 5.0 1.0*/;
\r
70 Vertical_shift=motion_dir * 0.0/*ID:VSpeed 0.0 5.0 1.0*/;
\r
72 rect[i].resize(rectsize, rectsize); //Resize rectangles.
\r
73 rect[i].shift(Horizontal_shift, Vertical_shift);
\r
78 rectcolorR[i]=Math.random(1.0)* 0.5/*ID:RGain 0.0 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/*ID:GGain 0.0 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/*ID:BGain 0.0 1.0 0.5*/; //Set B values. Note that "i" is converted to double-type.
\r
85 ///+ 2.4 linkto BasicCode3_1a
\r
86 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
107 >>>>>>> 06a470a0e79a283223a73d8c5f6e43ef76174d97
110 namespace PsychlopsSilverlightApp
\r
113 public class PsychlopsMain
\r
114 {///- Prefix linkto BasicCode1
\r
118 //// Psychlops runs at the first line of this function psychlops_main().
\r
119 public void psychlops_main()
\r
121 ///+ 0 linkto BasicCode3_1a
\r
122 ////Prepare global parameters
\r
123 int maxrectnum = 200;
\r
125 double rectsize = 5.0;
\r
126 Rectangle[] rect = StaticFunctions.NewArray<Rectangle>(maxrectnum);
\r
127 double[] rectcolorR = new double[maxrectnum];
\r
128 double[] rectcolorG = new double[maxrectnum];
\r
129 double[] rectcolorB = new double[maxrectnum];
\r
130 ///- 0 linkto BasicCode3_1a
\r
132 Canvas window = new Canvas(Canvas.window);
\r
133 var img = new Image("logo.png");
\r
136 ///+ 1 linkto BasicCode3_1a
\r
138 for (int i = 0; i < rectnum; i++)
\r
141 ////set positions and sizes
\r
142 rect[i].set(rectsize, rectsize); //Set a size of rectangles.
\r
143 rect[i].centering();
\r
144 rect[i].shift((i - 0.5 * rectnum) * rectsize * 1.5,
\r
145 (i - 0.5 * rectnum) * rectsize * 1.5); //Move Rectangles to initial positions
\r
149 rectcolorR[i] = Math.random(1.0) * 0.5; //Set R values. Note that "i" is converted to double-type.
\r
150 rectcolorG[i] = Math.random(1.0) * 0.5; //Set G values. Note that "i" is converted to double-type.
\r
151 rectcolorB[i] = Math.random(1.0) * 0.5; //Set B values. Note that "i" is converted to double-type.
\r
154 ///- 1 linkto BasicCode3_1a
\r
157 ////drawing objects
\r
158 ///+ 2.1 linkto BasicCode3_2a
\r
159 ////Prepare variables for movie control;
\r
161 int motion_dir = 1;
\r
162 double Horizontal_shift, Vertical_shift;
\r
163 ///- 2.1 linkto BasicCode3_2a
\r
165 while (!Keyboard.esc.pushed())
\r
167 window.clear(Color.black);
\r
168 for (int i = 0; i < rectnum; i++)
\r
171 ////set positions and sizes
\r
173 Horizontal_shift = Math.sin(2 * Math.PI * ((double)frame / 30.0)) * motion_dir * 100.0; //Calculate horizontal displacement from the center.
\r
174 Vertical_shift = Math.sin(2 * Math.PI * ((double)frame / 30.0)) * motion_dir * 0.0;//Calculate vertical displacement from the center.
\r
175 rect[i].resize(rectsize, rectsize); //Resize rectangles.
\r
176 rect[i].centering(); //Rectangles are moved to the center...
\r
177 rect[i].shift(Horizontal_shift + (i - 0.5 * rectnum) * rectsize * 1.5,
\r
178 Vertical_shift + (i - 0.5 * rectnum) * rectsize * 1.5); //and then move to designated positions
\r
181 ///+ 2.3 linkto BasicCode3_2a
\r
183 rectcolorR[i] = Math.random(1.0) * 0.5; //Set R values. Note that "i" is converted to double-type.
\r
184 rectcolorG[i] = Math.random(1.0) * 0.5; //Set G values. Note that "i" is converted to double-type.
\r
185 rectcolorB[i] = Math.random(1.0) * 0.5; //Set B values. Note that "i" is converted to double-type.
\r
186 ///- 2.3 linkto BasicCode3_2a
\r
189 ///+ 2.4 linkto BasicCode3_1a
\r
190 for (int i = 0; i < rectnum; i++)
\r
192 rect[i].draw(new Color(rectcolorR[i], rectcolorG[i], rectcolorB[i])); //draw objects by designated colors.
\r
195 ///- 2.4 linkto BasicCode3_1a
\r
215 namespace PsychlopsSilverlight4test
\r
218 public class PsychlopsMain
\r
220 void RectLuminance()
\r
222 Canvas display = new Canvas(Canvas.window);
\r
223 Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);
\r
224 Letters le = new Letters("Reload to restart");
\r
225 le.fill = Color.black;
\r
226 le.align = Letters.HorizontalAlign.center;
\r
228 while (!Keyboard.esc.pushed())
\r
230 Display.clear(Color.white);
\r
231 le.centering().shift(-200,-10).draw();
\r
238 public void psychlops_main()
\r
262 namespace PsychlopsSilverlight4test
\r
265 public class PsychlopsMain
\r
268 Psychlops.Canvas cnvs;
\r
270 double x, y, z, t, p, temp, xx, yy;
\r
272 //Set Target Initial Value
\r
273 double TargetEcce = 100.0, TargetSize = 5.0, TargetNumber = 5, Rotate = 0.0;
\r
275 //Set Background Initial Value
\r
276 double Axis = 0.0, BGRadii = 150, BGSize = 5.0;
\r
277 Psychlops.Widgets.Slider thetaSpeed, DotNumber;
\r
282 public void psychlops_main()
\r
284 cnvs = new Canvas(500, 500);
\r
286 Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);
\r
289 img = new Image("Resources/logo.png");
\r
291 Interval rng = new Interval();
\r
292 thetaSpeed = new Psychlops.Widgets.Slider("Label", -10 <= rng <= 10, 3.0);
\r
293 DotNumber = new Psychlops.Widgets.Slider("DotNum", 0 <= rng <= 100, 50.0);
\r
295 //Declare background dots and target
\r
296 Rectangle[] BGDot = new Rectangle[2048];
\r
297 for(int i=0; i<2048; i++){
\r
298 BGDot[i]=new Rectangle();
\r
300 Rectangle[] Target= new Rectangle[10];
\r
301 for(int i=0; i<10; i++){
\r
302 Target[i]=new Rectangle();
\r
306 //Declare Matrix to keep back ground dots' coordinate value
\r
307 double[] DotX=new double[2048];
\r
308 double[] DotY = new double[2048];
\r
311 //Set Independent variables to manipulate
\r
314 //Initialize positions of background dots
\r
315 for(int i=0; i<2048; i++){
\r
316 t=2.0*Math.PI*Math.random(1.0);
\r
317 p=2.0*Math.PI*Math.random(1.0);
\r
321 x=BGRadii*Math.cos(t)*Math.cos(p);
\r
322 y=BGRadii*Math.sin(t)*Math.cos(p);
\r
323 BGDot[i].set(BGSize, BGSize);
\r
324 BGDot[i].centering().shift(x,y);
\r
327 //Initialize positions of targets
\r
328 for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize);
\r
332 //Main stimulus loop
\r
334 //Clear the main window
\r
338 temp=Axis/360*2*Math.PI;
\r
339 COS=Math.cos(temp);
\r
340 SIN=Math.sin(temp);
\r
342 //Calculate positions of background dots and set them
\r
343 for(int i=0; i<DotNumber; i++){
\r
344 //Calculate in polar coordinate
\r
345 t=DotX[i]+2.0*Math.PI*thetaSpeed/360.0;
\r
348 //Save current position
\r
351 //Convert to Decartes coordinate
\r
352 x=BGRadii*Math.cos(t)*Math.cos(p);
\r
353 y=BGRadii*Math.sin(t)*Math.cos(p);
\r
354 z=BGRadii*Math.sin(p);
\r
358 //Set Dotsize and Draw them
\r
359 BGDot[i].set(BGSize, BGSize);
\r
360 BGDot[i].centering().shift(xx,yy);
\r
361 BGDot[i].draw( Color.blue );
\r
364 //Calculate positions of targets and set them
\r
365 temp=Rotate*2*Math.PI/360.0;
\r
366 for (int i = 0; i < 5; i++)
\r
368 t = 2.0 * Math.PI/TargetNumber;
\r
369 x = TargetEcce*Math.cos(i*t+temp);
\r
370 y = TargetEcce*Math.sin(i*t+temp);
\r
371 Target[i].centering().shift(x,y);
\r
372 Target[i].fill = Color.yellow;
\r
376 img.centering(Mouse.position).draw();
\r
378 cnvs.var(Mouse.position.x, 100, 100);
\r
379 cnvs.var(Mouse.position.y, 100, 140);
\r
381 //Reflect drawing at the next frame;
\r
393 namespace PsychlopsSilverlight4test
\r
395 public class PsychlopsMain
\r
397 public void psychlops_main()
\r
399 var figure_type = Psychlops.Widgets.Browser.Element.byID("FIGURE");
\r
400 var size_x = Psychlops.Widgets.Browser.Element.byID("SIZE_X");
\r
401 var size_y = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");
\r
402 var shift_x = Psychlops.Widgets.Browser.Element.byID("SHIFT_X");
\r
403 var shift_y = Psychlops.Widgets.Browser.Element.byID("SHIFT_Y");
\r
404 var color_r = Psychlops.Widgets.Browser.Element.byID("COLOR_R");
\r
405 var color_g = Psychlops.Widgets.Browser.Element.byID("COLOR_G");
\r
406 var color_b = Psychlops.Widgets.Browser.Element.byID("COLOR_B");
\r
408 Canvas window = new Canvas(300, 300);
\r
410 var figure_r = new Rectangle();
\r
411 var figure_e = new Ellipse();
\r
412 Shape figure = figure_r;
\r
414 while (!Keyboard.esc.pushed())
\r
416 if (System.String.Compare(figure_type, "Rectangle") == 0)
\r
418 figure_r.set(size_x, size_y);
\r
423 figure_e.set(size_x, size_y);
\r
426 figure.fill = new Color(color_r, color_g, color_b);
\r
428 window.clear(Color.black);
\r
429 figure.centering().shift(shift_x, shift_y).draw();
\r
443 namespace Psychlops
\r
446 public class RandomDots
\r
449 public Point[] cood;
\r
450 public RandomDots()
\r
452 cood = new Point[250];
\r
453 dot = new Rectangle(5, 5);
\r
457 dot.fill = Color.white;
\r
458 foreach (Point p in cood)
\r
460 dot.centering(p).draw();
\r
469 namespace PsychlopsSilverlight4test
\r
472 public class PsychlopsMain
\r
485 public void psychlops_main()
\r
487 cnvs = new Canvas(500, 500);
\r
489 img = new Image(isize * 2, isize * 2);
\r
490 Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);
\r
493 fixation = new Ellipse(10, 10);
\r
494 fixation.fill = Color.red;
\r
495 //var poly = new Rectangle(100, 100);
\r
496 var poly = new Letters("日本語");
\r
497 //var poly = new Polygon(); poly.append(0, 100); poly.append(-100, 0); poly.append(0, -100); poly.append(100, 0);
\r
498 //var poly = new Ellipse(100, 100);
\r
499 //var poly = new Line(0,0,100, 0);
\r
500 poly.fill = Color.red;
\r
501 poly.stroke = new Stroke { color = Color.yellow, thick = 1 };
\r
504 var rng = new Interval();
\r
505 var slider = new Psychlops.Widgets.Slider("tesrt", -100 <= rng <= 100);
\r
507 dots = new RandomDots();
\r
515 cnvs.clear(new Color(Mouse.left.pressed() ? 0.75 : 0.5));
\r
516 col.set(Math.random(1.0));
\r
518 /*if (frames % 2 == 0)
\r
520 fixation.centering().shift(100, 100);
\r
521 fixation.draw(new Stroke(Color.blue, 3));
\r
524 fixation.centering().shift(slider, 0);
\r
525 fixation.draw(Color.red);
\r
527 //Figures.drawGabor(ref img, 20, 100, 1, 0, frames * 2.0 * Math.PI / tfreq / 60);
\r
528 //Figures.drawGaussian(ref img, 20, 1);
\r
529 //Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);
\r
530 //img.centering(Mouse.position);
\r
532 g.centering(Mouse.position).draw();
\r
535 shape.centering(Mouse.position).shift(100, 0);
\r
537 if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100);
\r
539 cnvs.var(frames, 0, 20);
\r
540 //slider.value = frames / 100.0;
\r
542 /*if (frames % 2 != 0)
\r
544 fixation.shift(100, 100);
\r
545 fixation.draw(new Stroke(Color.green, 3));
\r
548 for (int i = 0; i < dots.cood.Length; i++)
\r
550 dots.cood[i].set(Math.random(500), Math.random(500));
\r
552 cnvs.var((double)slider, 200, 200);
\r
567 namespace PsychlopsSilverlight4test
\r
570 public class PsychlopsMain
\r
576 public void psychlops_main()
\r
579 cnvs = new Canvas(500, 500);
\r
580 rect = new Rectangle[n];
\r
581 for (int i = 0; i < n; i++)
\r
583 rect[i] = new Rectangle(10, 10);
\r
584 rect[i].fill = Color.red;
\r
586 Interval rng = new Interval();
\r
587 var slider = new Psychlops.Widgets.Slider("Label", -100 <= rng <= 100);
\r
592 for (int i = 0; i < n; i++)
\r
594 rect[i].centering().shift(slider * i*3, i*3).draw();
\r