2 ///+ Prefix linkto BasicCode1
\r
3 //// Lines for set up Psychlops environment
\r
6 namespace PsychlopsSilverlightApp
\r
9 public class PsychlopsMain
\r
11 ///- Prefix linkto BasicCode1
\r
15 //// Psychlops runs at the first line of this function psychlops_main().
\r
16 public void psychlops_main()
\r
20 ////Prepare global parameters
\r
21 Rectangle p1 = new Rectangle(1,1);
\r
22 Color col1 = new Color();
\r
26 double lmean=0.25, contrast = 0.5;
\r
30 Canvas disp = new Canvas(Canvas.window, Display.secondary);
\r
32 var fieldW_ = Psychlops.Widgets.Browser.Element.byID("fieldW");
\r
33 var fieldH_ = Psychlops.Widgets.Browser.Element.byID("fieldH");
\r
34 var wL_ = Psychlops.Widgets.Browser.Element.byID("wL");
\r
35 var Cont_ = Psychlops.Widgets.Browser.Element.byID("Cont");
\r
36 var ix_ = Psychlops.Widgets.Browser.Element.byID("ix");
\r
37 var iy_ = Psychlops.Widgets.Browser.Element.byID("iy");
\r
38 var gap_ = Psychlops.Widgets.Browser.Element.byID("gap");
\r
43 p1.centering().shift(-width*0.5 + x0, -height*0.5 + y0); //Move a point to the initial position.
\r
48 for(int i=0; i < width; i++)
\r
50 col1.set(lmean*((contrast*Math.sin((2*Math.PI*i/lambda)))+1)); //Set a color.
\r
52 ///+ 2.1 Drawing a column
\r
53 ////drawing a column
\r
54 for(int j=0;j < height; j++)
\r
59 ///- 2.1 Drawing a column
\r
61 p1.shift(1, -height * pitch); //back to vertical intitial point after drawing one column.
\r
66 while (!Keyboard.spc.pushed()) { }; //Wait until space key is pressed.
\r
78 //// Lines for set up Psychlops environment
\r
81 namespace PsychlopsSilverlightApp
\r
84 public class PsychlopsMain
\r
90 //// Psychlops runs at the first line of this function psychlops_main().
\r
91 public void psychlops_main()
\r
93 Canvas window = new Canvas(300, 300); //Create a window. Here, window variables are preset mode.
\r
95 var FIGURE = Psychlops.Widgets.Browser.Element.byID("FIGURE");
\r
96 var SIZE_X_ = Psychlops.Widgets.Browser.Element.byID("SIZE_X");
\r
97 var SIZE_Y_ = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");
\r
98 var COLOR_R = Psychlops.Widgets.Browser.Element.byID("COLOR_R");
\r
99 var COLOR_G = Psychlops.Widgets.Browser.Element.byID("COLOR_G");
\r
100 var COLOR_B = Psychlops.Widgets.Browser.Element.byID("COLOR_B");
\r
101 var COLOR_BG = Psychlops.Widgets.Browser.Element.byID("COLOR_BG");
\r
102 var Period_Size = Psychlops.Widgets.Browser.Element.byID("Period_Size");
\r
103 var Period_Position = Psychlops.Widgets.Browser.Element.byID("Period_Position");
\r
104 var Speed_HSize_ = Psychlops.Widgets.Browser.Element.byID("Speed_HSize");
\r
105 var Speed_VSize = Psychlops.Widgets.Browser.Element.byID("Speed_VSize");
\r
106 var Speed_VMotion = Psychlops.Widgets.Browser.Element.byID("Speed_VMotion");
\r
107 double SIZE_X = SIZE_X_, SIZE_Y = SIZE_Y_;
\r
110 //// Set a figure size, position and color.
\r
111 Rectangle figure = new Rectangle();
\r
112 Ellipse figure2 = new Ellipse();
\r
113 figure.set(SIZE_X_, SIZE_Y_); // Set the size of figure.
\r
114 figure2.set(SIZE_X_, SIZE_Y_); // Set the size of figure.
\r
115 figure.centering().shift(0, 0); // Move the figure to the starting point.
\r
116 figure2.centering().shift(0, 0); // Move the figure to the starting point.
\r
120 int looming_direction = 1, motion_dir = 1;
\r
121 double direction = 1.0;
\r
122 //looming_direction is a variable for size change.
\r
123 //motion_dir is a variable for motion direction.
\r
124 ///+ 3 Drawing loop
\r
125 //// Draw each frames in a "while loop".
\r
126 while (!Keyboard.esc.pushed())
\r
127 { //exit a program when the escape key is pressed down.
\r
128 window.clear(COLOR_BG); // Clear the window with a designated gray-scale level.
\r
131 //// Calculate object's position and size for each frame.
\r
133 if (frame % Period_Size == 0)
\r
134 { // a direction of size change will reverse at designated frames.
\r
135 looming_direction = looming_direction * -1;
\r
138 if (frame % Period_Position == 0)
\r
139 { // motion direction will reverse at designated frames.
\r
146 //// Settting figure's properties
\r
147 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
148 figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".
\r
149 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
150 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
151 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".
\r
152 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
154 figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
155 figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".
\r
156 figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
157 figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".
\r
158 figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".
\r
159 figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir".
\r
165 if ("Rectangle".Equals(FIGURE))
\r
167 figure.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.
\r
171 figure2.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.
\r
173 window.flip(); // Reflect the drawing for the display by flipping frame buffers.
\r
177 ////make a step for next frames
\r
181 ///- 3 Drawing loop
\r
194 //The reversed-phi motion.
\r
196 //Phi movement as a subtraction process. Vision Res 10:1411?1430
\r
199 //// Include Psychlops Package
\r
202 namespace PsychlopsSilverlightApp
\r
205 public class PsychlopsMain
\r
210 ///+ Stimulus drawing function
\r
211 //// A function for stimulus drawing (main body)
\r
212 void RectLuminance()
\r
216 //// Declare and initialize local variables
\r
217 double rect_size = 20;
\r
219 double bg_lum = 0.5;
\r
220 double radii = 200;
\r
222 int element_number = 25;
\r
223 int radial_row = 5;
\r
225 double rotation_tf = 0.2;
\r
226 double polarity = 1;
\r
229 double contrastflag = 1;
\r
233 Canvas display = new Canvas(Canvas.window); //Prepare drawing window
\r
234 refresh = Display.getRefreshRate();
\r
236 Ellipse rect = new Ellipse();
\r
237 rect.set(rect_size, rect_size);
\r
239 Ellipse fixation = new Ellipse(5, 5);
\r
240 fixation.centering();
\r
242 Letters let1 = new Letters("Press Space key to change stimulus type");
\r
243 let1.centering().shift(-180, 220);
\r
244 Letters let2 = new Letters("Phi");
\r
245 let2.centering().shift(-10, 200);
\r
246 Letters let3 = new Letters("Reversed-Phi");
\r
247 let3.centering().shift(-60, 200);
\r
249 rotation = Math.random(2 * Math.PI);
\r
251 ///+ user interface
\r
252 ////register variables to demo circumstances
\r
253 Interval rng = new Interval();
\r
255 Psychlops.Widgets.Slider rect_contrast;
\r
256 rect_contrast = new Psychlops.Widgets.Slider("Contrast", 0.1 <= rng <= 1.0, 0.1);
\r
257 rect_contrast.value = 0.5;
\r
258 ///- user interface
\r
264 //AppState::setThreadPriority(AppState::HIGH);
\r
268 if (Keyboard.spc.pushed()) contrastflag = -contrastflag;
\r
269 if (contrastflag < 0) polarity = -polarity;
\r
270 rotation = 2 * Math.PI * rotation_tf * frame * period / refresh;
\r
272 for (int frame_now = 0; frame_now < period; frame_now++)
\r
274 Display.clear(new Color(bg_lum));
\r
275 for (int j = 0; j < radial_row; j++)
\r
277 rect.resize(rect_size * (j + radial_row) / 10.0, rect_size * (j + radial_row) / 10.0);
\r
278 for (double i = 0; i < element_number; i++)
\r
280 rect_lum = bg_lum * (1.0 + polarity * rect_contrast);
\r
281 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
282 rect.draw(rect_lum);
\r
285 fixation.draw(Color.red);
\r
287 if (contrastflag > 0) let2.draw();
\r
293 //AppState::setThreadPriority(AppState::NORMAL);
\r
295 ///- Stimulus drawing function
\r
297 ///+ Main function for demo circumstances
\r
298 //// Psychlops Main function
\r
299 public void psychlops_main()
\r
301 ///+ Demo circumstances
\r
302 //// Spells for run demonstration circumstances
\r
303 Procedure p = new Procedure();
\r
304 //p.setDesign(Procedure::DEMO); //Designate that this is a demo.
\r
305 p.setProcedure(RectLuminance); //The argument name is a name of drawing function.
\r
307 ///- Demo circumstances
\r
309 ///- Main function for demo circumstances
\r
318 //Two types of plaid motion
\r
319 //E. H. Adelson and J. A. Movshon (1982).
\r
320 //Phenomenal coherence of moving visual patterns. Nature 300, 523-525
\r
323 //// Include Psychlops Package
\r
326 namespace PsychlopsSilverlightApp
\r
329 public class PsychlopsMain
\r
334 // Struct for component paremeters
\r
337 public double contrast;
\r
338 public double orientation;
\r
339 public double lambda;
\r
344 ///+ Stimulus drawing function
\r
345 //// A function for stimulus drawing (main body)
\r
346 void drawgratingmovie(Image[] img, component c1, component c2, double contrast, int start, int maxframe, double bg_lum, double alpha)
\r
348 double _xp, _xp2, col1, col2;
\r
349 double contrast1, contrast2;
\r
350 double imageheight, imagewidth;
\r
352 contrast1 = contrast*c1.contrast/(c1.contrast+c2.contrast);
\r
353 contrast2 = contrast*c2.contrast/(c1.contrast+c2.contrast);
\r
355 imageheight = img[0].getHeight();
\r
356 imagewidth = img[0].getWidth();
\r
358 for(int frame=start; frame<start+maxframe+1; frame++){
\r
359 //Display.progressbar(frame, maxframe+1);
\r
360 //img[frame].convert(Image::RGBA);
\r
361 for(int i=0; i<imagewidth; i++){
\r
362 for(int j=0; j<imageheight; j++){
\r
363 _xp = Math.sin(c1.orientation)*(i-imagewidth*0.5) + Math.cos(c1.orientation) * (j-imageheight *0.5);
\r
364 _xp2 = Math.sin(c2.orientation)*(i-imagewidth*0.5) + Math.cos(c2.orientation) * (j-imageheight *0.5);
\r
365 col1 = bg_lum*contrast1*Math.sin(2*Math.PI*_xp/c1.lambda + 2*Math.PI*c1.tf*frame/(double)refresh);
\r
366 col2 = bg_lum*contrast2*Math.sin(2*Math.PI*_xp2/c2.lambda + 2*Math.PI*c2.tf*frame/(double)refresh);
\r
367 img[frame].pix(i,j,new Color(col1+col2+bg_lum));
\r
368 img[frame].alpha(i,j,alpha);
\r
371 //img[frame].cache();
\r
375 ///+ Stimulus drawing function
\r
376 //// A function for stimulus drawing (main body)
\r
378 Canvas display = new Canvas(Canvas.window);
\r
380 //// Declare and initialize local variables
\r
381 int rect_size = 150;
\r
382 double rect_lum = 0.5;
\r
383 double bg_lum = 0.2;
\r
384 double duration = 400;
\r
386 double[] lambda = new double[2], contrast = new double[2], tf = new double[2];
\r
387 double center_orientation = 0.0;
\r
388 Image[,] movie = StaticFunctions.NewArray<Image>(2, 120);
\r
389 Image[,] component_movie = StaticFunctions.NewArray<Image>(4, 120);
\r
390 Image envelope = new Image(), envelope_small = new Image();
\r
392 for(int i=0; i<120; i++)
\r
394 movie[0, i].set(rect_size, rect_size);
\r
395 movie[1, i].set(rect_size, rect_size);
\r
396 component_movie[0, i].set(rect_size/2, rect_size/2);
\r
397 component_movie[1, i].set(rect_size/2, rect_size/2);
\r
398 component_movie[2, i].set(rect_size/2, rect_size/2);
\r
399 component_movie[3, i].set(rect_size/2, rect_size/2);
\r
401 envelope.set(rect_size, rect_size);
\r
402 envelope_small.set(rect_size/2, rect_size/2);
\r
404 Letters let1 = new Letters(), let2 = new Letters(), let3 = new Letters();
\r
405 let1.str = "Component1";
\r
406 let2.str = "Component2";
\r
407 let3.str = "Superposition";
\r
408 let1.centering().shift(-rect_size*1.25, -rect_size);
\r
410 let2.centering().shift(rect_size*1.25, -rect_size);
\r
412 let3.centering().shift(0.0, rect_size*0.75);
\r
415 component c1, c2, c0;
\r
416 c0 = new component{ 0.0,0.0,1.0,1.0 }; //dummy for component movie
\r
418 // Prepare Type-I plaid movie
\r
419 center_orientation = 0.0;
\r
420 orientation_offset = Math.PI/6;
\r
421 contrast[0] = 1.0, contrast[1] = 1.0;
\r
422 lambda[0] = 30.0, lambda[1] = 30.0;
\r
423 tf[0] = 1.0; tf[1] = 1.0;
\r
425 c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};
\r
426 c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};
\r
428 drawgratingmovie(movie[0],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
429 drawgratingmovie(component_movie[0],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
430 drawgratingmovie(component_movie[1],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
434 // Prepare Type-II plaid movie
\r
435 center_orientation = -0.0, orientation_offset = Math.PI/12;
\r
436 contrast[0] = 1.0, contrast[1] = 1.0;
\r
437 lambda[0] = 30.0, lambda[1] = 30.0;
\r
438 tf[0] = 1.0; tf[1] = 4.0;
\r
440 c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};
\r
441 c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};
\r
443 drawgratingmovie(movie[1],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
444 drawgratingmovie(component_movie[2],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
445 drawgratingmovie(component_movie[3],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);
\r
449 //draw Gaussian envelopes
\r
450 envelope.clear(new Color(bg_lum)); //clear offscreen image
\r
452 for(int i=0; i<rect_size; i++){
\r
453 _x=i-0.5*rect_size;
\r
454 for(int j=0; j<rect_size; j++){
\r
455 _y=j-0.5*rect_size;
\r
456 envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/6.0, 2.0) ))));
\r
460 envelope_small.clear(new Color(bg_lum)); //clear offscreen image
\r
461 for(int i=0; i<rect_size*0.5; i++){
\r
462 _x=i-0.25*rect_size;
\r
463 for(int j=0; j<rect_size*0.5; j++){
\r
464 _y=j-0.25*rect_size;
\r
465 envelope_small.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/12.0, 2.0) ))));
\r
468 envelope.cache(); //send offscreen image from main memory to GPU
\r
469 envelope_small.cache(); //send offscreen image from main memory to GPU
\r
472 ///+ user interface
\r
473 // Draw user interface
\r
474 Widgets::SelectBox stimulus_type;
\r
475 stimulus_type.area.set(120, 20);
\r
476 stimulus_type.append(L"TypeI");
\r
477 stimulus_type.append(L"TypeII");
\r
478 stimulus_type.centering().shift(-120.0,250.0);
\r
480 Psychlops::Widgets::SelectBox stimulus_type2;
\r
481 stimulus_type2.area.set(120, 20);
\r
482 stimulus_type2.append(L"Continuous");
\r
483 stimulus_type2.append(L"Periodic");
\r
484 stimulus_type2.centering().shift(120.0,250.0);
\r
486 Psychlops::Widgets::Slider duration_slider;
\r
487 duration_slider.area.set(100,20);
\r
488 duration_slider.centering().shift(120,280.0);
\r
489 Interval rng = new Interval();
\r
490 duration_slider.link(duration, 50<=rng<=950, 50.0, 50.0);
\r
491 ///- user interface
\r
496 int period = refresh_int;
\r
498 while(!Keyboard.esc.pushed()) {
\r
499 Display.clear(new Color(bg_lum));
\r
500 movienum = stimulus_type.getSelected(); //if "Type-I" is selected, 0, else frame refresh per sec
\r
503 else period = refresh_int;
\r
506 movie[movienum, frame].centering().draw();
\r
507 envelope.centering().draw();
\r
508 component_movie[movienum*2, frame].centering().shift(-rect_size*0.5, -rect_size).draw();
\r
509 envelope_small.centering().shift(-rect_size*0.5, -rect_size).draw();
\r
510 component_movie[movienum*2+1, frame].centering().shift(rect_size*0.5, -rect_size).draw();
\r
511 envelope_small.centering().shift(rect_size*0.5, -rect_size).draw();
\r
514 ///+ draw user interface
\r
518 stimulus_type.draw();
\r
519 stimulus_type2.draw();
\r
520 if(stimulus_type2.getSelected())duration_slider.draw();
\r
521 ///- draw user interface
\r
523 if(frame++ >= period) frame -= refresh_int;
\r
528 ///- Stimulus drawing function
\r
530 ///+ Main function for demo circumstances
\r
531 public void psychlops_main() {
\r
532 ///+ Demo circumstances
\r
533 //// Spells for run demonstration circumstances
\r
534 Procedure p = new Procedure();
\r
535 //p.setDesign(Procedure::DEMO); //Designate that this is a demo.
\r
536 p.setProcedure(drawplaid); //The argument name is a name of drawing function.
\r
538 ///- Demo circumstances
\r
547 //Position Bias Program
\r
548 namespace PsychlopsSilverlightApp
\r
551 public class PsychlopsMain
\r
554 Image img, img2, img3;
\r
557 Psychlops.Widgets.Slider tfreq;
\r
558 Psychlops.Widgets.Slider contrast;
\r
559 Psychlops.Widgets.Slider lambda;
\r
563 public void psychlops_main()
\r
565 cnvs = new Canvas(300, 600);
\r
566 Interval rng = new Interval();
\r
567 tfreq = new Psychlops.Widgets.Slider("Temporal Frequency(Hz)", -5 <= rng <= 5, 3.0);
\r
568 contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.25);
\r
569 lambda = new Psychlops.Widgets.Slider("Wave Length", 10.0 <= rng <= 120.0, 30);
\r
571 img = new Image(isize * 2, isize * 2);
\r
572 img2 = new Image(isize * 2, isize * 2);
\r
573 img3 = new Image(isize * 2, isize * 2);
\r
576 var gabor1 = StaticFunctions.NewArray<Figures.ShaderGabor>(100);
\r
578 var gabor1 = StaticFunctions.NewArray<Figures.ShaderGaborAlpha>(100);
\r
579 >>>>>>> remotes/psychlopssilverlight/master
580 foreach(var g in gabor1)
\r
582 g.setSigma(isize / 8).centering().shift(Math.random(300) - 150, Math.random(600) - 300);
\r
583 g.orientation = Math.random(2*Math.PI);
\r
588 cnvs.clear(new Color(0.5));
\r
590 Figures.drawGabor(ref img, isize / 8, 1/lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);
\r
591 Figures.drawGabor(ref img2, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * -tfreq / 60);
\r
592 Figures.drawGabor(ref img3, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);
\r
595 //img.centering().shift(0, -isize * 1.5).draw();
\r
596 //img2.centering().draw();
\r
597 //img3.centering().shift(0, isize * 1.5).draw();
\r
600 foreach (var g in gabor1)
\r
602 g.wavelength = lambda;
\r
603 g.phase = (double)frames * 2.0 * Math.PI * tfreq / 60;
\r
604 g.contrast = contrast;
\r
608 if (!Mouse.left.pressed()) frames++;
\r