1 // Motion with glass patterns.
\r
2 // Ross, J., Badcock, D. R., and Hayes, A. (2000)
\r
3 // Coherent global motion in the absence of coherent velocity signals.
\r
4 // Current Biology, 10, 679-682.
\r
6 //// Include Psychlops Package
\r
9 namespace PsychlopsSilverlightApp
\r
12 public class PsychlopsMain
\r
14 Psychlops.Widgets.Slider distance, duration, stimulus_type;
\r
17 public void psychlops_main()
\r
22 readonly int DOTNUM = 512;
\r
24 ///+ Stimulus drawing function
\r
25 //// A function for stimulus drawing (main body)
\r
26 void GlassPattern() {
\r
29 //// Declare and initialize local variables
\r
30 Canvas cnvs = new Canvas(400,400); //Prepare drawing window
\r
32 double dot_lum = 0.5;
\r
33 double bg_lum = 0.2;
\r
34 double fieldsize = 300;
\r
35 double[] orientation = new double[DOTNUM];
\r
36 Rectangle dots = new Rectangle(dotsize, dotsize);
\r
37 ///+ prepare dots position
\r
38 //// prepare dots position and paired orientation
\r
39 Matrix positionmat = Matrix.gen(DOTNUM,2);
\r
40 //Math.random(positionmat, -0.5*fieldsize, 0.5*fieldsize);
\r
41 positionmat.each( (v) => Math.random(-0.5*fieldsize, 0.5*fieldsize) );
\r
44 for(int i=0; i<DOTNUM; i++){orientation[i] = Math.atan2(positionmat[i+1,2], positionmat[i+1,1]);}
\r
45 ///- prepare dots position
\r
48 ///+ Draw Gaussian Envelope
\r
49 ////Draw offscreen Gaussian Envelope
\r
50 Image envelope = new Image(fieldsize+100, fieldsize+100);
\r
51 envelope.clear(new Color(bg_lum)); //clear offscreen image
\r
53 for(int i=0; i<fieldsize+100; i++){
\r
54 _x=i-0.5*fieldsize-50;
\r
55 for(int j=0; j<fieldsize+100; j++){
\r
56 _y=j-0.5*fieldsize-50;
\r
57 envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*Math.pow(fieldsize/6.0, 2.0) ))));
\r
61 ///- Draw Gaussian Envelope
\r
62 ///+ set Independent
\r
63 //// set variables and value ranges for interaction
\r
64 Interval rng = new Interval();
\r
65 stimulus_type = new Psychlops.Widgets.Slider("Stimulus Type", 0.0 <= rng <= 2.0, 1, 1);
\r
66 stimulus_type.setValue(0);
\r
67 distance = new Psychlops.Widgets.Slider("distance between pairs", 1 <= rng <= 100, 1, 1);
\r
68 distance.setValue(3.0);
\r
69 duration = new Psychlops.Widgets.Slider("Refresh", 0.0 <= rng <= 10.0, 1, 1);
\r
70 duration.setValue(10);
\r
71 ///- set Independent
\r
74 while(!Keyboard.esc.pushed()) {
\r
75 ///+ position change
\r
76 //// Re-randomize position with a desingated interval
\r
77 if(frame > duration)
\r
79 //Math.random(positionmat, -0.5 * fieldsize, 0.5 * fieldsize);
\r
80 positionmat.each((v) => Math.random(-0.5 * fieldsize, 0.5 * fieldsize));
\r
81 for (int i = 0; i < DOTNUM; i++) { orientation[i] = Math.atan2(positionmat[i + 1, 2], positionmat[i + 1, 1]); }
\r
84 ///- position change
\r
85 Display.clear(new Color(bg_lum)); //Clear window
\r
87 //// Draw DOTNUM pairs of dots
\r
88 for(int i=0; i<DOTNUM; i++){
\r
89 ///+ draw first dots
\r
91 ///+ switch stimulus type
\r
92 //// draw the second dots to generate selected stimulu type.
\r
93 switch((int)stimulus_type){
\r
97 dots.centering().shift(positionmat[i+1,1],positionmat[i+1,2]); // move to center position
\r
98 dots.shift(-0.5*distance*Math.cos(orientation[i]+0.5*Math.PI),-0.5*distance*Math.sin(orientation[i]+0.5*Math.PI));// move to the first position
\r
99 dots.draw(new Color(dot_lum)); // draw first dot
\r
100 dots.shift(distance*Math.cos(orientation[i]+0.5*Math.PI),distance*Math.sin(orientation[i]+0.5*Math.PI));// move to the second position
\r
101 //cnvs.msg("Rotation", cnvs.getCenter().x, cnvs.getHeight() - 20);
\r
104 ///+ case diversion
\r
107 dots.centering().shift(positionmat[i+1,1],positionmat[i+1,2]);// move to center position
\r
108 dots.shift(-0.5*distance*Math.cos(orientation[i]+0.5*Math.PI),-0.5*distance*Math.sin(orientation[i]+0.5*Math.PI));// move to the first position
\r
109 dots.draw(new Color(dot_lum));// draw first dot
\r
110 dots.shift(distance*Math.cos(orientation[i]),distance*Math.sin(orientation[i]));// move to the second position
\r
112 ///- case diversion
\r
116 dots.centering().shift(positionmat[i+1,1],positionmat[i+1,2]);// move to center position
\r
117 dots.shift(-0.5*distance*Math.cos(orientation[i]+0.5*Math.PI),-0.5*distance*Math.sin(orientation[i]+0.5*Math.PI));// move to the first position
\r
118 dots.draw(new Color(dot_lum));// draw first dot
\r
119 dots.shift(distance*Math.cos(orientation[i]+0.25*Math.PI),distance*Math.sin(orientation[i]+0.25*Math.PI));// move to the second position
\r
123 ///- switch stimulus type
\r
125 dots.draw(new Color(dot_lum)); // Draw dots at a desinated position.
\r
128 envelope.centering().draw(); //Draw offscreen Gaussian onto screen
\r
129 Display.flip(); // Flip frame buffers
\r
140 * //Psychlops Code Template
\r
141 // Please visit following web site to get sample codes.
\r
142 // http://psychlops.sourceforge.jp/ja/?StartCode
\r
143 // CodeDresser at following address is also available to view the code.
\r
144 // http://visitope.org/Tools/codedresser.html
\r
146 ///+ 0 Setup Psychlops Circumstances
\r
147 //// 0 Setup Psychlops Circumstances
\r
150 namespace PsychlopsSilverlightApp
\r
153 public class PsychlopsMain
\r
155 // Psychlops Win32 1.5.5 / 20110927
\r
156 ///- 0 Setup Psychlops Circumstances
\r
158 Psychlops.Widgets.Slider SOAFrames, gap, wavelength, contrast;
\r
160 public void psychlops_main() {
\r
162 ///+ 1 Declaration /////////////////////////////////////////////////////////////
\r
164 // declare default window and variables for its parameters
\r
165 Canvas cnvs = new Canvas(900,600, Canvas.window, Display.primary);
\r
166 double CANVAS_FRAMENUM;
\r
167 int CANVAS_REFRESHRATE;
\r
168 Color DEFAULT_BG_COLOR = new Color();
\r
170 int gratingwidth = 500, gratingheight = 100;
\r
172 Color color = new Color(0.0,0.0,0.0);
\r
173 Rectangle grating = new Rectangle();
\r
176 Interval rng = new Interval();
\r
178 //declare local variables around here
\r
180 ///- 1 Declaration /////////////////////////////////////////////////////////////
\r
182 ///+ 2 Initialization //////////////////////////////////////////////////////////
\r
183 //// 2 Initialization
\r
185 // Set initial values for local variables
\r
186 CANVAS_REFRESHRATE = (int)cnvs.getRefreshRate();
\r
187 CANVAS_FRAMENUM = 0;
\r
188 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
191 SOAFrames = new Psychlops.Widgets.Slider("SOA Frames", 1 <=rng<=20 , 1 , 1);
\r
192 SOAFrames.value = 5;
\r
193 gap = new Psychlops.Widgets.Slider("Grating gap" , 0 <=rng<=200 , 1 , 10);
\r
195 wavelength = new Psychlops.Widgets.Slider("Wave Length", 1 <= rng <= 50, 1, 10);
\r
196 wavelength.value = 30.0;
\r
197 contrast = new Psychlops.Widgets.Slider("Contrast" , 0.0<=rng<=1.0 , 0.1 , 0.01);
\r
198 contrast.value = 0.1;
\r
200 // Draw Offline images around here
\r
202 // Offline Movie calculation using Image array around here
\r
204 ///- 2 Initialization //////////////////////////////////////////////////////////
\r
206 ///+ 3 Drawing /////////////////////////////////////////////////////////////////
\r
208 while(!Keyboard.esc.pushed()) {
\r
209 cnvs.clear(DEFAULT_BG_COLOR);
\r
211 //Write draw commands for realtime figure calculation and drawing around here
\r
214 if(Math.mod(CANVAS_FRAMENUM,SOAFrames) == 0){shift += 1;}
\r
216 grating.set(1,gratingheight).centering().shift(-gratingwidth/2, 0);
\r
217 for(int i=0; i<gratingwidth; i++) {
\r
219 + 0.25*contrast*Math.sin(2*Math.PI*(i*2.0/wavelength + 0.50 * shift))
\r
220 + 0.25*contrast*Math.sin(2*Math.PI*(i*3.0/wavelength + 0.75 * shift))
\r
223 grating.shift(1, 0);
\r
224 grating.draw(color);
\r
227 grating.set(1,gratingheight).centering().shift(-gratingwidth/2, -gratingheight-gap);
\r
228 for(int i=0; i<gratingwidth; i++) {
\r
230 + 0.25*contrast*Math.sin(2.0*Math.PI*(i*2.0/wavelength + 0.50 * shift))
\r
233 grating.shift(1,0);
\r
234 grating.draw(color);
\r
237 grating.set(1,gratingheight).centering().shift(-gratingwidth/2, gratingheight+gap);
\r
238 for(int i=0; i<gratingwidth; i++) {
\r
240 + 0.25*contrast*Math.sin(2.0*Math.PI*(i*3.0/wavelength + 0.75 * shift))
\r
243 grating.shift(1,0);
\r
244 grating.draw(color);
\r
250 ///- 3 Drawing /////////////////////////////////////////////////////////////////
\r
262 public void psychlops_main() {
\r
264 Canvas display = new Canvas(768,768);
\r
266 double rect_size = 100;
\r
267 double rect_lum = 0.5;
\r
268 double bg_lum = 0.5;
\r
269 double size = 250.0;
\r
274 int envelopemode = 0;
\r
275 double refresh = display.getRefreshRate();
\r
276 double[] SF=new double[2];
\r
283 double[] initphase = new double[2];
\r
284 double _i, _j, _x, _y, _x2, _y2, col;
\r
285 double amplitude = 1.0;
\r
287 Rectangle fixation1 = new Rectangle(3,9);
\r
288 Rectangle fixation2 = new Rectangle(9,3);
\r
289 fixation1.centering();
\r
290 fixation2.centering();
\r
291 Rectangle contrastrect = new Rectangle();
\r
292 contrastrect.set(760,760);
\r
294 Image envelope = new Image();
\r
295 Psychlops.Color bglum= new Color(0.5,0.5,0.5);
\r
296 Psychlops.Color masklum = new Color(0.5,0.5,0.5,0.5);
\r
298 Interval rng = new Interval();
\r
301 Psychlops.Widgets.Slider TF;
\r
302 TF = new Psychlops.Widgets.Slider("TF", 0.25<=rng<=2.0 , 0.1);
\r
307 Psychlops.Widgets.Slider SFs;
\r
308 SFs = new Psychlops.Widgets.Slider("SF", 4.0<=rng<=16.0 , 4.0);
\r
311 Psychlops.Widgets.Slider contrast;
\r
312 contrast= new Psychlops.Widgets.Slider("Contrast", 0.0<=rng<=1.0 , 0.1);
\r
313 contrast.value = 0.1;
\r
316 var element = StaticFunctions.NewArray<Figures.ShaderGabor>(2);
\r
317 for (int i = 0; i < element.Length; i++){
\r
318 element[i].setSigma(sigma); // set a size of patch as a halfwidth of Gaussian
\r
319 element[i].orientation = Math.PI/4.0+Math.PI/2.0*(1-i);//Math.PI/2*(rand()%2);// //set orientations
\r
325 envelope.set(size, size);
\r
326 envelope.clear(bglum);
\r
328 for(int i=0; i<size; i++){
\r
329 for(int j=0; j<size; j++){
\r
332 _x=_i*Math.cos(-Math.PI/4.0)+_j*Math.sin(-Math.PI/4.0);
\r
333 _y=-_i*Math.sin(-Math.PI/4.0)+_j*Math.cos(-Math.PI/4.0);
\r
334 col=Math.exp(-(_x*_x)/(2*Math.pow(sigma*2/6.0,2.0))-(_y*_y)/(2*Math.pow(sigma*2,2.0)));
\r
335 envelope.alpha(i,j,1.0-col);
\r
341 while(!Keyboard.esc.pushed()) {
\r
342 if(Keyboard.spc.pushed())envelopemode++; envelopemode%=2;
\r
343 Display.clear(bglum);
\r
345 //phase = fmod(phase,60);
\r
347 for(int i=0; i<2; i++) {
\r
348 element[i].phase =(SF[i]/SF[0])*amplitude*
\r
349 Math.PI*Math.sin(Math.PI/2*i+2*Math.PI*phase*TF/refresh);
\r
350 element[i].wavelength = lambda/SF[i];
\r
351 element[i].contrast = contrast;
\r
355 element[0].centering().shift(-size * 0.6, -size * 0.6);
\r
357 element[1].centering().shift(size*0.6,-size*0.6);
\r
359 element[1].centering().shift(-size*0.6,size*0.6);
\r
361 element[0].centering().shift(size*0.6,size*0.6);
\r
365 if(envelopemode>0){
\r
366 envelope.centering().shift(size*0.6,-size*0.6).draw();
\r
367 envelope.centering().shift(-size*0.6,size*0.6).draw();
\r
369 masklum.set(bg_lum, bg_lum, bg_lum, 1-contrast);
\r
370 contrastrect.centering();
\r
371 contrastrect.draw(masklum);
\r
372 fixation1.centering().shift(size*2,0.0);
\r
373 fixation1.draw(Color.red);
\r
374 fixation2.centering().shift(size*2,0.0);
\r
375 fixation2.draw(Color.red);
\r
377 Display.var(Mouse.x, 300, 300);
\r
378 Display.var(Mouse.y, 300, 320);
\r
396 //Position Bias Program
\r
397 namespace PsychlopsSilverlightApp
\r
400 public class PsychlopsMain
\r
403 Image img, img2, img3;
\r
406 Psychlops.Widgets.Slider tfreq;
\r
407 Psychlops.Widgets.Slider contrast;
\r
408 Psychlops.Widgets.Slider lambda;
\r
412 public void psychlops_main()
\r
414 cnvs = new Canvas(300, 600);
\r
415 Interval rng = new Interval();
\r
416 tfreq = new Psychlops.Widgets.Slider("Temporal Frequency(Hz)", -5 <= rng <= 5, 3.0);
\r
417 contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.25);
\r
418 lambda = new Psychlops.Widgets.Slider("Wave Length", 10.0 <= rng <= 120.0, 30);
\r
420 img = new Image(isize * 2, isize * 2);
\r
421 img2 = new Image(isize * 2, isize * 2);
\r
422 img3 = new Image(isize * 2, isize * 2);
\r
424 var gabor1 = StaticFunctions.NewArray<Figures.ShaderGabor>(100);
\r
425 foreach (var g in gabor1)
\r
427 g.setSigma(isize/8).centering().shift(Math.random(300) - 150, Math.random(600) - 300);
\r
428 //g.setSize(isize).centering().shift(Math.random(300) - 150, Math.random(600) - 300);
\r
429 g.orientation = Math.random(2 * Math.PI);
\r
430 //g.orientation2 = Math.random(2 * Math.PI);
\r
435 cnvs.clear(new Color(0.5));
\r
437 Figures.drawGabor(ref img, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);
\r
438 Figures.drawGabor(ref img2, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * -tfreq / 60);
\r
439 Figures.drawGabor(ref img3, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);
\r
442 //img.centering().shift(0, -isize * 1.5).draw();
\r
443 //img2.centering().draw();
\r
444 //img3.centering().shift(0, isize * 1.5).draw();
\r
447 //foreach (var g in gabor1)
\r
448 for (int i = 0; i < gabor1.Length; i++)
\r
450 gabor1[i].wavelength = lambda;
\r
451 gabor1[i].phase = (double)frames * 2.0 * Math.PI * tfreq / 60;
\r
452 gabor1[i].contrast = contrast;
\r
453 //g.wavelength2 = lambda * 2;
\r
454 //g.phase2 = (double)frames * 2.0 * Math.PI * tfreq / 60;
\r
455 //g.contrast2 = contrast / 2;
\r
459 if (!Mouse.left.pressed()) frames++;
\r
469 ///+ Prefix linkto BasicCode1
\r
470 //// Lines for set up Psychlops environment
\r
473 namespace PsychlopsSilverlightApp
\r
476 public class PsychlopsMain
\r
478 ///- Prefix linkto BasicCode1
\r
482 //// Psychlops runs at the first line of this function psychlops_main().
\r
483 public void psychlops_main()
\r
487 ////Prepare global parameters
\r
488 Rectangle p1 = new Rectangle(1,1);
\r
489 Color col1 = new Color();
\r
493 double lmean=0.25, contrast = 0.5;
\r
497 Canvas disp = new Canvas(Canvas.window, Display.secondary);
\r
499 var fieldW_ = Psychlops.Widgets.Browser.Element.byID("fieldW");
\r
500 var fieldH_ = Psychlops.Widgets.Browser.Element.byID("fieldH");
\r
501 var wL_ = Psychlops.Widgets.Browser.Element.byID("wL");
\r
502 var Cont_ = Psychlops.Widgets.Browser.Element.byID("Cont");
\r
503 var ix_ = Psychlops.Widgets.Browser.Element.byID("ix");
\r
504 var iy_ = Psychlops.Widgets.Browser.Element.byID("iy");
\r
505 var gap_ = Psychlops.Widgets.Browser.Element.byID("gap");
\r
510 p1.centering().shift(-width*0.5 + x0, -height*0.5 + y0); //Move a point to the initial position.
\r
514 ////drawing objects
\r
515 for(int i=0; i < width; i++)
\r
517 col1.set(lmean*((contrast*Math.sin((2*Math.PI*i/lambda)))+1)); //Set a color.
\r
519 ///+ 2.1 Drawing a column
\r
520 ////drawing a column
\r
521 for(int j=0;j < height; j++)
\r
524 p1.shift(0, pitch);
\r
526 ///- 2.1 Drawing a column
\r
528 p1.shift(1, -height * pitch); //back to vertical intitial point after drawing one column.
\r
533 while (!Keyboard.spc.pushed()) { }; //Wait until space key is pressed.
\r
545 //// Lines for set up Psychlops environment
\r
548 namespace PsychlopsSilverlightApp
\r
551 public class PsychlopsMain
\r
557 //// Psychlops runs at the first line of this function psychlops_main().
\r
558 public void psychlops_main()
\r
560 Canvas window = new Canvas(300, 300); //Create a window. Here, window variables are preset mode.
\r
562 var FIGURE = Psychlops.Widgets.Browser.Element.byID("FIGURE");
\r
563 var SIZE_X_ = Psychlops.Widgets.Browser.Element.byID("SIZE_X");
\r
564 var SIZE_Y_ = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");
\r
565 var COLOR_R = Psychlops.Widgets.Browser.Element.byID("COLOR_R");
\r
566 var COLOR_G = Psychlops.Widgets.Browser.Element.byID("COLOR_G");
\r
567 var COLOR_B = Psychlops.Widgets.Browser.Element.byID("COLOR_B");
\r
568 var COLOR_BG = Psychlops.Widgets.Browser.Element.byID("COLOR_BG");
\r
569 var Period_Size = Psychlops.Widgets.Browser.Element.byID("Period_Size");
\r
570 var Period_Position = Psychlops.Widgets.Browser.Element.byID("Period_Position");
\r
571 var Speed_HSize_ = Psychlops.Widgets.Browser.Element.byID("Speed_HSize");
\r
572 var Speed_VSize = Psychlops.Widgets.Browser.Element.byID("Speed_VSize");
\r
573 var Speed_VMotion = Psychlops.Widgets.Browser.Element.byID("Speed_VMotion");
\r
574 double SIZE_X = SIZE_X_, SIZE_Y = SIZE_Y_;
\r
577 //// Set a figure size, position and color.
\r
578 Rectangle figure = new Rectangle();
\r
579 Ellipse figure2 = new Ellipse();
\r
580 figure.set(SIZE_X_, SIZE_Y_); // Set the size of figure.
\r
581 figure2.set(SIZE_X_, SIZE_Y_); // Set the size of figure.
\r
582 figure.centering().shift(0, 0); // Move the figure to the starting point.
\r
583 figure2.centering().shift(0, 0); // Move the figure to the starting point.
\r
587 int looming_direction = 1, motion_dir = 1;
\r
588 double direction = 1.0;
\r
589 //looming_direction is a variable for size change.
\r
590 //motion_dir is a variable for motion direction.
\r
591 ///+ 3 Drawing loop
\r
592 //// Draw each frames in a "while loop".
\r
593 while (!Keyboard.esc.pushed())
\r
594 { //exit a program when the escape key is pressed down.
\r
595 window.clear(COLOR_BG); // Clear the window with a designated gray-scale level.
\r
598 //// Calculate object's position and size for each frame.
\r
600 if (frame % Period_Size == 0)
\r
601 { // a direction of size change will reverse at designated frames.
\r
602 looming_direction = looming_direction * -1;
\r
605 if (frame % Period_Position == 0)
\r
606 { // motion direction will reverse at designated frames.
\r
613 //// Settting figure's properties
\r
614 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
615 figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".
\r
616 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
617 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
618 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".
\r
619 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
621 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
622 figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".
\r
623 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
624 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
625 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".
\r
626 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
632 if ("Rectangle".Equals(FIGURE))
\r
634 figure.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.
\r
638 figure2.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.
\r
640 window.flip(); // Reflect the drawing for the display by flipping frame buffers.
\r
644 ////make a step for next frames
\r
648 ///- 3 Drawing loop
\r
661 //The reversed-phi motion.
\r
663 //Phi movement as a subtraction process. Vision Res 10:1411?1430
\r
666 //// Include Psychlops Package
\r
669 namespace PsychlopsSilverlightApp
\r
672 public class PsychlopsMain
\r
677 ///+ Stimulus drawing function
\r
678 //// A function for stimulus drawing (main body)
\r
679 void RectLuminance()
\r
683 //// Declare and initialize local variables
\r
684 double rect_size = 20;
\r
686 double bg_lum = 0.5;
\r
687 double radii = 200;
\r
689 int element_number = 25;
\r
690 int radial_row = 5;
\r
692 double rotation_tf = 0.2;
\r
693 double polarity = 1;
\r
696 double contrastflag = 1;
\r
700 Canvas display = new Canvas(Canvas.window); //Prepare drawing window
\r
701 refresh = Display.getRefreshRate();
\r
703 Ellipse rect = new Ellipse();
\r
704 rect.set(rect_size, rect_size);
\r
706 Ellipse fixation = new Ellipse(5, 5);
\r
707 fixation.centering();
\r
709 Letters let1 = new Letters("Press Space key to change stimulus type");
\r
710 let1.centering().shift(-180, 220);
\r
711 Letters let2 = new Letters("Phi");
\r
712 let2.centering().shift(-10, 200);
\r
713 Letters let3 = new Letters("Reversed-Phi");
\r
714 let3.centering().shift(-60, 200);
\r
716 rotation = Math.random(2 * Math.PI);
\r
718 ///+ user interface
\r
719 ////register variables to demo circumstances
\r
720 Interval rng = new Interval();
\r
722 Psychlops.Widgets.Slider rect_contrast;
\r
723 rect_contrast = new Psychlops.Widgets.Slider("Contrast", 0.1 <= rng <= 1.0, 0.1);
\r
724 rect_contrast.value = 0.5;
\r
725 ///- user interface
\r
731 //AppState::setThreadPriority(AppState::HIGH);
\r
735 if (Keyboard.spc.pushed()) contrastflag = -contrastflag;
\r
736 if (contrastflag < 0) polarity = -polarity;
\r
737 rotation = 2 * Math.PI * rotation_tf * frame * period / refresh;
\r
739 for (int frame_now = 0; frame_now < period; frame_now++)
\r
741 Display.clear(new Color(bg_lum));
\r
742 for (int j = 0; j < radial_row; j++)
\r
744 rect.resize(rect_size * (j + radial_row) / 10.0, rect_size * (j + radial_row) / 10.0);
\r
745 for (double i = 0; i < element_number; i++)
\r
747 rect_lum = bg_lum * (1.0 + polarity * rect_contrast);
\r
748 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
749 rect.draw(rect_lum);
\r
752 fixation.draw(Color.red);
\r
754 if (contrastflag > 0) let2.draw();
\r
760 //AppState::setThreadPriority(AppState::NORMAL);
\r
762 ///- Stimulus drawing function
\r
764 ///+ Main function for demo circumstances
\r
765 //// Psychlops Main function
\r
766 public void psychlops_main()
\r
768 ///+ Demo circumstances
\r
769 //// Spells for run demonstration circumstances
\r
770 Procedure p = new Procedure();
\r
771 //p.setDesign(Procedure::DEMO); //Designate that this is a demo.
\r
772 p.setProcedure(RectLuminance); //The argument name is a name of drawing function.
\r
774 ///- Demo circumstances
\r
776 ///- Main function for demo circumstances
\r
785 //Two types of plaid motion
\r
786 //E. H. Adelson and J. A. Movshon (1982).
\r
787 //Phenomenal coherence of moving visual patterns. Nature 300, 523-525
\r
790 //// Include Psychlops Package
\r
793 namespace PsychlopsSilverlightApp
\r
796 public class PsychlopsMain
\r
801 // Struct for component paremeters
\r
804 public double contrast;
\r
805 public double orientation;
\r
806 public double lambda;
\r
811 ///+ Stimulus drawing function
\r
812 //// A function for stimulus drawing (main body)
\r
813 void drawgratingmovie(Image[] img, component c1, component c2, double contrast, int start, int maxframe, double bg_lum, double alpha)
\r
815 double _xp, _xp2, col1, col2;
\r
816 double contrast1, contrast2;
\r
817 double imageheight, imagewidth;
\r
819 contrast1 = contrast*c1.contrast/(c1.contrast+c2.contrast);
\r
820 contrast2 = contrast*c2.contrast/(c1.contrast+c2.contrast);
\r
822 imageheight = img[0].getHeight();
\r
823 imagewidth = img[0].getWidth();
\r
825 for(int frame=start; frame<start+maxframe+1; frame++){
\r
826 //Display.progressbar(frame, maxframe+1);
\r
827 //img[frame].convert(Image::RGBA);
\r
828 for(int i=0; i<imagewidth; i++){
\r
829 for(int j=0; j<imageheight; j++){
\r
830 _xp = Math.sin(c1.orientation)*(i-imagewidth*0.5) + Math.cos(c1.orientation) * (j-imageheight *0.5);
\r
831 _xp2 = Math.sin(c2.orientation)*(i-imagewidth*0.5) + Math.cos(c2.orientation) * (j-imageheight *0.5);
\r
832 col1 = bg_lum*contrast1*Math.sin(2*Math.PI*_xp/c1.lambda + 2*Math.PI*c1.tf*frame/(double)refresh);
\r
833 col2 = bg_lum*contrast2*Math.sin(2*Math.PI*_xp2/c2.lambda + 2*Math.PI*c2.tf*frame/(double)refresh);
\r
834 img[frame].pix(i,j,new Color(col1+col2+bg_lum));
\r
835 img[frame].alpha(i,j,alpha);
\r
838 //img[frame].cache();
\r
842 ///+ Stimulus drawing function
\r
843 //// A function for stimulus drawing (main body)
\r
845 Canvas display = new Canvas(Canvas.window);
\r
847 //// Declare and initialize local variables
\r
848 int rect_size = 150;
\r
849 double rect_lum = 0.5;
\r
850 double bg_lum = 0.2;
\r
851 double duration = 400;
\r
853 double[] lambda = new double[2], contrast = new double[2], tf = new double[2];
\r
854 double center_orientation = 0.0;
\r
855 Image[,] movie = StaticFunctions.NewArray<Image>(2, 120);
\r
856 Image[,] component_movie = StaticFunctions.NewArray<Image>(4, 120);
\r
857 Image envelope = new Image(), envelope_small = new Image();
\r
859 for(int i=0; i<120; i++)
\r
861 movie[0, i].set(rect_size, rect_size);
\r
862 movie[1, i].set(rect_size, rect_size);
\r
863 component_movie[0, i].set(rect_size/2, rect_size/2);
\r
864 component_movie[1, i].set(rect_size/2, rect_size/2);
\r
865 component_movie[2, i].set(rect_size/2, rect_size/2);
\r
866 component_movie[3, i].set(rect_size/2, rect_size/2);
\r
868 envelope.set(rect_size, rect_size);
\r
869 envelope_small.set(rect_size/2, rect_size/2);
\r
871 Letters let1 = new Letters(), let2 = new Letters(), let3 = new Letters();
\r
872 let1.str = "Component1";
\r
873 let2.str = "Component2";
\r
874 let3.str = "Superposition";
\r
875 let1.centering().shift(-rect_size*1.25, -rect_size);
\r
877 let2.centering().shift(rect_size*1.25, -rect_size);
\r
879 let3.centering().shift(0.0, rect_size*0.75);
\r
882 component c1, c2, c0;
\r
883 c0 = new component{ 0.0,0.0,1.0,1.0 }; //dummy for component movie
\r
885 // Prepare Type-I plaid movie
\r
886 center_orientation = 0.0;
\r
887 orientation_offset = Math.PI/6;
\r
888 contrast[0] = 1.0, contrast[1] = 1.0;
\r
889 lambda[0] = 30.0, lambda[1] = 30.0;
\r
890 tf[0] = 1.0; tf[1] = 1.0;
\r
892 c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};
\r
893 c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};
\r
895 drawgratingmovie(movie[0],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
896 drawgratingmovie(component_movie[0],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
897 drawgratingmovie(component_movie[1],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
901 // Prepare Type-II plaid movie
\r
902 center_orientation = -0.0, orientation_offset = Math.PI/12;
\r
903 contrast[0] = 1.0, contrast[1] = 1.0;
\r
904 lambda[0] = 30.0, lambda[1] = 30.0;
\r
905 tf[0] = 1.0; tf[1] = 4.0;
\r
907 c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};
\r
908 c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};
\r
910 drawgratingmovie(movie[1],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
911 drawgratingmovie(component_movie[2],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
912 drawgratingmovie(component_movie[3],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
916 //draw Gaussian envelopes
\r
917 envelope.clear(new Color(bg_lum)); //clear offscreen image
\r
919 for(int i=0; i<rect_size; i++){
\r
920 _x=i-0.5*rect_size;
\r
921 for(int j=0; j<rect_size; j++){
\r
922 _y=j-0.5*rect_size;
\r
923 envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/6.0, 2.0) ))));
\r
927 envelope_small.clear(new Color(bg_lum)); //clear offscreen image
\r
928 for(int i=0; i<rect_size*0.5; i++){
\r
929 _x=i-0.25*rect_size;
\r
930 for(int j=0; j<rect_size*0.5; j++){
\r
931 _y=j-0.25*rect_size;
\r
932 envelope_small.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/12.0, 2.0) ))));
\r
935 envelope.cache(); //send offscreen image from main memory to GPU
\r
936 envelope_small.cache(); //send offscreen image from main memory to GPU
\r
939 ///+ user interface
\r
940 // Draw user interface
\r
941 Widgets::SelectBox stimulus_type;
\r
942 stimulus_type.area.set(120, 20);
\r
943 stimulus_type.append(L"TypeI");
\r
944 stimulus_type.append(L"TypeII");
\r
945 stimulus_type.centering().shift(-120.0,250.0);
\r
947 Psychlops::Widgets::SelectBox stimulus_type2;
\r
948 stimulus_type2.area.set(120, 20);
\r
949 stimulus_type2.append(L"Continuous");
\r
950 stimulus_type2.append(L"Periodic");
\r
951 stimulus_type2.centering().shift(120.0,250.0);
\r
953 Psychlops::Widgets::Slider duration_slider;
\r
954 duration_slider.area.set(100,20);
\r
955 duration_slider.centering().shift(120,280.0);
\r
956 Interval rng = new Interval();
\r
957 duration_slider.link(duration, 50<=rng<=950, 50.0, 50.0);
\r
958 ///- user interface
\r
963 int period = refresh_int;
\r
965 while(!Keyboard.esc.pushed()) {
\r
966 Display.clear(new Color(bg_lum));
\r
967 movienum = stimulus_type.getSelected(); //if "Type-I" is selected, 0, else frame refresh per sec
\r
970 else period = refresh_int;
\r
973 movie[movienum, frame].centering().draw();
\r
974 envelope.centering().draw();
\r
975 component_movie[movienum*2, frame].centering().shift(-rect_size*0.5, -rect_size).draw();
\r
976 envelope_small.centering().shift(-rect_size*0.5, -rect_size).draw();
\r
977 component_movie[movienum*2+1, frame].centering().shift(rect_size*0.5, -rect_size).draw();
\r
978 envelope_small.centering().shift(rect_size*0.5, -rect_size).draw();
\r
981 ///+ draw user interface
\r
985 stimulus_type.draw();
\r
986 stimulus_type2.draw();
\r
987 if(stimulus_type2.getSelected())duration_slider.draw();
\r
988 ///- draw user interface
\r
990 if(frame++ >= period) frame -= refresh_int;
\r
995 ///- Stimulus drawing function
\r
997 ///+ Main function for demo circumstances
\r
998 public void psychlops_main() {
\r
999 ///+ Demo circumstances
\r
1000 //// Spells for run demonstration circumstances
\r
1001 Procedure p = new Procedure();
\r
1002 //p.setDesign(Procedure::DEMO); //Designate that this is a demo.
\r
1003 p.setProcedure(drawplaid); //The argument name is a name of drawing function.
\r
1005 ///- Demo circumstances
\r