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
15 ///+ 0 linkto BasicCode3_1a
\r
16 ////Prepare global parameters
\r
17 const int maxrectnum = 200;
\r
18 int rectnum = 100/*ID:rectnumber 25.0 200.0 25.0*/;
\r
19 double rectsize = 5.0/*ID:dotsize 1.0 10.0 1.0*/;
\r
20 Rectangle[] rect = Rectangle.Array(maxrectnum);
\r
21 double[] rectcolorR = new double[maxrectnum];
\r
22 double[] rectcolorG = new double[maxrectnum];
\r
23 double[] rectcolorB = new double[maxrectnum];
\r
24 ///- 0 linkto BasicCode3_1a
\r
26 Canvas window = new Canvas(Canvas.window);
\r
28 ///+ 1 linkto BasicCode3_1a
\r
30 for(int i=0; i < rectnum; i++){
\r
32 ////set positions and sizes
\r
33 rect[i].set(rectsize, rectsize); //Set a size of rectangles.
\r
34 rect[i].centering();
\r
35 rect[i].shift((i - 0.5 *rectnum) * rectsize* 1.5/*ID:RectHGap 1.0 3.0 0.5*/,
\r
36 (i-0.5*rectnum) * rectsize * 1.5/*ID:RectVGap 1.0 3.0 0.5*/); //Move Rectangles to initial positions
\r
40 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
41 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
42 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
45 ///- 1 linkto BasicCode3_1a
\r
49 ///+ 2.1 linkto BasicCode3_2a
\r
50 ////Prepare variables for movie control;
\r
53 double Horizontal_shift, Vertical_shift;
\r
54 ///- 2.1 linkto BasicCode3_2a
\r
56 while(!Keyboard.esc.pushed()){
\r
57 window.clear(Color.black);
\r
58 for(int i=0; i < rectnum; i++){
\r
60 ////set positions and sizes
\r
62 Horizontal_shift=Math.sin(2 * Math.PI * ((double)frame / 30.0/*ID:Period_HPosition 30 240 30*/))*motion_dir * 100.0/*ID:HSpeed 0.0 100.0 10.0*/; //Calculate horizontal displacement from the center.
\r
63 Vertical_shift=Math.sin(2 * Math.PI * ((double)frame / 30.0/*ID:Period_HPosition 30 240 30*/))*motion_dir * 0.0/*ID:VSpeed 0.0 100.0 10.0*/;//Calculate vertical displacement from the center.
\r
64 rect[i].resize(rectsize, rectsize); //Resize rectangles.
\r
65 rect[i].centering(); //Rectangles are moved to the center...
\r
66 rect[i].shift(Horizontal_shift + (i-0.5*rectnum) * rectsize * 1.5/*ID:RectHGap 1.0 3.0 0.5*/,
\r
67 Vertical_shift + (i-0.5*rectnum) *rectsize * 1.5/*ID:RectVGap 1.0 3.0 0.5*/); //and then move to designated positions
\r
70 ///+ 2.3 linkto BasicCode3_2a
\r
72 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
73 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
74 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
75 ///- 2.3 linkto BasicCode3_2a
\r
78 ///+ 2.4 linkto BasicCode3_1a
\r
79 for(int i=0; i < rectnum; i++){
\r
80 rect[i].draw(new Color(rectcolorR[i], rectcolorG[i], rectcolorB[i])); //draw objects by designated colors.
\r
83 ///- 2.4 linkto BasicCode3_1a
\r
102 namespace PsychlopsSilverlight4test
\r
105 public class PsychlopsMain
\r
107 void RectLuminance()
\r
109 Canvas display = new Canvas(Canvas.window);
\r
110 Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);
\r
111 Letters le = new Letters("Reload to restart");
\r
112 le.fill = Color.black;
\r
113 le.align = Letters.HorizontalAlign.center;
\r
115 while (!Keyboard.esc.pushed())
\r
117 Display.clear(Color.white);
\r
118 le.centering().shift(-200,-10).draw();
\r
125 public void psychlops_main()
\r
148 namespace PsychlopsSilverlight4test
\r
151 public class PsychlopsMain
\r
154 Psychlops.Canvas cnvs;
\r
156 double x, y, z, t, p, temp, xx, yy;
\r
158 //Set Target Initial Value
\r
159 double TargetEcce = 100.0, TargetSize = 5.0, TargetNumber = 5, Rotate = 0.0;
\r
161 //Set Background Initial Value
\r
162 double Axis = 0.0, BGRadii = 150, BGSize = 5.0;
\r
163 Psychlops.Widgets.Slider thetaSpeed, DotNumber;
\r
168 public void psychlops_main()
\r
170 cnvs = new Canvas(500, 500);
\r
172 Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);
\r
175 img = new Image("Resources/logo.png");
\r
177 Interval rng = new Interval();
\r
178 thetaSpeed = new Psychlops.Widgets.Slider("Label", -10 <= rng <= 10, 3.0);
\r
179 DotNumber = new Psychlops.Widgets.Slider("DotNum", 0 <= rng <= 100, 50.0);
\r
181 //Declare background dots and target
\r
182 Rectangle[] BGDot = new Rectangle[2048];
\r
183 for(int i=0; i<2048; i++){
\r
184 BGDot[i]=new Rectangle();
\r
186 Rectangle[] Target= new Rectangle[10];
\r
187 for(int i=0; i<10; i++){
\r
188 Target[i]=new Rectangle();
\r
192 //Declare Matrix to keep back ground dots' coordinate value
\r
193 double[] DotX=new double[2048];
\r
194 double[] DotY = new double[2048];
\r
197 //Set Independent variables to manipulate
\r
200 //Initialize positions of background dots
\r
201 for(int i=0; i<2048; i++){
\r
202 t=2.0*Math.PI*Math.random(1.0);
\r
203 p=2.0*Math.PI*Math.random(1.0);
\r
207 x=BGRadii*Math.cos(t)*Math.cos(p);
\r
208 y=BGRadii*Math.sin(t)*Math.cos(p);
\r
209 BGDot[i].set(BGSize, BGSize);
\r
210 BGDot[i].centering().shift(x,y);
\r
213 //Initialize positions of targets
\r
214 for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize);
\r
218 //Main stimulus loop
\r
220 //Clear the main window
\r
224 temp=Axis/360*2*Math.PI;
\r
225 COS=Math.cos(temp);
\r
226 SIN=Math.sin(temp);
\r
228 //Calculate positions of background dots and set them
\r
229 for(int i=0; i<DotNumber; i++){
\r
230 //Calculate in polar coordinate
\r
231 t=DotX[i]+2.0*Math.PI*thetaSpeed/360.0;
\r
234 //Save current position
\r
237 //Convert to Decartes coordinate
\r
238 x=BGRadii*Math.cos(t)*Math.cos(p);
\r
239 y=BGRadii*Math.sin(t)*Math.cos(p);
\r
240 z=BGRadii*Math.sin(p);
\r
244 //Set Dotsize and Draw them
\r
245 BGDot[i].set(BGSize, BGSize);
\r
246 BGDot[i].centering().shift(xx,yy);
\r
247 BGDot[i].draw( Color.blue );
\r
250 //Calculate positions of targets and set them
\r
251 temp=Rotate*2*Math.PI/360.0;
\r
252 for (int i = 0; i < 5; i++)
\r
254 t = 2.0 * Math.PI/TargetNumber;
\r
255 x = TargetEcce*Math.cos(i*t+temp);
\r
256 y = TargetEcce*Math.sin(i*t+temp);
\r
257 Target[i].centering().shift(x,y);
\r
258 Target[i].fill = Color.yellow;
\r
262 img.centering(Mouse.position).draw();
\r
264 cnvs.var(Mouse.position.x, 100, 100);
\r
265 cnvs.var(Mouse.position.y, 100, 140);
\r
267 //Reflect drawing at the next frame;
\r
279 namespace PsychlopsSilverlight4test
\r
281 public class PsychlopsMain
\r
283 public void psychlops_main()
\r
285 var figure_type = Psychlops.Widgets.Browser.Element.byID("FIGURE");
\r
286 var size_x = Psychlops.Widgets.Browser.Element.byID("SIZE_X");
\r
287 var size_y = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");
\r
288 var shift_x = Psychlops.Widgets.Browser.Element.byID("SHIFT_X");
\r
289 var shift_y = Psychlops.Widgets.Browser.Element.byID("SHIFT_Y");
\r
290 var color_r = Psychlops.Widgets.Browser.Element.byID("COLOR_R");
\r
291 var color_g = Psychlops.Widgets.Browser.Element.byID("COLOR_G");
\r
292 var color_b = Psychlops.Widgets.Browser.Element.byID("COLOR_B");
\r
294 Canvas window = new Canvas(300, 300);
\r
296 var figure_r = new Rectangle();
\r
297 var figure_e = new Ellipse();
\r
298 Shape figure = figure_r;
\r
300 while (!Keyboard.esc.pushed())
\r
302 if (System.String.Compare(figure_type, "Rectangle") == 0)
\r
304 figure_r.set(size_x, size_y);
\r
309 figure_e.set(size_x, size_y);
\r
312 figure.fill = new Color(color_r, color_g, color_b);
\r
314 window.clear(Color.black);
\r
315 figure.centering().shift(shift_x, shift_y).draw();
\r
329 namespace Psychlops
\r
332 public class RandomDots
\r
335 public Point[] cood;
\r
336 public RandomDots()
\r
338 cood = new Point[250];
\r
339 dot = new Rectangle(5, 5);
\r
343 dot.fill = Color.white;
\r
344 foreach (Point p in cood)
\r
346 dot.centering(p).draw();
\r
355 namespace PsychlopsSilverlight4test
\r
358 public class PsychlopsMain
\r
371 public void psychlops_main()
\r
373 cnvs = new Canvas(500, 500);
\r
375 img = new Image(isize * 2, isize * 2);
\r
376 Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);
\r
379 fixation = new Ellipse(10, 10);
\r
380 fixation.fill = Color.red;
\r
381 //var poly = new Rectangle(100, 100);
\r
382 var poly = new Letters("日本語");
\r
383 //var poly = new Polygon(); poly.append(0, 100); poly.append(-100, 0); poly.append(0, -100); poly.append(100, 0);
\r
384 //var poly = new Ellipse(100, 100);
\r
385 //var poly = new Line(0,0,100, 0);
\r
386 poly.fill = Color.red;
\r
387 poly.stroke = new Stroke { color = Color.yellow, thick = 1 };
\r
390 var rng = new Interval();
\r
391 var slider = new Psychlops.Widgets.Slider("tesrt", -100 <= rng <= 100);
\r
393 dots = new RandomDots();
\r
401 cnvs.clear(new Color(Mouse.left.pressed() ? 0.75 : 0.5));
\r
402 col.set(Math.random(1.0));
\r
404 /*if (frames % 2 == 0)
\r
406 fixation.centering().shift(100, 100);
\r
407 fixation.draw(new Stroke(Color.blue, 3));
\r
410 fixation.centering().shift(slider, 0);
\r
411 fixation.draw(Color.red);
\r
413 //Figures.drawGabor(ref img, 20, 100, 1, 0, frames * 2.0 * Math.PI / tfreq / 60);
\r
414 //Figures.drawGaussian(ref img, 20, 1);
\r
415 //Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);
\r
416 //img.centering(Mouse.position);
\r
418 g.centering(Mouse.position).draw();
\r
421 shape.centering(Mouse.position).shift(100, 0);
\r
423 if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100);
\r
425 cnvs.var(frames, 0, 20);
\r
426 //slider.value = frames / 100.0;
\r
428 /*if (frames % 2 != 0)
\r
430 fixation.shift(100, 100);
\r
431 fixation.draw(new Stroke(Color.green, 3));
\r
434 for (int i = 0; i < dots.cood.Length; i++)
\r
436 dots.cood[i].set(Math.random(500), Math.random(500));
\r
438 cnvs.var((double)slider, 200, 200);
\r
453 namespace PsychlopsSilverlight4test
\r
456 public class PsychlopsMain
\r
462 public void psychlops_main()
\r
465 cnvs = new Canvas(500, 500);
\r
466 rect = new Rectangle[n];
\r
467 for (int i = 0; i < n; i++)
\r
469 rect[i] = new Rectangle(10, 10);
\r
470 rect[i].fill = Color.red;
\r
472 Interval rng = new Interval();
\r
473 var slider = new Psychlops.Widgets.Slider("Label", -100 <= rng <= 100);
\r
478 for (int i = 0; i < n; i++)
\r
480 rect[i].centering().shift(slider * i*3, i*3).draw();
\r