3 // Zaidi Q, Ennis R, Cao D, Lee B (2012)
\r
4 // Neural locus of color after-image.
\r
5 // Current Biology, 22, 220-224
\r
7 //// Include Psychlops Package
\r
10 namespace PsychlopsSilverlightApp
\r
13 public class PsychlopsMain
\r
18 ///+ Stimulus drawing function
\r
19 //// A function for stimulus drawing (main body)
\r
20 public void psychlops_main() {
\r
23 //// Declare and initialize local variables
\r
24 Canvas cnvs = new Canvas(Canvas.window); //Prepare drawing window
\r
25 double dotsize = 100;
\r
27 double bg_lum = 0.5;
\r
28 double duration = 8.0;
\r
30 bool draw_base_position = false;
\r
32 var fixate = new Rectangle();
\r
33 Image dot = new Image();
\r
34 Color col = new Color();
\r
35 double xp, yp, radius, a;
\r
37 Psychlops.Widgets.Slider hue, value;
\r
40 ///+ set Independent
\r
41 //// set variables and value ranges for interaction
\r
42 Interval rng = new Interval();
\r
43 hue = new Psychlops.Widgets.Slider("Hue", 0.0 <= rng < 360.0, 1, 12);
\r
44 hue.setValue(300.0);
\r
45 value = new Psychlops.Widgets.Slider("Lightness", 0 <= rng <= 1.0, 0.1, 0.05);
\r
46 value.setValue(0.7);
\r
47 ///- set Independent
\r
49 dot.set(dotsize, dotsize);
\r
50 double width = dotsize, height = dotsize, sigma = (width / 6.0);
\r
56 while (!Keyboard.esc.pushed())
\r
61 Psychlops.ColorSpaces.HSV hsv = new Psychlops.ColorSpaces.HSV();
\r
62 hsv.H = Math.mod( hue.getValue(), 360);
\r
64 hsv.V = value.getValue();
\r
67 yp = y - height / 2.0;
\r
68 xp = x - width / 2.0;
\r
69 radius = Math.sqrt(xp * xp + yp * yp);
\r
70 hsv.A = Math.exp(-(radius * radius) / (2.0 * sigma * sigma));
\r
78 if(frame%((int)duration)==0) {
\r
79 stroke++; stroke %= 8;
\r
83 cnvs.clear(new Color(bg_lum)); //Clear window
\r
87 //// Draw dots at a desinated position.
\r
88 for(int i=0; i<8; i++) {
\r
90 dot.centering().shift(dotsize*1.3*Math.cos(i/8.0*2*Math.PI), dotsize*1.3*Math.sin(i/8.0*2*Math.PI)).draw();
\r
95 fixate.centering().draw();
\r
97 cnvs.flip(); // Flip frame buffers
\r
102 ///- Stimulus drawing function
\r
110 // Motion with glass patterns.
\r
111 // Ross, J., Badcock, D. R., and Hayes, A. (2000)
\r
112 // Coherent global motion in the absence of coherent velocity signals.
\r
113 // Current Biology, 10, 679-682.
\r
115 //// Include Psychlops Package
\r
118 namespace PsychlopsSilverlightApp
\r
121 public class PsychlopsMain
\r
123 Psychlops.Widgets.Slider distance, duration, stimulus_type;
\r
126 public void psychlops_main()
\r
131 readonly int DOTNUM = 512;
\r
133 ///+ Stimulus drawing function
\r
134 //// A function for stimulus drawing (main body)
\r
135 void GlassPattern() {
\r
138 //// Declare and initialize local variables
\r
139 Canvas cnvs = new Canvas(400,400); //Prepare drawing window
\r
140 double dotsize = 2;
\r
141 double dot_lum = 1.0;
\r
142 double bg_lum = 0.2;
\r
143 double fieldsize = 300;
\r
144 double[] orientation = new double[DOTNUM];
\r
145 Rectangle dots = new Rectangle(dotsize, dotsize);
\r
146 Ellipse dot = new Ellipse(dotsize*3, dotsize*3);
\r
147 ///+ prepare dots position
\r
148 //// prepare dots position and paired orientation
\r
149 Matrix positionmat = Matrix.gen(DOTNUM,2);
\r
150 //Math.random(positionmat, -0.5*fieldsize, 0.5*fieldsize);
\r
151 positionmat.each( (v) => Math.random(-0.5*fieldsize, 0.5*fieldsize) );
\r
154 for(int i=0; i<DOTNUM; i++){orientation[i] = Math.atan2(positionmat[i+1,2], positionmat[i+1,1]);}
\r
155 ///- prepare dots position
\r
158 ///+ Draw Gaussian Envelope
\r
159 ////Draw offscreen Gaussian Envelope
\r
160 Image envelope = new Image(fieldsize+100, fieldsize+100);
\r
161 envelope.clear(new Color(bg_lum)); //clear offscreen image
\r
163 for(int i=0; i<fieldsize+100; i++){
\r
164 _x=i-0.5*fieldsize-50;
\r
165 for(int j=0; j<fieldsize+100; j++){
\r
166 _y=j-0.5*fieldsize-50;
\r
167 envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*Math.pow(fieldsize/4.0, 2.0) ))));
\r
171 ///- Draw Gaussian Envelope
\r
172 ///+ set Independent
\r
173 //// set variables and value ranges for interaction
\r
174 Interval rng = new Interval();
\r
175 stimulus_type = new Psychlops.Widgets.Slider("Stimulus Type", 0.0 <= rng <= 5.0, 1, 1);
\r
176 stimulus_type.setValue(0);
\r
177 distance = new Psychlops.Widgets.Slider("distance between pairs", 1 <= rng <= 10, 1, 1);
\r
178 distance.setValue(4.0);
\r
179 duration = new Psychlops.Widgets.Slider("Refresh", 0.0 <= rng <= 30.0, 1, 1);
\r
180 duration.setValue(5);
\r
181 ///- set Independent
\r
185 bool draw_base_position = false;
\r
186 Color col = new Color();
\r
189 ///+ initialize position
\r
190 //// Re-randomize position with a desingated interval
\r
191 //Math.random(positionmat, -0.5 * fieldsize, 0.5 * fieldsize);
\r
192 positionmat.each((v) => Math.random(-0.5 * fieldsize, 0.5 * fieldsize));
\r
193 for (int i = 0; i < DOTNUM; i++) { orientation[i] = Math.atan2(positionmat[i + 1, 2], positionmat[i + 1, 1]); }
\r
195 ///- initialize position
\r
197 while (!Keyboard.esc.pushed())
\r
200 if (frame % duration == 0)
\r
202 stroke++; stroke %= 4;
\r
203 if (stroke < 2) col.set(dot_lum);
\r
204 else col.set(1 - dot_lum);
\r
205 draw_base_position = (stroke % 2 == 0);
\r
209 Display.clear(new Color(bg_lum)); //Clear window
\r
211 if ((int)stimulus_type <= 1)
\r
213 for (int i = -10; i < 11; i++)
\r
215 if (stroke % 2 == 0)
\r
216 dot.centering().shift((stimulus_type * 2 - 1) * -distance / 2.0, i * 20);
\r
218 dot.centering().shift((stimulus_type * 2 - 1) * distance / 2.0, i * 20);
\r
223 //// Draw DOTNUM pairs of dots
\r
224 for (int i = 0; i < DOTNUM; i++)
\r
226 ///+ draw first dots
\r
228 ///+ switch stimulus type
\r
229 //// draw the second dots to generate selected stimulu type.
\r
230 switch ((int)stimulus_type)
\r
235 dots.centering().shift(positionmat[i + 1, 1], positionmat[i + 1, 2]); // move to center position
\r
236 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
237 if (draw_base_position) dots.draw(col); // draw first dot
\r
238 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
239 //cnvs.msg("Rotation", cnvs.getCenter().x, cnvs.getHeight() - 20);
\r
242 ///+ case diversion
\r
245 dots.centering().shift(positionmat[i + 1, 1], positionmat[i + 1, 2]);// move to center position
\r
246 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
247 if (draw_base_position) dots.draw(col); // draw first dot
\r
248 dots.shift(distance * Math.cos(orientation[i]), distance * Math.sin(orientation[i]));// move to the second position
\r
250 ///- case diversion
\r
254 dots.centering().shift(positionmat[i + 1, 1], positionmat[i + 1, 2]);// move to center position
\r
255 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
256 if (draw_base_position) dots.draw(col); // draw first dot
\r
257 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
261 ///- switch stimulus type
\r
263 ///- draw first dots
\r
266 ///+ draw second dots
\r
267 if (!draw_base_position) dots.draw(col); // Draw dots at a desinated position.
\r
268 ///- draw second dots
\r
273 envelope.centering().draw();
\r
274 Display.flip(); // Flip frame buffers
\r
285 //Psychlops Code Template
\r
286 // Please visit following web site to get sample codes.
\r
287 // http://psychlops.sourceforge.jp/ja/?StartCode
\r
288 // CodeDresser at following address is also available to view the code.
\r
289 // http://visitope.org/Tools/codedresser.html
\r
291 ///+ 0 Setup Psychlops Circumstances
\r
292 //// 0 Setup Psychlops Circumstances
\r
295 namespace PsychlopsSilverlightApp
\r
298 public class PsychlopsMain
\r
300 // Psychlops Win32 1.5.5 / 20110927
\r
301 ///- 0 Setup Psychlops Circumstances
\r
303 Psychlops.Widgets.Slider SOAFrames, gap, wavelength, contrast;
\r
305 public void psychlops_main() {
\r
307 ///+ 1 Declaration /////////////////////////////////////////////////////////////
\r
309 // declare default window and variables for its parameters
\r
310 Canvas cnvs = new Canvas(600,600, Canvas.window, Display.primary);
\r
311 double CANVAS_FRAMENUM;
\r
312 int CANVAS_REFRESHRATE;
\r
313 Color DEFAULT_BG_COLOR = new Color();
\r
315 int gratingwidth = 500, gratingheight = 100;
\r
317 Color color = new Color(0.0,0.0,0.0);
\r
318 Rectangle grating = new Rectangle();
\r
321 Interval rng = new Interval();
\r
323 //declare local variables around here
\r
325 ///- 1 Declaration /////////////////////////////////////////////////////////////
\r
327 ///+ 2 Initialization //////////////////////////////////////////////////////////
\r
328 //// 2 Initialization
\r
330 // Set initial values for local variables
\r
331 CANVAS_REFRESHRATE = (int)cnvs.getRefreshRate();
\r
332 CANVAS_FRAMENUM = 0;
\r
333 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
336 SOAFrames = new Psychlops.Widgets.Slider("SOA Frames", 1 <=rng<=20 , 1 , 1);
\r
337 SOAFrames.value = 5;
\r
338 gap = new Psychlops.Widgets.Slider("Grating gap" , 0 <=rng<=200 , 1 , 10);
\r
340 wavelength = new Psychlops.Widgets.Slider("Wave Length", 1 <= rng <= 50, 1, 10);
\r
341 wavelength.value = 30.0;
\r
342 contrast = new Psychlops.Widgets.Slider("Contrast" , 0.0<=rng<=1.0 , 0.1 , 0.01);
\r
343 contrast.value = 0.1;
\r
345 // Draw Offline images around here
\r
347 // Offline Movie calculation using Image array around here
\r
349 ///- 2 Initialization //////////////////////////////////////////////////////////
\r
351 ///+ 3 Drawing /////////////////////////////////////////////////////////////////
\r
353 while(!Keyboard.esc.pushed()) {
\r
354 cnvs.clear(DEFAULT_BG_COLOR);
\r
356 //Write draw commands for realtime figure calculation and drawing around here
\r
359 if(Math.mod(CANVAS_FRAMENUM,SOAFrames) == 0){shift += 1;}
\r
361 grating.set(1,gratingheight).centering().shift(-gratingwidth/2, 0);
\r
362 for(int i=0; i<gratingwidth; i++) {
\r
364 + 0.25*contrast*Math.sin(2*Math.PI*(i*2.0/wavelength + 0.50 * shift))
\r
365 + 0.25*contrast*Math.sin(2*Math.PI*(i*3.0/wavelength + 0.75 * shift))
\r
368 grating.shift(1, 0);
\r
369 grating.draw(color);
\r
372 grating.set(1,gratingheight).centering().shift(-gratingwidth/2, -gratingheight-gap);
\r
373 for(int i=0; i<gratingwidth; i++) {
\r
375 + 0.25*contrast*Math.sin(2.0*Math.PI*(i*2.0/wavelength + 0.50 * shift))
\r
378 grating.shift(1,0);
\r
379 grating.draw(color);
\r
382 grating.set(1,gratingheight).centering().shift(-gratingwidth/2, gratingheight+gap);
\r
383 for(int i=0; i<gratingwidth; i++) {
\r
385 + 0.25*contrast*Math.sin(2.0*Math.PI*(i*3.0/wavelength + 0.75 * shift))
\r
388 grating.shift(1,0);
\r
389 grating.draw(color);
\r
395 ///- 3 Drawing /////////////////////////////////////////////////////////////////
\r
407 public void psychlops_main() {
\r
409 Canvas display = new Canvas(768,768);
\r
411 double rect_size = 100;
\r
412 double rect_lum = 0.5;
\r
413 double bg_lum = 0.5;
\r
414 double size = 250.0;
\r
419 int envelopemode = 0;
\r
420 double refresh = display.getRefreshRate();
\r
421 double[] SF=new double[2];
\r
428 double[] initphase = new double[2];
\r
429 double _i, _j, _x, _y, _x2, _y2, col;
\r
430 double amplitude = 1.0;
\r
432 Rectangle fixation1 = new Rectangle(3,9);
\r
433 Rectangle fixation2 = new Rectangle(9,3);
\r
434 fixation1.centering();
\r
435 fixation2.centering();
\r
436 Rectangle contrastrect = new Rectangle();
\r
437 contrastrect.set(760,760);
\r
439 Image envelope = new Image();
\r
440 Psychlops.Color bglum= new Color(0.5,0.5,0.5);
\r
441 Psychlops.Color masklum = new Color(0.5,0.5,0.5,0.5);
\r
443 Interval rng = new Interval();
\r
446 Psychlops.Widgets.Slider TF;
\r
447 TF = new Psychlops.Widgets.Slider("TF", 0.25<=rng<=2.0 , 0.1);
\r
452 Psychlops.Widgets.Slider SFs;
\r
453 SFs = new Psychlops.Widgets.Slider("SF", 4.0<=rng<=16.0 , 4.0);
\r
456 Psychlops.Widgets.Slider contrast;
\r
457 contrast= new Psychlops.Widgets.Slider("Contrast", 0.0<=rng<=1.0 , 0.1);
\r
458 contrast.value = 0.1;
\r
461 var element = StaticFunctions.NewArray<Figures.ShaderGabor>(2);
\r
462 for (int i = 0; i < element.Length; i++){
\r
463 element[i].setSigma(sigma); // set a size of patch as a halfwidth of Gaussian
\r
464 element[i].orientation = Math.PI/4.0+Math.PI/2.0*(1-i);//Math.PI/2*(rand()%2);// //set orientations
\r
470 envelope.set(size, size);
\r
471 envelope.clear(bglum);
\r
473 for(int i=0; i<size; i++){
\r
474 for(int j=0; j<size; j++){
\r
477 _x=_i*Math.cos(-Math.PI/4.0)+_j*Math.sin(-Math.PI/4.0);
\r
478 _y=-_i*Math.sin(-Math.PI/4.0)+_j*Math.cos(-Math.PI/4.0);
\r
479 col=Math.exp(-(_x*_x)/(2*Math.pow(sigma*2/6.0,2.0))-(_y*_y)/(2*Math.pow(sigma*2,2.0)));
\r
480 envelope.alpha(i,j,1.0-col);
\r
486 while(!Keyboard.esc.pushed()) {
\r
487 if(Keyboard.spc.pushed())envelopemode++; envelopemode%=2;
\r
488 Display.clear(bglum);
\r
490 //phase = fmod(phase,60);
\r
492 for(int i=0; i<2; i++) {
\r
493 element[i].phase =(SF[i]/SF[0])*amplitude*
\r
494 Math.PI*Math.sin(Math.PI/2*i+2*Math.PI*phase*TF/refresh);
\r
495 element[i].wavelength = lambda/SF[i];
\r
496 element[i].contrast = contrast;
\r
500 element[0].centering().shift(-size * 0.6, -size * 0.6);
\r
502 element[1].centering().shift(size*0.6,-size*0.6);
\r
504 element[1].centering().shift(-size*0.6,size*0.6);
\r
506 element[0].centering().shift(size*0.6,size*0.6);
\r
510 if(envelopemode>0){
\r
511 envelope.centering().shift(size*0.6,-size*0.6).draw();
\r
512 envelope.centering().shift(-size*0.6,size*0.6).draw();
\r
514 masklum.set(bg_lum, bg_lum, bg_lum, 1-contrast);
\r
515 contrastrect.centering();
\r
516 contrastrect.draw(masklum);
\r
517 fixation1.centering().shift(size*2,0.0);
\r
518 fixation1.draw(Color.red);
\r
519 fixation2.centering().shift(size*2,0.0);
\r
520 fixation2.draw(Color.red);
\r
522 Display.var(Mouse.x, 300, 300);
\r
523 Display.var(Mouse.y, 300, 320);
\r
541 //Position Bias Program
\r
542 namespace PsychlopsSilverlightApp
\r
545 public class PsychlopsMain
\r
548 Image img, img2, img3;
\r
551 Psychlops.Widgets.Slider tfreq;
\r
552 Psychlops.Widgets.Slider contrast;
\r
553 Psychlops.Widgets.Slider lambda;
\r
557 public void psychlops_main()
\r
559 cnvs = new Canvas(300, 600);
\r
560 Interval rng = new Interval();
\r
561 tfreq = new Psychlops.Widgets.Slider("Temporal Frequency(Hz)", -5 <= rng <= 5, 3.0);
\r
562 contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.25);
\r
563 lambda = new Psychlops.Widgets.Slider("Wave Length", 10.0 <= rng <= 120.0, 30);
\r
565 img = new Image(isize * 2, isize * 2);
\r
566 img2 = new Image(isize * 2, isize * 2);
\r
567 img3 = new Image(isize * 2, isize * 2);
\r
569 var gabor1 = StaticFunctions.NewArray<Figures.ShaderGabor>(100);
\r
570 foreach (var g in gabor1)
\r
572 g.setSigma(isize/8).centering().shift(Math.random(300) - 150, Math.random(600) - 300);
\r
573 //g.setSize(isize).centering().shift(Math.random(300) - 150, Math.random(600) - 300);
\r
574 g.orientation = Math.random(2 * Math.PI);
\r
575 //g.orientation2 = Math.random(2 * Math.PI);
\r
580 cnvs.clear(new Color(0.5));
\r
582 Figures.drawGabor(ref img, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);
\r
583 Figures.drawGabor(ref img2, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * -tfreq / 60);
\r
584 Figures.drawGabor(ref img3, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);
\r
587 //img.centering().shift(0, -isize * 1.5).draw();
\r
588 //img2.centering().draw();
\r
589 //img3.centering().shift(0, isize * 1.5).draw();
\r
592 //foreach (var g in gabor1)
\r
593 for (int i = 0; i < gabor1.Length; i++)
\r
595 gabor1[i].wavelength = lambda;
\r
596 gabor1[i].phase = (double)frames * 2.0 * Math.PI * tfreq / 60;
\r
597 gabor1[i].contrast = contrast;
\r
598 //g.wavelength2 = lambda * 2;
\r
599 //g.phase2 = (double)frames * 2.0 * Math.PI * tfreq / 60;
\r
600 //g.contrast2 = contrast / 2;
\r
604 if (!Mouse.left.pressed()) frames++;
\r
614 ///+ Prefix linkto BasicCode1
\r
615 //// Lines for set up Psychlops environment
\r
618 namespace PsychlopsSilverlightApp
\r
621 public class PsychlopsMain
\r
623 ///- Prefix linkto BasicCode1
\r
627 //// Psychlops runs at the first line of this function psychlops_main().
\r
628 public void psychlops_main()
\r
632 ////Prepare global parameters
\r
633 Rectangle p1 = new Rectangle(1,1);
\r
634 Color col1 = new Color();
\r
638 double lmean=0.25, contrast = 0.5;
\r
642 Canvas disp = new Canvas(Canvas.window, Display.secondary);
\r
644 var fieldW_ = Psychlops.Widgets.Browser.Element.byID("fieldW");
\r
645 var fieldH_ = Psychlops.Widgets.Browser.Element.byID("fieldH");
\r
646 var wL_ = Psychlops.Widgets.Browser.Element.byID("wL");
\r
647 var Cont_ = Psychlops.Widgets.Browser.Element.byID("Cont");
\r
648 var ix_ = Psychlops.Widgets.Browser.Element.byID("ix");
\r
649 var iy_ = Psychlops.Widgets.Browser.Element.byID("iy");
\r
650 var gap_ = Psychlops.Widgets.Browser.Element.byID("gap");
\r
655 p1.centering().shift(-width*0.5 + x0, -height*0.5 + y0); //Move a point to the initial position.
\r
659 ////drawing objects
\r
660 for(int i=0; i < width; i++)
\r
662 col1.set(lmean*((contrast*Math.sin((2*Math.PI*i/lambda)))+1)); //Set a color.
\r
664 ///+ 2.1 Drawing a column
\r
665 ////drawing a column
\r
666 for(int j=0;j < height; j++)
\r
669 p1.shift(0, pitch);
\r
671 ///- 2.1 Drawing a column
\r
673 p1.shift(1, -height * pitch); //back to vertical intitial point after drawing one column.
\r
678 while (!Keyboard.spc.pushed()) { }; //Wait until space key is pressed.
\r
690 //// Lines for set up Psychlops environment
\r
693 namespace PsychlopsSilverlightApp
\r
696 public class PsychlopsMain
\r
702 //// Psychlops runs at the first line of this function psychlops_main().
\r
703 public void psychlops_main()
\r
705 Canvas window = new Canvas(300, 300); //Create a window. Here, window variables are preset mode.
\r
707 var FIGURE = Psychlops.Widgets.Browser.Element.byID("FIGURE");
\r
708 var SIZE_X_ = Psychlops.Widgets.Browser.Element.byID("SIZE_X");
\r
709 var SIZE_Y_ = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");
\r
710 var COLOR_R = Psychlops.Widgets.Browser.Element.byID("COLOR_R");
\r
711 var COLOR_G = Psychlops.Widgets.Browser.Element.byID("COLOR_G");
\r
712 var COLOR_B = Psychlops.Widgets.Browser.Element.byID("COLOR_B");
\r
713 var COLOR_BG = Psychlops.Widgets.Browser.Element.byID("COLOR_BG");
\r
714 var Period_Size = Psychlops.Widgets.Browser.Element.byID("Period_Size");
\r
715 var Period_Position = Psychlops.Widgets.Browser.Element.byID("Period_Position");
\r
716 var Speed_HSize_ = Psychlops.Widgets.Browser.Element.byID("Speed_HSize");
\r
717 var Speed_VSize = Psychlops.Widgets.Browser.Element.byID("Speed_VSize");
\r
718 var Speed_VMotion = Psychlops.Widgets.Browser.Element.byID("Speed_VMotion");
\r
719 double SIZE_X = SIZE_X_, SIZE_Y = SIZE_Y_;
\r
722 //// Set a figure size, position and color.
\r
723 Rectangle figure = new Rectangle();
\r
724 Ellipse figure2 = new Ellipse();
\r
725 figure.set(SIZE_X_, SIZE_Y_); // Set the size of figure.
\r
726 figure2.set(SIZE_X_, SIZE_Y_); // Set the size of figure.
\r
727 figure.centering().shift(0, 0); // Move the figure to the starting point.
\r
728 figure2.centering().shift(0, 0); // Move the figure to the starting point.
\r
732 int looming_direction = 1, motion_dir = 1;
\r
733 double direction = 1.0;
\r
734 //looming_direction is a variable for size change.
\r
735 //motion_dir is a variable for motion direction.
\r
736 ///+ 3 Drawing loop
\r
737 //// Draw each frames in a "while loop".
\r
738 while (!Keyboard.esc.pushed())
\r
739 { //exit a program when the escape key is pressed down.
\r
740 window.clear(COLOR_BG); // Clear the window with a designated gray-scale level.
\r
743 //// Calculate object's position and size for each frame.
\r
745 if (frame % Period_Size == 0)
\r
746 { // a direction of size change will reverse at designated frames.
\r
747 looming_direction = looming_direction * -1;
\r
750 if (frame % Period_Position == 0)
\r
751 { // motion direction will reverse at designated frames.
\r
758 //// Settting figure's properties
\r
759 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
760 figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".
\r
761 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
762 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
763 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".
\r
764 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
766 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
767 figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".
\r
768 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
769 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
770 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".
\r
771 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
777 if ("Rectangle".Equals(FIGURE))
\r
779 figure.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.
\r
783 figure2.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.
\r
785 window.flip(); // Reflect the drawing for the display by flipping frame buffers.
\r
789 ////make a step for next frames
\r
793 ///- 3 Drawing loop
\r
806 //The reversed-phi motion.
\r
808 //Phi movement as a subtraction process. Vision Res 10:1411?1430
\r
811 //// Include Psychlops Package
\r
814 namespace PsychlopsSilverlightApp
\r
817 public class PsychlopsMain
\r
822 ///+ Stimulus drawing function
\r
823 //// A function for stimulus drawing (main body)
\r
824 void RectLuminance()
\r
828 //// Declare and initialize local variables
\r
829 double rect_size = 20;
\r
831 double bg_lum = 0.5;
\r
832 double radii = 200;
\r
834 int element_number = 25;
\r
835 int radial_row = 5;
\r
837 double rotation_tf = 0.2;
\r
838 double polarity = 1;
\r
841 double contrastflag = 1;
\r
845 Canvas display = new Canvas(Canvas.window); //Prepare drawing window
\r
846 refresh = Display.getRefreshRate();
\r
848 Ellipse rect = new Ellipse();
\r
849 rect.set(rect_size, rect_size);
\r
851 Ellipse fixation = new Ellipse(5, 5);
\r
852 fixation.centering();
\r
854 Letters let1 = new Letters("Press Space key to change stimulus type");
\r
855 let1.centering().shift(-180, 220);
\r
856 Letters let2 = new Letters("Phi");
\r
857 let2.centering().shift(-10, 200);
\r
858 Letters let3 = new Letters("Reversed-Phi");
\r
859 let3.centering().shift(-60, 200);
\r
861 rotation = Math.random(2 * Math.PI);
\r
863 ///+ user interface
\r
864 ////register variables to demo circumstances
\r
865 Interval rng = new Interval();
\r
867 Psychlops.Widgets.Slider rect_contrast;
\r
868 rect_contrast = new Psychlops.Widgets.Slider("Contrast", 0.1 <= rng <= 1.0, 0.1);
\r
869 rect_contrast.value = 0.5;
\r
870 ///- user interface
\r
876 //AppState::setThreadPriority(AppState::HIGH);
\r
880 if (Keyboard.spc.pushed()) contrastflag = -contrastflag;
\r
881 if (contrastflag < 0) polarity = -polarity;
\r
882 rotation = 2 * Math.PI * rotation_tf * frame * period / refresh;
\r
884 for (int frame_now = 0; frame_now < period; frame_now++)
\r
886 Display.clear(new Color(bg_lum));
\r
887 for (int j = 0; j < radial_row; j++)
\r
889 rect.resize(rect_size * (j + radial_row) / 10.0, rect_size * (j + radial_row) / 10.0);
\r
890 for (double i = 0; i < element_number; i++)
\r
892 rect_lum = bg_lum * (1.0 + polarity * rect_contrast);
\r
893 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
894 rect.draw(rect_lum);
\r
897 fixation.draw(Color.red);
\r
899 if (contrastflag > 0) let2.draw();
\r
905 //AppState::setThreadPriority(AppState::NORMAL);
\r
907 ///- Stimulus drawing function
\r
909 ///+ Main function for demo circumstances
\r
910 //// Psychlops Main function
\r
911 public void psychlops_main()
\r
913 ///+ Demo circumstances
\r
914 //// Spells for run demonstration circumstances
\r
915 Procedure p = new Procedure();
\r
916 //p.setDesign(Procedure::DEMO); //Designate that this is a demo.
\r
917 p.setProcedure(RectLuminance); //The argument name is a name of drawing function.
\r
919 ///- Demo circumstances
\r
921 ///- Main function for demo circumstances
\r
930 //Two types of plaid motion
\r
931 //E. H. Adelson and J. A. Movshon (1982).
\r
932 //Phenomenal coherence of moving visual patterns. Nature 300, 523-525
\r
935 //// Include Psychlops Package
\r
938 namespace PsychlopsSilverlightApp
\r
941 public class PsychlopsMain
\r
946 // Struct for component paremeters
\r
949 public double contrast;
\r
950 public double orientation;
\r
951 public double lambda;
\r
956 ///+ Stimulus drawing function
\r
957 //// A function for stimulus drawing (main body)
\r
958 void drawgratingmovie(Image[] img, component c1, component c2, double contrast, int start, int maxframe, double bg_lum, double alpha)
\r
960 double _xp, _xp2, col1, col2;
\r
961 double contrast1, contrast2;
\r
962 double imageheight, imagewidth;
\r
964 contrast1 = contrast*c1.contrast/(c1.contrast+c2.contrast);
\r
965 contrast2 = contrast*c2.contrast/(c1.contrast+c2.contrast);
\r
967 imageheight = img[0].getHeight();
\r
968 imagewidth = img[0].getWidth();
\r
970 for(int frame=start; frame<start+maxframe+1; frame++){
\r
971 //Display.progressbar(frame, maxframe+1);
\r
972 //img[frame].convert(Image::RGBA);
\r
973 for(int i=0; i<imagewidth; i++){
\r
974 for(int j=0; j<imageheight; j++){
\r
975 _xp = Math.sin(c1.orientation)*(i-imagewidth*0.5) + Math.cos(c1.orientation) * (j-imageheight *0.5);
\r
976 _xp2 = Math.sin(c2.orientation)*(i-imagewidth*0.5) + Math.cos(c2.orientation) * (j-imageheight *0.5);
\r
977 col1 = bg_lum*contrast1*Math.sin(2*Math.PI*_xp/c1.lambda + 2*Math.PI*c1.tf*frame/(double)refresh);
\r
978 col2 = bg_lum*contrast2*Math.sin(2*Math.PI*_xp2/c2.lambda + 2*Math.PI*c2.tf*frame/(double)refresh);
\r
979 img[frame].pix(i,j,new Color(col1+col2+bg_lum));
\r
980 img[frame].alpha(i,j,alpha);
\r
983 //img[frame].cache();
\r
987 ///+ Stimulus drawing function
\r
988 //// A function for stimulus drawing (main body)
\r
990 Canvas display = new Canvas(Canvas.window);
\r
992 //// Declare and initialize local variables
\r
993 int rect_size = 150;
\r
994 double rect_lum = 0.5;
\r
995 double bg_lum = 0.2;
\r
996 double duration = 400;
\r
998 double[] lambda = new double[2], contrast = new double[2], tf = new double[2];
\r
999 double center_orientation = 0.0;
\r
1000 Image[,] movie = StaticFunctions.NewArray<Image>(2, 120);
\r
1001 Image[,] component_movie = StaticFunctions.NewArray<Image>(4, 120);
\r
1002 Image envelope = new Image(), envelope_small = new Image();
\r
1004 for(int i=0; i<120; i++)
\r
1006 movie[0, i].set(rect_size, rect_size);
\r
1007 movie[1, i].set(rect_size, rect_size);
\r
1008 component_movie[0, i].set(rect_size/2, rect_size/2);
\r
1009 component_movie[1, i].set(rect_size/2, rect_size/2);
\r
1010 component_movie[2, i].set(rect_size/2, rect_size/2);
\r
1011 component_movie[3, i].set(rect_size/2, rect_size/2);
\r
1013 envelope.set(rect_size, rect_size);
\r
1014 envelope_small.set(rect_size/2, rect_size/2);
\r
1016 Letters let1 = new Letters(), let2 = new Letters(), let3 = new Letters();
\r
1017 let1.str = "Component1";
\r
1018 let2.str = "Component2";
\r
1019 let3.str = "Superposition";
\r
1020 let1.centering().shift(-rect_size*1.25, -rect_size);
\r
1022 let2.centering().shift(rect_size*1.25, -rect_size);
\r
1024 let3.centering().shift(0.0, rect_size*0.75);
\r
1027 component c1, c2, c0;
\r
1028 c0 = new component{ 0.0,0.0,1.0,1.0 }; //dummy for component movie
\r
1030 // Prepare Type-I plaid movie
\r
1031 center_orientation = 0.0;
\r
1032 orientation_offset = Math.PI/6;
\r
1033 contrast[0] = 1.0, contrast[1] = 1.0;
\r
1034 lambda[0] = 30.0, lambda[1] = 30.0;
\r
1035 tf[0] = 1.0; tf[1] = 1.0;
\r
1037 c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};
\r
1038 c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};
\r
1040 drawgratingmovie(movie[0],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
1041 drawgratingmovie(component_movie[0],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
1042 drawgratingmovie(component_movie[1],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
1046 // Prepare Type-II plaid movie
\r
1047 center_orientation = -0.0, orientation_offset = Math.PI/12;
\r
1048 contrast[0] = 1.0, contrast[1] = 1.0;
\r
1049 lambda[0] = 30.0, lambda[1] = 30.0;
\r
1050 tf[0] = 1.0; tf[1] = 4.0;
\r
1052 c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};
\r
1053 c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};
\r
1055 drawgratingmovie(movie[1],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
1056 drawgratingmovie(component_movie[2],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
1057 drawgratingmovie(component_movie[3],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
1061 //draw Gaussian envelopes
\r
1062 envelope.clear(new Color(bg_lum)); //clear offscreen image
\r
1064 for(int i=0; i<rect_size; i++){
\r
1065 _x=i-0.5*rect_size;
\r
1066 for(int j=0; j<rect_size; j++){
\r
1067 _y=j-0.5*rect_size;
\r
1068 envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/6.0, 2.0) ))));
\r
1072 envelope_small.clear(new Color(bg_lum)); //clear offscreen image
\r
1073 for(int i=0; i<rect_size*0.5; i++){
\r
1074 _x=i-0.25*rect_size;
\r
1075 for(int j=0; j<rect_size*0.5; j++){
\r
1076 _y=j-0.25*rect_size;
\r
1077 envelope_small.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/12.0, 2.0) ))));
\r
1080 envelope.cache(); //send offscreen image from main memory to GPU
\r
1081 envelope_small.cache(); //send offscreen image from main memory to GPU
\r
1084 ///+ user interface
\r
1085 // Draw user interface
\r
1086 Widgets::SelectBox stimulus_type;
\r
1087 stimulus_type.area.set(120, 20);
\r
1088 stimulus_type.append(L"TypeI");
\r
1089 stimulus_type.append(L"TypeII");
\r
1090 stimulus_type.centering().shift(-120.0,250.0);
\r
1092 Psychlops::Widgets::SelectBox stimulus_type2;
\r
1093 stimulus_type2.area.set(120, 20);
\r
1094 stimulus_type2.append(L"Continuous");
\r
1095 stimulus_type2.append(L"Periodic");
\r
1096 stimulus_type2.centering().shift(120.0,250.0);
\r
1098 Psychlops::Widgets::Slider duration_slider;
\r
1099 duration_slider.area.set(100,20);
\r
1100 duration_slider.centering().shift(120,280.0);
\r
1101 Interval rng = new Interval();
\r
1102 duration_slider.link(duration, 50<=rng<=950, 50.0, 50.0);
\r
1103 ///- user interface
\r
1108 int period = refresh_int;
\r
1110 while(!Keyboard.esc.pushed()) {
\r
1111 Display.clear(new Color(bg_lum));
\r
1112 movienum = stimulus_type.getSelected(); //if "Type-I" is selected, 0, else frame refresh per sec
\r
1115 else period = refresh_int;
\r
1118 movie[movienum, frame].centering().draw();
\r
1119 envelope.centering().draw();
\r
1120 component_movie[movienum*2, frame].centering().shift(-rect_size*0.5, -rect_size).draw();
\r
1121 envelope_small.centering().shift(-rect_size*0.5, -rect_size).draw();
\r
1122 component_movie[movienum*2+1, frame].centering().shift(rect_size*0.5, -rect_size).draw();
\r
1123 envelope_small.centering().shift(rect_size*0.5, -rect_size).draw();
\r
1126 ///+ draw user interface
\r
1130 stimulus_type.draw();
\r
1131 stimulus_type2.draw();
\r
1132 if(stimulus_type2.getSelected())duration_slider.draw();
\r
1133 ///- draw user interface
\r
1135 if(frame++ >= period) frame -= refresh_int;
\r
1140 ///- Stimulus drawing function
\r
1142 ///+ Main function for demo circumstances
\r
1143 public void psychlops_main() {
\r
1144 ///+ Demo circumstances
\r
1145 //// Spells for run demonstration circumstances
\r
1146 Procedure p = new Procedure();
\r
1147 //p.setDesign(Procedure::DEMO); //Designate that this is a demo.
\r
1148 p.setProcedure(drawplaid); //The argument name is a name of drawing function.
\r
1150 ///- Demo circumstances
\r