5 //Position Bias Program
\r
6 namespace PsychlopsSilverlightApp
\r
9 public class PsychlopsMain
\r
12 Image img, img2, img3;
\r
15 Psychlops.Widgets.Slider tfreq;
\r
16 Psychlops.Widgets.Slider contrast;
\r
17 Psychlops.Widgets.Slider lambda;
\r
21 public void psychlops_main()
\r
23 cnvs = new Canvas(300, 600);
\r
24 Interval rng = new Interval();
\r
25 tfreq = new Psychlops.Widgets.Slider("Temporal Frequency(Hz)", -5 <= rng <= 5, 3.0);
\r
26 contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.25);
\r
27 lambda = new Psychlops.Widgets.Slider("Wave Length", 10.0 <= rng <= 120.0, 30);
\r
29 img = new Image(isize * 2, isize * 2);
\r
30 img2 = new Image(isize * 2, isize * 2);
\r
31 img3 = new Image(isize * 2, isize * 2);
\r
33 var gabor1 = StaticFunctions.NewArray<Figures.ShaderGabor>(100);
\r
34 foreach (var g in gabor1)
\r
36 g.setSigma(isize/8).centering().shift(Math.random(300) - 150, Math.random(600) - 300);
\r
37 //g.setSize(isize).centering().shift(Math.random(300) - 150, Math.random(600) - 300);
\r
38 g.orientation = Math.random(2 * Math.PI);
\r
39 //g.orientation2 = Math.random(2 * Math.PI);
\r
44 cnvs.clear(new Color(0.5));
\r
46 Figures.drawGabor(ref img, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);
\r
47 Figures.drawGabor(ref img2, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * -tfreq / 60);
\r
48 Figures.drawGabor(ref img3, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);
\r
51 //img.centering().shift(0, -isize * 1.5).draw();
\r
52 //img2.centering().draw();
\r
53 //img3.centering().shift(0, isize * 1.5).draw();
\r
56 foreach (var g in gabor1)
\r
58 g.wavelength = lambda;
\r
59 g.phase = (double)frames * 2.0 * Math.PI * tfreq / 60;
\r
60 g.contrast = contrast;
\r
61 //g.wavelength2 = lambda * 2;
\r
62 //g.phase2 = (double)frames * 2.0 * Math.PI * tfreq / 60;
\r
63 //g.contrast2 = contrast / 2;
\r
67 if (!Mouse.left.pressed()) frames++;
\r
77 ///+ Prefix linkto BasicCode1
\r
78 //// Lines for set up Psychlops environment
\r
81 namespace PsychlopsSilverlightApp
\r
84 public class PsychlopsMain
\r
86 ///- Prefix linkto BasicCode1
\r
90 //// Psychlops runs at the first line of this function psychlops_main().
\r
91 public void psychlops_main()
\r
95 ////Prepare global parameters
\r
96 Rectangle p1 = new Rectangle(1,1);
\r
97 Color col1 = new Color();
\r
101 double lmean=0.25, contrast = 0.5;
\r
105 Canvas disp = new Canvas(Canvas.window, Display.secondary);
\r
107 var fieldW_ = Psychlops.Widgets.Browser.Element.byID("fieldW");
\r
108 var fieldH_ = Psychlops.Widgets.Browser.Element.byID("fieldH");
\r
109 var wL_ = Psychlops.Widgets.Browser.Element.byID("wL");
\r
110 var Cont_ = Psychlops.Widgets.Browser.Element.byID("Cont");
\r
111 var ix_ = Psychlops.Widgets.Browser.Element.byID("ix");
\r
112 var iy_ = Psychlops.Widgets.Browser.Element.byID("iy");
\r
113 var gap_ = Psychlops.Widgets.Browser.Element.byID("gap");
\r
118 p1.centering().shift(-width*0.5 + x0, -height*0.5 + y0); //Move a point to the initial position.
\r
122 ////drawing objects
\r
123 for(int i=0; i < width; i++)
\r
125 col1.set(lmean*((contrast*Math.sin((2*Math.PI*i/lambda)))+1)); //Set a color.
\r
127 ///+ 2.1 Drawing a column
\r
128 ////drawing a column
\r
129 for(int j=0;j < height; j++)
\r
132 p1.shift(0, pitch);
\r
134 ///- 2.1 Drawing a column
\r
136 p1.shift(1, -height * pitch); //back to vertical intitial point after drawing one column.
\r
141 while (!Keyboard.spc.pushed()) { }; //Wait until space key is pressed.
\r
153 //// Lines for set up Psychlops environment
\r
156 namespace PsychlopsSilverlightApp
\r
159 public class PsychlopsMain
\r
165 //// Psychlops runs at the first line of this function psychlops_main().
\r
166 public void psychlops_main()
\r
168 Canvas window = new Canvas(300, 300); //Create a window. Here, window variables are preset mode.
\r
170 var FIGURE = Psychlops.Widgets.Browser.Element.byID("FIGURE");
\r
171 var SIZE_X_ = Psychlops.Widgets.Browser.Element.byID("SIZE_X");
\r
172 var SIZE_Y_ = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");
\r
173 var COLOR_R = Psychlops.Widgets.Browser.Element.byID("COLOR_R");
\r
174 var COLOR_G = Psychlops.Widgets.Browser.Element.byID("COLOR_G");
\r
175 var COLOR_B = Psychlops.Widgets.Browser.Element.byID("COLOR_B");
\r
176 var COLOR_BG = Psychlops.Widgets.Browser.Element.byID("COLOR_BG");
\r
177 var Period_Size = Psychlops.Widgets.Browser.Element.byID("Period_Size");
\r
178 var Period_Position = Psychlops.Widgets.Browser.Element.byID("Period_Position");
\r
179 var Speed_HSize_ = Psychlops.Widgets.Browser.Element.byID("Speed_HSize");
\r
180 var Speed_VSize = Psychlops.Widgets.Browser.Element.byID("Speed_VSize");
\r
181 var Speed_VMotion = Psychlops.Widgets.Browser.Element.byID("Speed_VMotion");
\r
182 double SIZE_X = SIZE_X_, SIZE_Y = SIZE_Y_;
\r
185 //// Set a figure size, position and color.
\r
186 Rectangle figure = new Rectangle();
\r
187 Ellipse figure2 = new Ellipse();
\r
188 figure.set(SIZE_X_, SIZE_Y_); // Set the size of figure.
\r
189 figure2.set(SIZE_X_, SIZE_Y_); // Set the size of figure.
\r
190 figure.centering().shift(0, 0); // Move the figure to the starting point.
\r
191 figure2.centering().shift(0, 0); // Move the figure to the starting point.
\r
195 int looming_direction = 1, motion_dir = 1;
\r
196 double direction = 1.0;
\r
197 //looming_direction is a variable for size change.
\r
198 //motion_dir is a variable for motion direction.
\r
199 ///+ 3 Drawing loop
\r
200 //// Draw each frames in a "while loop".
\r
201 while (!Keyboard.esc.pushed())
\r
202 { //exit a program when the escape key is pressed down.
\r
203 window.clear(COLOR_BG); // Clear the window with a designated gray-scale level.
\r
206 //// Calculate object's position and size for each frame.
\r
208 if (frame % Period_Size == 0)
\r
209 { // a direction of size change will reverse at designated frames.
\r
210 looming_direction = looming_direction * -1;
\r
213 if (frame % Period_Position == 0)
\r
214 { // motion direction will reverse at designated frames.
\r
221 //// Settting figure's properties
\r
222 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
223 figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".
\r
224 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
225 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
226 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".
\r
227 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
229 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
230 figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".
\r
231 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
232 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
233 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".
\r
234 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
240 if ("Rectangle".Equals(FIGURE))
\r
242 figure.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.
\r
246 figure2.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.
\r
248 window.flip(); // Reflect the drawing for the display by flipping frame buffers.
\r
252 ////make a step for next frames
\r
256 ///- 3 Drawing loop
\r
269 //The reversed-phi motion.
\r
271 //Phi movement as a subtraction process. Vision Res 10:1411?1430
\r
274 //// Include Psychlops Package
\r
277 namespace PsychlopsSilverlightApp
\r
280 public class PsychlopsMain
\r
285 ///+ Stimulus drawing function
\r
286 //// A function for stimulus drawing (main body)
\r
287 void RectLuminance()
\r
291 //// Declare and initialize local variables
\r
292 double rect_size = 20;
\r
294 double bg_lum = 0.5;
\r
295 double radii = 200;
\r
297 int element_number = 25;
\r
298 int radial_row = 5;
\r
300 double rotation_tf = 0.2;
\r
301 double polarity = 1;
\r
304 double contrastflag = 1;
\r
308 Canvas display = new Canvas(Canvas.window); //Prepare drawing window
\r
309 refresh = Display.getRefreshRate();
\r
311 Ellipse rect = new Ellipse();
\r
312 rect.set(rect_size, rect_size);
\r
314 Ellipse fixation = new Ellipse(5, 5);
\r
315 fixation.centering();
\r
317 Letters let1 = new Letters("Press Space key to change stimulus type");
\r
318 let1.centering().shift(-180, 220);
\r
319 Letters let2 = new Letters("Phi");
\r
320 let2.centering().shift(-10, 200);
\r
321 Letters let3 = new Letters("Reversed-Phi");
\r
322 let3.centering().shift(-60, 200);
\r
324 rotation = Math.random(2 * Math.PI);
\r
326 ///+ user interface
\r
327 ////register variables to demo circumstances
\r
328 Interval rng = new Interval();
\r
330 Psychlops.Widgets.Slider rect_contrast;
\r
331 rect_contrast = new Psychlops.Widgets.Slider("Contrast", 0.1 <= rng <= 1.0, 0.1);
\r
332 rect_contrast.value = 0.5;
\r
333 ///- user interface
\r
339 //AppState::setThreadPriority(AppState::HIGH);
\r
343 if (Keyboard.spc.pushed()) contrastflag = -contrastflag;
\r
344 if (contrastflag < 0) polarity = -polarity;
\r
345 rotation = 2 * Math.PI * rotation_tf * frame * period / refresh;
\r
347 for (int frame_now = 0; frame_now < period; frame_now++)
\r
349 Display.clear(new Color(bg_lum));
\r
350 for (int j = 0; j < radial_row; j++)
\r
352 rect.resize(rect_size * (j + radial_row) / 10.0, rect_size * (j + radial_row) / 10.0);
\r
353 for (double i = 0; i < element_number; i++)
\r
355 rect_lum = bg_lum * (1.0 + polarity * rect_contrast);
\r
356 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
357 rect.draw(rect_lum);
\r
360 fixation.draw(Color.red);
\r
362 if (contrastflag > 0) let2.draw();
\r
368 //AppState::setThreadPriority(AppState::NORMAL);
\r
370 ///- Stimulus drawing function
\r
372 ///+ Main function for demo circumstances
\r
373 //// Psychlops Main function
\r
374 public void psychlops_main()
\r
376 ///+ Demo circumstances
\r
377 //// Spells for run demonstration circumstances
\r
378 Procedure p = new Procedure();
\r
379 //p.setDesign(Procedure::DEMO); //Designate that this is a demo.
\r
380 p.setProcedure(RectLuminance); //The argument name is a name of drawing function.
\r
382 ///- Demo circumstances
\r
384 ///- Main function for demo circumstances
\r
393 //Two types of plaid motion
\r
394 //E. H. Adelson and J. A. Movshon (1982).
\r
395 //Phenomenal coherence of moving visual patterns. Nature 300, 523-525
\r
398 //// Include Psychlops Package
\r
401 namespace PsychlopsSilverlightApp
\r
404 public class PsychlopsMain
\r
409 // Struct for component paremeters
\r
412 public double contrast;
\r
413 public double orientation;
\r
414 public double lambda;
\r
419 ///+ Stimulus drawing function
\r
420 //// A function for stimulus drawing (main body)
\r
421 void drawgratingmovie(Image[] img, component c1, component c2, double contrast, int start, int maxframe, double bg_lum, double alpha)
\r
423 double _xp, _xp2, col1, col2;
\r
424 double contrast1, contrast2;
\r
425 double imageheight, imagewidth;
\r
427 contrast1 = contrast*c1.contrast/(c1.contrast+c2.contrast);
\r
428 contrast2 = contrast*c2.contrast/(c1.contrast+c2.contrast);
\r
430 imageheight = img[0].getHeight();
\r
431 imagewidth = img[0].getWidth();
\r
433 for(int frame=start; frame<start+maxframe+1; frame++){
\r
434 //Display.progressbar(frame, maxframe+1);
\r
435 //img[frame].convert(Image::RGBA);
\r
436 for(int i=0; i<imagewidth; i++){
\r
437 for(int j=0; j<imageheight; j++){
\r
438 _xp = Math.sin(c1.orientation)*(i-imagewidth*0.5) + Math.cos(c1.orientation) * (j-imageheight *0.5);
\r
439 _xp2 = Math.sin(c2.orientation)*(i-imagewidth*0.5) + Math.cos(c2.orientation) * (j-imageheight *0.5);
\r
440 col1 = bg_lum*contrast1*Math.sin(2*Math.PI*_xp/c1.lambda + 2*Math.PI*c1.tf*frame/(double)refresh);
\r
441 col2 = bg_lum*contrast2*Math.sin(2*Math.PI*_xp2/c2.lambda + 2*Math.PI*c2.tf*frame/(double)refresh);
\r
442 img[frame].pix(i,j,new Color(col1+col2+bg_lum));
\r
443 img[frame].alpha(i,j,alpha);
\r
446 //img[frame].cache();
\r
450 ///+ Stimulus drawing function
\r
451 //// A function for stimulus drawing (main body)
\r
453 Canvas display = new Canvas(Canvas.window);
\r
455 //// Declare and initialize local variables
\r
456 int rect_size = 150;
\r
457 double rect_lum = 0.5;
\r
458 double bg_lum = 0.2;
\r
459 double duration = 400;
\r
461 double[] lambda = new double[2], contrast = new double[2], tf = new double[2];
\r
462 double center_orientation = 0.0;
\r
463 Image[,] movie = StaticFunctions.NewArray<Image>(2, 120);
\r
464 Image[,] component_movie = StaticFunctions.NewArray<Image>(4, 120);
\r
465 Image envelope = new Image(), envelope_small = new Image();
\r
467 for(int i=0; i<120; i++)
\r
469 movie[0, i].set(rect_size, rect_size);
\r
470 movie[1, i].set(rect_size, rect_size);
\r
471 component_movie[0, i].set(rect_size/2, rect_size/2);
\r
472 component_movie[1, i].set(rect_size/2, rect_size/2);
\r
473 component_movie[2, i].set(rect_size/2, rect_size/2);
\r
474 component_movie[3, i].set(rect_size/2, rect_size/2);
\r
476 envelope.set(rect_size, rect_size);
\r
477 envelope_small.set(rect_size/2, rect_size/2);
\r
479 Letters let1 = new Letters(), let2 = new Letters(), let3 = new Letters();
\r
480 let1.str = "Component1";
\r
481 let2.str = "Component2";
\r
482 let3.str = "Superposition";
\r
483 let1.centering().shift(-rect_size*1.25, -rect_size);
\r
485 let2.centering().shift(rect_size*1.25, -rect_size);
\r
487 let3.centering().shift(0.0, rect_size*0.75);
\r
490 component c1, c2, c0;
\r
491 c0 = new component{ 0.0,0.0,1.0,1.0 }; //dummy for component movie
\r
493 // Prepare Type-I plaid movie
\r
494 center_orientation = 0.0;
\r
495 orientation_offset = Math.PI/6;
\r
496 contrast[0] = 1.0, contrast[1] = 1.0;
\r
497 lambda[0] = 30.0, lambda[1] = 30.0;
\r
498 tf[0] = 1.0; tf[1] = 1.0;
\r
500 c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};
\r
501 c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};
\r
503 drawgratingmovie(movie[0],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
504 drawgratingmovie(component_movie[0],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
505 drawgratingmovie(component_movie[1],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
509 // Prepare Type-II plaid movie
\r
510 center_orientation = -0.0, orientation_offset = Math.PI/12;
\r
511 contrast[0] = 1.0, contrast[1] = 1.0;
\r
512 lambda[0] = 30.0, lambda[1] = 30.0;
\r
513 tf[0] = 1.0; tf[1] = 4.0;
\r
515 c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};
\r
516 c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};
\r
518 drawgratingmovie(movie[1],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
519 drawgratingmovie(component_movie[2],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
520 drawgratingmovie(component_movie[3],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
524 //draw Gaussian envelopes
\r
525 envelope.clear(new Color(bg_lum)); //clear offscreen image
\r
527 for(int i=0; i<rect_size; i++){
\r
528 _x=i-0.5*rect_size;
\r
529 for(int j=0; j<rect_size; j++){
\r
530 _y=j-0.5*rect_size;
\r
531 envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/6.0, 2.0) ))));
\r
535 envelope_small.clear(new Color(bg_lum)); //clear offscreen image
\r
536 for(int i=0; i<rect_size*0.5; i++){
\r
537 _x=i-0.25*rect_size;
\r
538 for(int j=0; j<rect_size*0.5; j++){
\r
539 _y=j-0.25*rect_size;
\r
540 envelope_small.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/12.0, 2.0) ))));
\r
543 envelope.cache(); //send offscreen image from main memory to GPU
\r
544 envelope_small.cache(); //send offscreen image from main memory to GPU
\r
547 ///+ user interface
\r
548 // Draw user interface
\r
549 Widgets::SelectBox stimulus_type;
\r
550 stimulus_type.area.set(120, 20);
\r
551 stimulus_type.append(L"TypeI");
\r
552 stimulus_type.append(L"TypeII");
\r
553 stimulus_type.centering().shift(-120.0,250.0);
\r
555 Psychlops::Widgets::SelectBox stimulus_type2;
\r
556 stimulus_type2.area.set(120, 20);
\r
557 stimulus_type2.append(L"Continuous");
\r
558 stimulus_type2.append(L"Periodic");
\r
559 stimulus_type2.centering().shift(120.0,250.0);
\r
561 Psychlops::Widgets::Slider duration_slider;
\r
562 duration_slider.area.set(100,20);
\r
563 duration_slider.centering().shift(120,280.0);
\r
564 Interval rng = new Interval();
\r
565 duration_slider.link(duration, 50<=rng<=950, 50.0, 50.0);
\r
566 ///- user interface
\r
571 int period = refresh_int;
\r
573 while(!Keyboard.esc.pushed()) {
\r
574 Display.clear(new Color(bg_lum));
\r
575 movienum = stimulus_type.getSelected(); //if "Type-I" is selected, 0, else frame refresh per sec
\r
578 else period = refresh_int;
\r
581 movie[movienum, frame].centering().draw();
\r
582 envelope.centering().draw();
\r
583 component_movie[movienum*2, frame].centering().shift(-rect_size*0.5, -rect_size).draw();
\r
584 envelope_small.centering().shift(-rect_size*0.5, -rect_size).draw();
\r
585 component_movie[movienum*2+1, frame].centering().shift(rect_size*0.5, -rect_size).draw();
\r
586 envelope_small.centering().shift(rect_size*0.5, -rect_size).draw();
\r
589 ///+ draw user interface
\r
593 stimulus_type.draw();
\r
594 stimulus_type2.draw();
\r
595 if(stimulus_type2.getSelected())duration_slider.draw();
\r
596 ///- draw user interface
\r
598 if(frame++ >= period) frame -= refresh_int;
\r
603 ///- Stimulus drawing function
\r
605 ///+ Main function for demo circumstances
\r
606 public void psychlops_main() {
\r
607 ///+ Demo circumstances
\r
608 //// Spells for run demonstration circumstances
\r
609 Procedure p = new Procedure();
\r
610 //p.setDesign(Procedure::DEMO); //Designate that this is a demo.
\r
611 p.setProcedure(drawplaid); //The argument name is a name of drawing function.
\r
613 ///- Demo circumstances
\r