2 ///+ Prefix linkto BasicCode1
\r
3 //// Lines for set up Psychlops environment
\r
6 namespace PsychlopsSilverlightApp
\r
9 public class PsychlopsMain
\r
11 ///- Prefix linkto BasicCode1
\r
15 //// Psychlops runs at the first line of this function psychlops_main().
\r
16 public void psychlops_main()
\r
20 ////Prepare global parameters
\r
21 Rectangle p1 = new Rectangle(1,1);
\r
22 Color col1 = new Color();
\r
26 double lmean=0.25, contrast = 0.5;
\r
30 Canvas disp = new Canvas(Canvas.window, Display.secondary);
\r
32 var fieldW_ = Psychlops.Widgets.Browser.Element.byID("fieldW");
\r
33 var fieldH_ = Psychlops.Widgets.Browser.Element.byID("fieldH");
\r
34 var wL_ = Psychlops.Widgets.Browser.Element.byID("wL");
\r
35 var Cont_ = Psychlops.Widgets.Browser.Element.byID("Cont");
\r
36 var ix_ = Psychlops.Widgets.Browser.Element.byID("ix");
\r
37 var iy_ = Psychlops.Widgets.Browser.Element.byID("iy");
\r
38 var gap_ = Psychlops.Widgets.Browser.Element.byID("gap");
\r
43 p1.centering().shift(-width*0.5 + x0, -height*0.5 + y0); //Move a point to the initial position.
\r
48 for(int i=0; i < width; i++)
\r
50 col1.set(lmean*((contrast*Math.sin((2*Math.PI*i/lambda)))+1)); //Set a color.
\r
52 ///+ 2.1 Drawing a column
\r
53 ////drawing a column
\r
54 for(int j=0;j < height; j++)
\r
59 ///- 2.1 Drawing a column
\r
61 p1.shift(1, -height * pitch); //back to vertical intitial point after drawing one column.
\r
66 while (!Keyboard.spc.pushed()) { }; //Wait until space key is pressed.
\r
77 //// Lines for set up Psychlops environment
\r
80 namespace PsychlopsSilverlightApp
\r
83 public class PsychlopsMain
\r
89 //// Psychlops runs at the first line of this function psychlops_main().
\r
90 public void psychlops_main()
\r
92 Canvas window = new Canvas(300, 300); //Create a window. Here, window variables are preset mode.
\r
94 var FIGURE = Psychlops.Widgets.Browser.Element.byID("FIGURE");
\r
95 var SIZE_X_ = Psychlops.Widgets.Browser.Element.byID("SIZE_X");
\r
96 var SIZE_Y_ = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");
\r
97 var COLOR_R = Psychlops.Widgets.Browser.Element.byID("COLOR_R");
\r
98 var COLOR_G = Psychlops.Widgets.Browser.Element.byID("COLOR_G");
\r
99 var COLOR_B = Psychlops.Widgets.Browser.Element.byID("COLOR_B");
\r
100 var COLOR_BG = Psychlops.Widgets.Browser.Element.byID("COLOR_BG");
\r
101 var Period_Size = Psychlops.Widgets.Browser.Element.byID("Period_Size");
\r
102 var Period_Position = Psychlops.Widgets.Browser.Element.byID("Period_Position");
\r
103 var Speed_HSize_ = Psychlops.Widgets.Browser.Element.byID("Speed_HSize");
\r
104 var Speed_VSize = Psychlops.Widgets.Browser.Element.byID("Speed_VSize");
\r
105 var Speed_VMotion = Psychlops.Widgets.Browser.Element.byID("Speed_VMotion");
\r
106 double SIZE_X = SIZE_X_, SIZE_Y = SIZE_Y_;
\r
109 //// Set a figure size, position and color.
\r
110 Rectangle figure = new Rectangle();
\r
111 Ellipse figure2 = new Ellipse();
\r
112 figure.set(SIZE_X_, SIZE_Y_); // Set the size of figure.
\r
113 figure2.set(SIZE_X_, SIZE_Y_); // Set the size of figure.
\r
114 figure.centering().shift(0, 0); // Move the figure to the starting point.
\r
115 figure2.centering().shift(0, 0); // Move the figure to the starting point.
\r
119 int looming_direction = 1, motion_dir = 1;
\r
120 double direction = 1.0;
\r
121 //looming_direction is a variable for size change.
\r
122 //motion_dir is a variable for motion direction.
\r
123 ///+ 3 Drawing loop
\r
124 //// Draw each frames in a "while loop".
\r
125 while (!Keyboard.esc.pushed())
\r
126 { //exit a program when the escape key is pressed down.
\r
127 window.clear(COLOR_BG); // Clear the window with a designated gray-scale level.
\r
130 //// Calculate object's position and size for each frame.
\r
132 if (frame % Period_Size == 0)
\r
133 { // a direction of size change will reverse at designated frames.
\r
134 looming_direction = looming_direction * -1;
\r
137 if (frame % Period_Position == 0)
\r
138 { // motion direction will reverse at designated frames.
\r
145 //// Settting figure's properties
\r
146 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
147 figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".
\r
148 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
149 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
150 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".
\r
151 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
153 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
154 figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".
\r
155 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
156 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
157 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".
\r
158 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
164 if ("Rectangle".Equals(FIGURE))
\r
166 figure.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.
\r
170 figure2.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.
\r
172 window.flip(); // Reflect the drawing for the display by flipping frame buffers.
\r
176 ////make a step for next frames
\r
180 ///- 3 Drawing loop
\r
193 //The reversed-phi motion.
\r
195 //Phi movement as a subtraction process. Vision Res 10:1411?1430
\r
198 //// Include Psychlops Package
\r
201 namespace PsychlopsSilverlightApp
\r
204 public class PsychlopsMain
\r
209 ///+ Stimulus drawing function
\r
210 //// A function for stimulus drawing (main body)
\r
211 void RectLuminance()
\r
215 //// Declare and initialize local variables
\r
216 double rect_size = 20;
\r
218 double bg_lum = 0.5;
\r
219 double radii = 200;
\r
221 int element_number = 25;
\r
222 int radial_row = 5;
\r
224 double rotation_tf = 0.2;
\r
225 double polarity = 1;
\r
228 double contrastflag = 1;
\r
232 Canvas display = new Canvas(Canvas.window); //Prepare drawing window
\r
233 refresh = Display.getRefreshRate();
\r
235 Ellipse rect = new Ellipse();
\r
236 rect.set(rect_size, rect_size);
\r
238 Ellipse fixation = new Ellipse(5, 5);
\r
239 fixation.centering();
\r
241 Letters let1 = new Letters("Press Space key to change stimulus type");
\r
242 let1.centering().shift(-180, 220);
\r
243 Letters let2 = new Letters("Phi");
\r
244 let2.centering().shift(-10, 200);
\r
245 Letters let3 = new Letters("Reversed-Phi");
\r
246 let3.centering().shift(-60, 200);
\r
248 rotation = Math.random(2 * Math.PI);
\r
250 ///+ user interface
\r
251 ////register variables to demo circumstances
\r
252 Interval rng = new Interval();
\r
254 Psychlops.Widgets.Slider rect_contrast;
\r
255 rect_contrast = new Psychlops.Widgets.Slider("Contrast", 0.1 <= rng <= 1.0, 0.1);
\r
256 rect_contrast.value = 0.5;
\r
257 ///- user interface
\r
263 //AppState::setThreadPriority(AppState::HIGH);
\r
267 if (Keyboard.spc.pushed()) contrastflag = -contrastflag;
\r
268 if (contrastflag < 0) polarity = -polarity;
\r
269 rotation = 2 * Math.PI * rotation_tf * frame * period / refresh;
\r
271 for (int frame_now = 0; frame_now < period; frame_now++)
\r
273 Display.clear(new Color(bg_lum));
\r
274 for (int j = 0; j < radial_row; j++)
\r
276 rect.resize(rect_size * (j + radial_row) / 10.0, rect_size * (j + radial_row) / 10.0);
\r
277 for (double i = 0; i < element_number; i++)
\r
279 rect_lum = bg_lum * (1.0 + polarity * rect_contrast);
\r
280 rect.centering().shift(radii * (j + radial_row) / 10.0 * Math.cos(rotation + i * 2 * Math.PI / element_number), radii * (j + radial_row) / 10.0 * Math.sin(rotation + i * 2 * Math.PI / element_number));
\r
281 rect.draw(rect_lum);
\r
284 fixation.draw(Color.red);
\r
286 if (contrastflag > 0) let2.draw();
\r
292 //AppState::setThreadPriority(AppState::NORMAL);
\r
294 ///- Stimulus drawing function
\r
296 ///+ Main function for demo circumstances
\r
297 //// Psychlops Main function
\r
298 public void psychlops_main()
\r
300 ///+ Demo circumstances
\r
301 //// Spells for run demonstration circumstances
\r
302 Procedure p = new Procedure();
\r
303 //p.setDesign(Procedure::DEMO); //Designate that this is a demo.
\r
304 p.setProcedure(RectLuminance); //The argument name is a name of drawing function.
\r
306 ///- Demo circumstances
\r
308 ///- Main function for demo circumstances
\r
317 //Two types of plaid motion
\r
318 //E. H. Adelson and J. A. Movshon (1982).
\r
319 //Phenomenal coherence of moving visual patterns. Nature 300, 523-525
\r
322 //// Include Psychlops Package
\r
325 namespace PsychlopsSilverlightApp
\r
328 public class PsychlopsMain
\r
333 // Struct for component paremeters
\r
336 public double contrast;
\r
337 public double orientation;
\r
338 public double lambda;
\r
343 ///+ Stimulus drawing function
\r
344 //// A function for stimulus drawing (main body)
\r
345 void drawgratingmovie(Image[] img, component c1, component c2, double contrast, int start, int maxframe, double bg_lum, double alpha)
\r
347 double _xp, _xp2, col1, col2;
\r
348 double contrast1, contrast2;
\r
349 double imageheight, imagewidth;
\r
351 contrast1 = contrast*c1.contrast/(c1.contrast+c2.contrast);
\r
352 contrast2 = contrast*c2.contrast/(c1.contrast+c2.contrast);
\r
354 imageheight = img[0].getHeight();
\r
355 imagewidth = img[0].getWidth();
\r
357 for(int frame=start; frame<start+maxframe+1; frame++){
\r
358 //Display.progressbar(frame, maxframe+1);
\r
359 //img[frame].convert(Image::RGBA);
\r
360 for(int i=0; i<imagewidth; i++){
\r
361 for(int j=0; j<imageheight; j++){
\r
362 _xp = Math.sin(c1.orientation)*(i-imagewidth*0.5) + Math.cos(c1.orientation) * (j-imageheight *0.5);
\r
363 _xp2 = Math.sin(c2.orientation)*(i-imagewidth*0.5) + Math.cos(c2.orientation) * (j-imageheight *0.5);
\r
364 col1 = bg_lum*contrast1*Math.sin(2*Math.PI*_xp/c1.lambda + 2*Math.PI*c1.tf*frame/(double)refresh);
\r
365 col2 = bg_lum*contrast2*Math.sin(2*Math.PI*_xp2/c2.lambda + 2*Math.PI*c2.tf*frame/(double)refresh);
\r
366 img[frame].pix(i,j,new Color(col1+col2+bg_lum));
\r
367 img[frame].alpha(i,j,alpha);
\r
370 //img[frame].cache();
\r
374 ///+ Stimulus drawing function
\r
375 //// A function for stimulus drawing (main body)
\r
377 Canvas display = new Canvas(Canvas.window);
\r
379 //// Declare and initialize local variables
\r
380 int rect_size = 150;
\r
381 double rect_lum = 0.5;
\r
382 double bg_lum = 0.2;
\r
383 double duration = 400;
\r
385 double[] lambda = new double[2], contrast = new double[2], tf = new double[2];
\r
386 double center_orientation = 0.0;
\r
387 Image[,] movie = StaticFunctions.NewArray<Image>(2, 120);
\r
388 Image[,] component_movie = StaticFunctions.NewArray<Image>(4, 120);
\r
389 Image envelope = new Image(), envelope_small = new Image();
\r
391 for(int i=0; i<120; i++)
\r
393 movie[0, i].set(rect_size, rect_size);
\r
394 movie[1, i].set(rect_size, rect_size);
\r
395 component_movie[0, i].set(rect_size/2, rect_size/2);
\r
396 component_movie[1, i].set(rect_size/2, rect_size/2);
\r
397 component_movie[2, i].set(rect_size/2, rect_size/2);
\r
398 component_movie[3, i].set(rect_size/2, rect_size/2);
\r
400 envelope.set(rect_size, rect_size);
\r
401 envelope_small.set(rect_size/2, rect_size/2);
\r
403 Letters let1 = new Letters(), let2 = new Letters(), let3 = new Letters();
\r
404 let1.str = "Component1";
\r
405 let2.str = "Component2";
\r
406 let3.str = "Superposition";
\r
407 let1.centering().shift(-rect_size*1.25, -rect_size);
\r
409 let2.centering().shift(rect_size*1.25, -rect_size);
\r
411 let3.centering().shift(0.0, rect_size*0.75);
\r
414 component c1, c2, c0;
\r
415 c0 = new component{ 0.0,0.0,1.0,1.0 }; //dummy for component movie
\r
417 // Prepare Type-I plaid movie
\r
418 center_orientation = 0.0;
\r
419 orientation_offset = Math.PI/6;
\r
420 contrast[0] = 1.0, contrast[1] = 1.0;
\r
421 lambda[0] = 30.0, lambda[1] = 30.0;
\r
422 tf[0] = 1.0; tf[1] = 1.0;
\r
424 c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};
\r
425 c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};
\r
427 drawgratingmovie(movie[0],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
428 drawgratingmovie(component_movie[0],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
429 drawgratingmovie(component_movie[1],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
433 // Prepare Type-II plaid movie
\r
434 center_orientation = -0.0, orientation_offset = Math.PI/12;
\r
435 contrast[0] = 1.0, contrast[1] = 1.0;
\r
436 lambda[0] = 30.0, lambda[1] = 30.0;
\r
437 tf[0] = 1.0; tf[1] = 4.0;
\r
439 c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};
\r
440 c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};
\r
442 drawgratingmovie(movie[1],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
443 drawgratingmovie(component_movie[2],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
444 drawgratingmovie(component_movie[3],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
448 //draw Gaussian envelopes
\r
449 envelope.clear(new Color(bg_lum)); //clear offscreen image
\r
451 for(int i=0; i<rect_size; i++){
\r
452 _x=i-0.5*rect_size;
\r
453 for(int j=0; j<rect_size; j++){
\r
454 _y=j-0.5*rect_size;
\r
455 envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/6.0, 2.0) ))));
\r
459 envelope_small.clear(new Color(bg_lum)); //clear offscreen image
\r
460 for(int i=0; i<rect_size*0.5; i++){
\r
461 _x=i-0.25*rect_size;
\r
462 for(int j=0; j<rect_size*0.5; j++){
\r
463 _y=j-0.25*rect_size;
\r
464 envelope_small.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/12.0, 2.0) ))));
\r
467 envelope.cache(); //send offscreen image from main memory to GPU
\r
468 envelope_small.cache(); //send offscreen image from main memory to GPU
\r
471 ///+ user interface
\r
472 // Draw user interface
\r
473 Widgets::SelectBox stimulus_type;
\r
474 stimulus_type.area.set(120, 20);
\r
475 stimulus_type.append(L"TypeI");
\r
476 stimulus_type.append(L"TypeII");
\r
477 stimulus_type.centering().shift(-120.0,250.0);
\r
479 Psychlops::Widgets::SelectBox stimulus_type2;
\r
480 stimulus_type2.area.set(120, 20);
\r
481 stimulus_type2.append(L"Continuous");
\r
482 stimulus_type2.append(L"Periodic");
\r
483 stimulus_type2.centering().shift(120.0,250.0);
\r
485 Psychlops::Widgets::Slider duration_slider;
\r
486 duration_slider.area.set(100,20);
\r
487 duration_slider.centering().shift(120,280.0);
\r
488 Interval rng = new Interval();
\r
489 duration_slider.link(duration, 50<=rng<=950, 50.0, 50.0);
\r
490 ///- user interface
\r
495 int period = refresh_int;
\r
497 while(!Keyboard.esc.pushed()) {
\r
498 Display.clear(new Color(bg_lum));
\r
499 movienum = stimulus_type.getSelected(); //if "Type-I" is selected, 0, else frame refresh per sec
\r
502 else period = refresh_int;
\r
505 movie[movienum, frame].centering().draw();
\r
506 envelope.centering().draw();
\r
507 component_movie[movienum*2, frame].centering().shift(-rect_size*0.5, -rect_size).draw();
\r
508 envelope_small.centering().shift(-rect_size*0.5, -rect_size).draw();
\r
509 component_movie[movienum*2+1, frame].centering().shift(rect_size*0.5, -rect_size).draw();
\r
510 envelope_small.centering().shift(rect_size*0.5, -rect_size).draw();
\r
513 ///+ draw user interface
\r
517 stimulus_type.draw();
\r
518 stimulus_type2.draw();
\r
519 if(stimulus_type2.getSelected())duration_slider.draw();
\r
520 ///- draw user interface
\r
522 if(frame++ >= period) frame -= refresh_int;
\r
527 ///- Stimulus drawing function
\r
529 ///+ Main function for demo circumstances
\r
530 public void psychlops_main() {
\r
531 ///+ Demo circumstances
\r
532 //// Spells for run demonstration circumstances
\r
533 Procedure p = new Procedure();
\r
534 //p.setDesign(Procedure::DEMO); //Designate that this is a demo.
\r
535 p.setProcedure(drawplaid); //The argument name is a name of drawing function.
\r
537 ///- Demo circumstances
\r
546 //Position Bias Program
\r
547 namespace PsychlopsSilverlightApp
\r
550 public class PsychlopsMain
\r
553 Image img, img2, img3;
\r
556 Psychlops.Widgets.Slider tfreq;
\r
557 Psychlops.Widgets.Slider contrast;
\r
558 Psychlops.Widgets.Slider lambda;
\r
562 public void psychlops_main()
\r
564 cnvs = new Canvas(300, 600);
\r
565 Interval rng = new Interval();
\r
566 tfreq = new Psychlops.Widgets.Slider("Temporal Frequency(Hz)", -5 <= rng <= 5, 3.0);
\r
567 contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.25);
\r
568 lambda = new Psychlops.Widgets.Slider("Wave Length", 10.0 <= rng <= 120.0, 30);
\r
570 img = new Image(isize * 2, isize * 2);
\r
571 img2 = new Image(isize * 2, isize * 2);
\r
572 img3 = new Image(isize * 2, isize * 2);
\r
574 var gabor1 = StaticFunctions.NewArray<Figures.ShaderGabor>(100);
\r
575 foreach(var g in gabor1)
\r
577 g.setSigma(isize / 8).centering().shift(Math.random(300) - 150, Math.random(600) - 300);
\r
578 g.orientation = Math.random(2*Math.PI);
\r
583 cnvs.clear(new Color(0.5));
\r
585 Figures.drawGabor(ref img, isize / 8, 1/lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);
\r
586 Figures.drawGabor(ref img2, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * -tfreq / 60);
\r
587 Figures.drawGabor(ref img3, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);
\r
590 //img.centering().shift(0, -isize * 1.5).draw();
\r
591 //img2.centering().draw();
\r
592 //img3.centering().shift(0, isize * 1.5).draw();
\r
595 foreach (var g in gabor1)
\r
597 g.wavelength = lambda;
\r
598 g.phase = (double)frames * 2.0 * Math.PI * tfreq / 60;
\r
599 g.contrast = contrast;
\r
603 if (!Mouse.left.pressed()) frames++;
\r