1 //Psychlops Code Template
\r
2 // Please visit following web site to get sample codes.
\r
3 // http://psychlops.sourceforge.jp/ja/?StartCode
\r
4 // CodeDresser at following address is also available to view the code.
\r
5 // http://visitope.org/Tools/codedresser.html
\r
7 ///+ 0 Setup Psychlops Circumstances
\r
8 //// 0 Setup Psychlops Circumstances
\r
11 namespace PsychlopsSilverlightApp
\r
14 public class PsychlopsMain
\r
16 // Psychlops Win32 1.5.5 / 20110927
\r
17 ///- 0 Setup Psychlops Circumstances
\r
19 Psychlops.Widgets.Slider SOAFrames, gap, wavelength, contrast;
\r
21 public void psychlops_main() {
\r
23 ///+ 1 Declaration /////////////////////////////////////////////////////////////
\r
25 // declare default window and variables for its parameters
\r
26 Canvas cnvs = new Canvas(900,600, Canvas.window, Display.primary);
\r
27 double CANVAS_FRAMENUM;
\r
28 int CANVAS_REFRESHRATE;
\r
29 Color DEFAULT_BG_COLOR = new Color();
\r
31 int gratingwidth = 500, gratingheight = 100;
\r
33 Color color = new Color(0.0,0.0,0.0);
\r
34 Rectangle grating = new Rectangle();
\r
37 Interval rng = new Interval();
\r
39 //declare local variables around here
\r
41 ///- 1 Declaration /////////////////////////////////////////////////////////////
\r
43 ///+ 2 Initialization //////////////////////////////////////////////////////////
\r
44 //// 2 Initialization
\r
46 // Set initial values for local variables
\r
47 CANVAS_REFRESHRATE = (int)cnvs.getRefreshRate();
\r
48 CANVAS_FRAMENUM = 0;
\r
49 DEFAULT_BG_COLOR.set(127.0/255.0,127.0/255.0,127.0/255.0,1.0); // default background color is 127/255 mid-gray
\r
52 SOAFrames = new Psychlops.Widgets.Slider("SOA Frames", 1 <=rng<=20 , 1 , 1);
\r
53 SOAFrames.value = 5;
\r
54 gap = new Psychlops.Widgets.Slider("Grating gap" , 0 <=rng<=200 , 1 , 10);
\r
56 wavelength = new Psychlops.Widgets.Slider("Wave Length", 1 <= rng <= 50, 1, 10);
\r
57 wavelength.value = 30.0;
\r
58 contrast = new Psychlops.Widgets.Slider("Contrast" , 0.0<=rng<=1.0 , 0.1 , 0.01);
\r
59 contrast.value = 0.1;
\r
61 // Draw Offline images around here
\r
63 // Offline Movie calculation using Image array around here
\r
65 ///- 2 Initialization //////////////////////////////////////////////////////////
\r
67 ///+ 3 Drawing /////////////////////////////////////////////////////////////////
\r
69 while(!Keyboard.esc.pushed()) {
\r
70 cnvs.clear(DEFAULT_BG_COLOR);
\r
72 //Write draw commands for realtime figure calculation and drawing around here
\r
75 if(Math.mod(CANVAS_FRAMENUM,SOAFrames) == 0){shift += 1;}
\r
77 grating.set(1,gratingheight).centering().shift(-gratingwidth/2, 0);
\r
78 for(int i=0; i<gratingwidth; i++) {
\r
80 + 0.25*contrast*Math.sin(2*Math.PI*(i*2.0/wavelength + 0.50 * shift))
\r
81 + 0.25*contrast*Math.sin(2*Math.PI*(i*3.0/wavelength + 0.75 * shift))
\r
84 grating.shift(1, 0);
\r
85 grating.draw(color);
\r
88 grating.set(1,gratingheight).centering().shift(-gratingwidth/2, -gratingheight-gap);
\r
89 for(int i=0; i<gratingwidth; i++) {
\r
91 + 0.25*contrast*Math.sin(2.0*Math.PI*(i*2.0/wavelength + 0.50 * shift))
\r
95 grating.draw(color);
\r
98 grating.set(1,gratingheight).centering().shift(-gratingwidth/2, gratingheight+gap);
\r
99 for(int i=0; i<gratingwidth; i++) {
\r
101 + 0.25*contrast*Math.sin(2.0*Math.PI*(i*3.0/wavelength + 0.75 * shift))
\r
104 grating.shift(1,0);
\r
105 grating.draw(color);
\r
111 ///- 3 Drawing /////////////////////////////////////////////////////////////////
\r
121 public void psychlops_main() {
\r
123 Canvas display = new Canvas(768,768);
\r
125 double rect_size = 100;
\r
126 double rect_lum = 0.5;
\r
127 double bg_lum = 0.5;
\r
128 double size = 250.0;
\r
133 int envelopemode = 0;
\r
134 double refresh = display.getRefreshRate();
\r
135 double[] SF=new double[2];
\r
142 double[] initphase = new double[2];
\r
143 double _i, _j, _x, _y, _x2, _y2, col;
\r
144 double amplitude = 1.0;
\r
146 Rectangle fixation1 = new Rectangle(3,9);
\r
147 Rectangle fixation2 = new Rectangle(9,3);
\r
148 fixation1.centering();
\r
149 fixation2.centering();
\r
150 Rectangle contrastrect = new Rectangle();
\r
151 contrastrect.set(760,760);
\r
153 Image envelope = new Image();
\r
154 Psychlops.Color bglum= new Color(0.5,0.5,0.5);
\r
155 Psychlops.Color masklum = new Color(0.5,0.5,0.5,0.5);
\r
157 Interval rng = new Interval();
\r
160 Psychlops.Widgets.Slider TF;
\r
161 TF = new Psychlops.Widgets.Slider("TF", 0.25<=rng<=2.0 , 0.1);
\r
166 Psychlops.Widgets.Slider SFs;
\r
167 SFs = new Psychlops.Widgets.Slider("SF", 4.0<=rng<=16.0 , 4.0);
\r
170 Psychlops.Widgets.Slider contrast;
\r
171 contrast= new Psychlops.Widgets.Slider("Contrast", 0.0<=rng<=1.0 , 0.1);
\r
172 contrast.value = 0.1;
\r
175 var element = StaticFunctions.NewArray<Figures.ShaderGabor>(2);
\r
176 for (int i = 0; i < element.Length; i++){
\r
177 element[i].setSigma(sigma); // set a size of patch as a halfwidth of Gaussian
\r
178 element[i].orientation = Math.PI/4.0+Math.PI/2.0*(1-i);//Math.PI/2*(rand()%2);// //set orientations
\r
184 envelope.set(size, size);
\r
185 envelope.clear(bglum);
\r
187 for(int i=0; i<size; i++){
\r
188 for(int j=0; j<size; j++){
\r
191 _x=_i*Math.cos(-Math.PI/4.0)+_j*Math.sin(-Math.PI/4.0);
\r
192 _y=-_i*Math.sin(-Math.PI/4.0)+_j*Math.cos(-Math.PI/4.0);
\r
193 col=Math.exp(-(_x*_x)/(2*Math.pow(sigma*2/6.0,2.0))-(_y*_y)/(2*Math.pow(sigma*2,2.0)));
\r
194 envelope.alpha(i,j,1.0-col);
\r
200 while(!Keyboard.esc.pushed()) {
\r
201 if(Keyboard.spc.pushed())envelopemode++; envelopemode%=2;
\r
202 Display.clear(bglum);
\r
204 //phase = fmod(phase,60);
\r
206 for(int i=0; i<2; i++) {
\r
207 element[i].phase =(SF[i]/SF[0])*amplitude*
\r
208 Math.PI*Math.sin(Math.PI/2*i+2*Math.PI*phase*TF/refresh);
\r
209 element[i].wavelength = lambda/SF[i];
\r
210 element[i].contrast = contrast;
\r
214 element[0].centering().shift(-size * 0.6, -size * 0.6);
\r
216 element[1].centering().shift(size*0.6,-size*0.6);
\r
218 element[1].centering().shift(-size*0.6,size*0.6);
\r
220 element[0].centering().shift(size*0.6,size*0.6);
\r
224 if(envelopemode>0){
\r
225 envelope.centering().shift(size*0.6,-size*0.6).draw();
\r
226 envelope.centering().shift(-size*0.6,size*0.6).draw();
\r
228 masklum.set(bg_lum, bg_lum, bg_lum, 1-contrast);
\r
229 contrastrect.centering();
\r
230 contrastrect.draw(masklum);
\r
231 fixation1.centering().shift(size*2,0.0);
\r
232 fixation1.draw(Color.red);
\r
233 fixation2.centering().shift(size*2,0.0);
\r
234 fixation2.draw(Color.red);
\r
236 Display.var(Mouse.x, 300, 300);
\r
237 Display.var(Mouse.y, 300, 320);
\r
255 //Position Bias Program
\r
256 namespace PsychlopsSilverlightApp
\r
259 public class PsychlopsMain
\r
262 Image img, img2, img3;
\r
265 Psychlops.Widgets.Slider tfreq;
\r
266 Psychlops.Widgets.Slider contrast;
\r
267 Psychlops.Widgets.Slider lambda;
\r
271 public void psychlops_main()
\r
273 cnvs = new Canvas(300, 600);
\r
274 Interval rng = new Interval();
\r
275 tfreq = new Psychlops.Widgets.Slider("Temporal Frequency(Hz)", -5 <= rng <= 5, 3.0);
\r
276 contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.25);
\r
277 lambda = new Psychlops.Widgets.Slider("Wave Length", 10.0 <= rng <= 120.0, 30);
\r
279 img = new Image(isize * 2, isize * 2);
\r
280 img2 = new Image(isize * 2, isize * 2);
\r
281 img3 = new Image(isize * 2, isize * 2);
\r
283 var gabor1 = StaticFunctions.NewArray<Figures.ShaderGabor>(100);
\r
284 foreach (var g in gabor1)
\r
286 g.setSigma(isize/8).centering().shift(Math.random(300) - 150, Math.random(600) - 300);
\r
287 //g.setSize(isize).centering().shift(Math.random(300) - 150, Math.random(600) - 300);
\r
288 g.orientation = Math.random(2 * Math.PI);
\r
289 //g.orientation2 = Math.random(2 * Math.PI);
\r
294 cnvs.clear(new Color(0.5));
\r
296 Figures.drawGabor(ref img, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);
\r
297 Figures.drawGabor(ref img2, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * -tfreq / 60);
\r
298 Figures.drawGabor(ref img3, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);
\r
301 //img.centering().shift(0, -isize * 1.5).draw();
\r
302 //img2.centering().draw();
\r
303 //img3.centering().shift(0, isize * 1.5).draw();
\r
306 //foreach (var g in gabor1)
\r
307 for (int i = 0; i < gabor1.Length; i++)
\r
309 gabor1[i].wavelength = lambda;
\r
310 gabor1[i].phase = (double)frames * 2.0 * Math.PI * tfreq / 60;
\r
311 gabor1[i].contrast = contrast;
\r
312 //g.wavelength2 = lambda * 2;
\r
313 //g.phase2 = (double)frames * 2.0 * Math.PI * tfreq / 60;
\r
314 //g.contrast2 = contrast / 2;
\r
318 if (!Mouse.left.pressed()) frames++;
\r
328 ///+ Prefix linkto BasicCode1
\r
329 //// Lines for set up Psychlops environment
\r
332 namespace PsychlopsSilverlightApp
\r
335 public class PsychlopsMain
\r
337 ///- Prefix linkto BasicCode1
\r
341 //// Psychlops runs at the first line of this function psychlops_main().
\r
342 public void psychlops_main()
\r
346 ////Prepare global parameters
\r
347 Rectangle p1 = new Rectangle(1,1);
\r
348 Color col1 = new Color();
\r
352 double lmean=0.25, contrast = 0.5;
\r
356 Canvas disp = new Canvas(Canvas.window, Display.secondary);
\r
358 var fieldW_ = Psychlops.Widgets.Browser.Element.byID("fieldW");
\r
359 var fieldH_ = Psychlops.Widgets.Browser.Element.byID("fieldH");
\r
360 var wL_ = Psychlops.Widgets.Browser.Element.byID("wL");
\r
361 var Cont_ = Psychlops.Widgets.Browser.Element.byID("Cont");
\r
362 var ix_ = Psychlops.Widgets.Browser.Element.byID("ix");
\r
363 var iy_ = Psychlops.Widgets.Browser.Element.byID("iy");
\r
364 var gap_ = Psychlops.Widgets.Browser.Element.byID("gap");
\r
369 p1.centering().shift(-width*0.5 + x0, -height*0.5 + y0); //Move a point to the initial position.
\r
373 ////drawing objects
\r
374 for(int i=0; i < width; i++)
\r
376 col1.set(lmean*((contrast*Math.sin((2*Math.PI*i/lambda)))+1)); //Set a color.
\r
378 ///+ 2.1 Drawing a column
\r
379 ////drawing a column
\r
380 for(int j=0;j < height; j++)
\r
383 p1.shift(0, pitch);
\r
385 ///- 2.1 Drawing a column
\r
387 p1.shift(1, -height * pitch); //back to vertical intitial point after drawing one column.
\r
392 while (!Keyboard.spc.pushed()) { }; //Wait until space key is pressed.
\r
404 //// Lines for set up Psychlops environment
\r
407 namespace PsychlopsSilverlightApp
\r
410 public class PsychlopsMain
\r
416 //// Psychlops runs at the first line of this function psychlops_main().
\r
417 public void psychlops_main()
\r
419 Canvas window = new Canvas(300, 300); //Create a window. Here, window variables are preset mode.
\r
421 var FIGURE = Psychlops.Widgets.Browser.Element.byID("FIGURE");
\r
422 var SIZE_X_ = Psychlops.Widgets.Browser.Element.byID("SIZE_X");
\r
423 var SIZE_Y_ = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");
\r
424 var COLOR_R = Psychlops.Widgets.Browser.Element.byID("COLOR_R");
\r
425 var COLOR_G = Psychlops.Widgets.Browser.Element.byID("COLOR_G");
\r
426 var COLOR_B = Psychlops.Widgets.Browser.Element.byID("COLOR_B");
\r
427 var COLOR_BG = Psychlops.Widgets.Browser.Element.byID("COLOR_BG");
\r
428 var Period_Size = Psychlops.Widgets.Browser.Element.byID("Period_Size");
\r
429 var Period_Position = Psychlops.Widgets.Browser.Element.byID("Period_Position");
\r
430 var Speed_HSize_ = Psychlops.Widgets.Browser.Element.byID("Speed_HSize");
\r
431 var Speed_VSize = Psychlops.Widgets.Browser.Element.byID("Speed_VSize");
\r
432 var Speed_VMotion = Psychlops.Widgets.Browser.Element.byID("Speed_VMotion");
\r
433 double SIZE_X = SIZE_X_, SIZE_Y = SIZE_Y_;
\r
436 //// Set a figure size, position and color.
\r
437 Rectangle figure = new Rectangle();
\r
438 Ellipse figure2 = new Ellipse();
\r
439 figure.set(SIZE_X_, SIZE_Y_); // Set the size of figure.
\r
440 figure2.set(SIZE_X_, SIZE_Y_); // Set the size of figure.
\r
441 figure.centering().shift(0, 0); // Move the figure to the starting point.
\r
442 figure2.centering().shift(0, 0); // Move the figure to the starting point.
\r
446 int looming_direction = 1, motion_dir = 1;
\r
447 double direction = 1.0;
\r
448 //looming_direction is a variable for size change.
\r
449 //motion_dir is a variable for motion direction.
\r
450 ///+ 3 Drawing loop
\r
451 //// Draw each frames in a "while loop".
\r
452 while (!Keyboard.esc.pushed())
\r
453 { //exit a program when the escape key is pressed down.
\r
454 window.clear(COLOR_BG); // Clear the window with a designated gray-scale level.
\r
457 //// Calculate object's position and size for each frame.
\r
459 if (frame % Period_Size == 0)
\r
460 { // a direction of size change will reverse at designated frames.
\r
461 looming_direction = looming_direction * -1;
\r
464 if (frame % Period_Position == 0)
\r
465 { // motion direction will reverse at designated frames.
\r
472 //// Settting figure's properties
\r
473 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
474 figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".
\r
475 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
476 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
477 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".
\r
478 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
480 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
481 figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".
\r
482 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
483 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
484 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".
\r
485 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
491 if ("Rectangle".Equals(FIGURE))
\r
493 figure.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.
\r
497 figure2.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.
\r
499 window.flip(); // Reflect the drawing for the display by flipping frame buffers.
\r
503 ////make a step for next frames
\r
507 ///- 3 Drawing loop
\r
520 //The reversed-phi motion.
\r
522 //Phi movement as a subtraction process. Vision Res 10:1411?1430
\r
525 //// Include Psychlops Package
\r
528 namespace PsychlopsSilverlightApp
\r
531 public class PsychlopsMain
\r
536 ///+ Stimulus drawing function
\r
537 //// A function for stimulus drawing (main body)
\r
538 void RectLuminance()
\r
542 //// Declare and initialize local variables
\r
543 double rect_size = 20;
\r
545 double bg_lum = 0.5;
\r
546 double radii = 200;
\r
548 int element_number = 25;
\r
549 int radial_row = 5;
\r
551 double rotation_tf = 0.2;
\r
552 double polarity = 1;
\r
555 double contrastflag = 1;
\r
559 Canvas display = new Canvas(Canvas.window); //Prepare drawing window
\r
560 refresh = Display.getRefreshRate();
\r
562 Ellipse rect = new Ellipse();
\r
563 rect.set(rect_size, rect_size);
\r
565 Ellipse fixation = new Ellipse(5, 5);
\r
566 fixation.centering();
\r
568 Letters let1 = new Letters("Press Space key to change stimulus type");
\r
569 let1.centering().shift(-180, 220);
\r
570 Letters let2 = new Letters("Phi");
\r
571 let2.centering().shift(-10, 200);
\r
572 Letters let3 = new Letters("Reversed-Phi");
\r
573 let3.centering().shift(-60, 200);
\r
575 rotation = Math.random(2 * Math.PI);
\r
577 ///+ user interface
\r
578 ////register variables to demo circumstances
\r
579 Interval rng = new Interval();
\r
581 Psychlops.Widgets.Slider rect_contrast;
\r
582 rect_contrast = new Psychlops.Widgets.Slider("Contrast", 0.1 <= rng <= 1.0, 0.1);
\r
583 rect_contrast.value = 0.5;
\r
584 ///- user interface
\r
590 //AppState::setThreadPriority(AppState::HIGH);
\r
594 if (Keyboard.spc.pushed()) contrastflag = -contrastflag;
\r
595 if (contrastflag < 0) polarity = -polarity;
\r
596 rotation = 2 * Math.PI * rotation_tf * frame * period / refresh;
\r
598 for (int frame_now = 0; frame_now < period; frame_now++)
\r
600 Display.clear(new Color(bg_lum));
\r
601 for (int j = 0; j < radial_row; j++)
\r
603 rect.resize(rect_size * (j + radial_row) / 10.0, rect_size * (j + radial_row) / 10.0);
\r
604 for (double i = 0; i < element_number; i++)
\r
606 rect_lum = bg_lum * (1.0 + polarity * rect_contrast);
\r
607 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
608 rect.draw(rect_lum);
\r
611 fixation.draw(Color.red);
\r
613 if (contrastflag > 0) let2.draw();
\r
619 //AppState::setThreadPriority(AppState::NORMAL);
\r
621 ///- Stimulus drawing function
\r
623 ///+ Main function for demo circumstances
\r
624 //// Psychlops Main function
\r
625 public void psychlops_main()
\r
627 ///+ Demo circumstances
\r
628 //// Spells for run demonstration circumstances
\r
629 Procedure p = new Procedure();
\r
630 //p.setDesign(Procedure::DEMO); //Designate that this is a demo.
\r
631 p.setProcedure(RectLuminance); //The argument name is a name of drawing function.
\r
633 ///- Demo circumstances
\r
635 ///- Main function for demo circumstances
\r
644 //Two types of plaid motion
\r
645 //E. H. Adelson and J. A. Movshon (1982).
\r
646 //Phenomenal coherence of moving visual patterns. Nature 300, 523-525
\r
649 //// Include Psychlops Package
\r
652 namespace PsychlopsSilverlightApp
\r
655 public class PsychlopsMain
\r
660 // Struct for component paremeters
\r
663 public double contrast;
\r
664 public double orientation;
\r
665 public double lambda;
\r
670 ///+ Stimulus drawing function
\r
671 //// A function for stimulus drawing (main body)
\r
672 void drawgratingmovie(Image[] img, component c1, component c2, double contrast, int start, int maxframe, double bg_lum, double alpha)
\r
674 double _xp, _xp2, col1, col2;
\r
675 double contrast1, contrast2;
\r
676 double imageheight, imagewidth;
\r
678 contrast1 = contrast*c1.contrast/(c1.contrast+c2.contrast);
\r
679 contrast2 = contrast*c2.contrast/(c1.contrast+c2.contrast);
\r
681 imageheight = img[0].getHeight();
\r
682 imagewidth = img[0].getWidth();
\r
684 for(int frame=start; frame<start+maxframe+1; frame++){
\r
685 //Display.progressbar(frame, maxframe+1);
\r
686 //img[frame].convert(Image::RGBA);
\r
687 for(int i=0; i<imagewidth; i++){
\r
688 for(int j=0; j<imageheight; j++){
\r
689 _xp = Math.sin(c1.orientation)*(i-imagewidth*0.5) + Math.cos(c1.orientation) * (j-imageheight *0.5);
\r
690 _xp2 = Math.sin(c2.orientation)*(i-imagewidth*0.5) + Math.cos(c2.orientation) * (j-imageheight *0.5);
\r
691 col1 = bg_lum*contrast1*Math.sin(2*Math.PI*_xp/c1.lambda + 2*Math.PI*c1.tf*frame/(double)refresh);
\r
692 col2 = bg_lum*contrast2*Math.sin(2*Math.PI*_xp2/c2.lambda + 2*Math.PI*c2.tf*frame/(double)refresh);
\r
693 img[frame].pix(i,j,new Color(col1+col2+bg_lum));
\r
694 img[frame].alpha(i,j,alpha);
\r
697 //img[frame].cache();
\r
701 ///+ Stimulus drawing function
\r
702 //// A function for stimulus drawing (main body)
\r
704 Canvas display = new Canvas(Canvas.window);
\r
706 //// Declare and initialize local variables
\r
707 int rect_size = 150;
\r
708 double rect_lum = 0.5;
\r
709 double bg_lum = 0.2;
\r
710 double duration = 400;
\r
712 double[] lambda = new double[2], contrast = new double[2], tf = new double[2];
\r
713 double center_orientation = 0.0;
\r
714 Image[,] movie = StaticFunctions.NewArray<Image>(2, 120);
\r
715 Image[,] component_movie = StaticFunctions.NewArray<Image>(4, 120);
\r
716 Image envelope = new Image(), envelope_small = new Image();
\r
718 for(int i=0; i<120; i++)
\r
720 movie[0, i].set(rect_size, rect_size);
\r
721 movie[1, i].set(rect_size, rect_size);
\r
722 component_movie[0, i].set(rect_size/2, rect_size/2);
\r
723 component_movie[1, i].set(rect_size/2, rect_size/2);
\r
724 component_movie[2, i].set(rect_size/2, rect_size/2);
\r
725 component_movie[3, i].set(rect_size/2, rect_size/2);
\r
727 envelope.set(rect_size, rect_size);
\r
728 envelope_small.set(rect_size/2, rect_size/2);
\r
730 Letters let1 = new Letters(), let2 = new Letters(), let3 = new Letters();
\r
731 let1.str = "Component1";
\r
732 let2.str = "Component2";
\r
733 let3.str = "Superposition";
\r
734 let1.centering().shift(-rect_size*1.25, -rect_size);
\r
736 let2.centering().shift(rect_size*1.25, -rect_size);
\r
738 let3.centering().shift(0.0, rect_size*0.75);
\r
741 component c1, c2, c0;
\r
742 c0 = new component{ 0.0,0.0,1.0,1.0 }; //dummy for component movie
\r
744 // Prepare Type-I plaid movie
\r
745 center_orientation = 0.0;
\r
746 orientation_offset = Math.PI/6;
\r
747 contrast[0] = 1.0, contrast[1] = 1.0;
\r
748 lambda[0] = 30.0, lambda[1] = 30.0;
\r
749 tf[0] = 1.0; tf[1] = 1.0;
\r
751 c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};
\r
752 c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};
\r
754 drawgratingmovie(movie[0],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
755 drawgratingmovie(component_movie[0],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
756 drawgratingmovie(component_movie[1],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
760 // Prepare Type-II plaid movie
\r
761 center_orientation = -0.0, orientation_offset = Math.PI/12;
\r
762 contrast[0] = 1.0, contrast[1] = 1.0;
\r
763 lambda[0] = 30.0, lambda[1] = 30.0;
\r
764 tf[0] = 1.0; tf[1] = 4.0;
\r
766 c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};
\r
767 c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};
\r
769 drawgratingmovie(movie[1],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
770 drawgratingmovie(component_movie[2],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
771 drawgratingmovie(component_movie[3],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
775 //draw Gaussian envelopes
\r
776 envelope.clear(new Color(bg_lum)); //clear offscreen image
\r
778 for(int i=0; i<rect_size; i++){
\r
779 _x=i-0.5*rect_size;
\r
780 for(int j=0; j<rect_size; j++){
\r
781 _y=j-0.5*rect_size;
\r
782 envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/6.0, 2.0) ))));
\r
786 envelope_small.clear(new Color(bg_lum)); //clear offscreen image
\r
787 for(int i=0; i<rect_size*0.5; i++){
\r
788 _x=i-0.25*rect_size;
\r
789 for(int j=0; j<rect_size*0.5; j++){
\r
790 _y=j-0.25*rect_size;
\r
791 envelope_small.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/12.0, 2.0) ))));
\r
794 envelope.cache(); //send offscreen image from main memory to GPU
\r
795 envelope_small.cache(); //send offscreen image from main memory to GPU
\r
798 ///+ user interface
\r
799 // Draw user interface
\r
800 Widgets::SelectBox stimulus_type;
\r
801 stimulus_type.area.set(120, 20);
\r
802 stimulus_type.append(L"TypeI");
\r
803 stimulus_type.append(L"TypeII");
\r
804 stimulus_type.centering().shift(-120.0,250.0);
\r
806 Psychlops::Widgets::SelectBox stimulus_type2;
\r
807 stimulus_type2.area.set(120, 20);
\r
808 stimulus_type2.append(L"Continuous");
\r
809 stimulus_type2.append(L"Periodic");
\r
810 stimulus_type2.centering().shift(120.0,250.0);
\r
812 Psychlops::Widgets::Slider duration_slider;
\r
813 duration_slider.area.set(100,20);
\r
814 duration_slider.centering().shift(120,280.0);
\r
815 Interval rng = new Interval();
\r
816 duration_slider.link(duration, 50<=rng<=950, 50.0, 50.0);
\r
817 ///- user interface
\r
822 int period = refresh_int;
\r
824 while(!Keyboard.esc.pushed()) {
\r
825 Display.clear(new Color(bg_lum));
\r
826 movienum = stimulus_type.getSelected(); //if "Type-I" is selected, 0, else frame refresh per sec
\r
829 else period = refresh_int;
\r
832 movie[movienum, frame].centering().draw();
\r
833 envelope.centering().draw();
\r
834 component_movie[movienum*2, frame].centering().shift(-rect_size*0.5, -rect_size).draw();
\r
835 envelope_small.centering().shift(-rect_size*0.5, -rect_size).draw();
\r
836 component_movie[movienum*2+1, frame].centering().shift(rect_size*0.5, -rect_size).draw();
\r
837 envelope_small.centering().shift(rect_size*0.5, -rect_size).draw();
\r
840 ///+ draw user interface
\r
844 stimulus_type.draw();
\r
845 stimulus_type2.draw();
\r
846 if(stimulus_type2.getSelected())duration_slider.draw();
\r
847 ///- draw user interface
\r
849 if(frame++ >= period) frame -= refresh_int;
\r
854 ///- Stimulus drawing function
\r
856 ///+ Main function for demo circumstances
\r
857 public void psychlops_main() {
\r
858 ///+ Demo circumstances
\r
859 //// Spells for run demonstration circumstances
\r
860 Procedure p = new Procedure();
\r
861 //p.setDesign(Procedure::DEMO); //Designate that this is a demo.
\r
862 p.setProcedure(drawplaid); //The argument name is a name of drawing function.
\r
864 ///- Demo circumstances
\r