-\r
-///+ Prefix linkto BasicCode1\r
-//// Lines for set up Psychlops environment\r
+//Two types of plaid motion\r
+//E. H. Adelson and J. A. Movshon (1982).\r
+//Phenomenal coherence of moving visual patterns. Nature 300, 523-525\r
+\r
+///+ Prefix\r
+//// Include Psychlops Package\r
using Psychlops;\r
\r
-namespace PsychlopsSilverlightApp\r
-{\r
+ namespace PsychlopsSilverlightApp\r
+ {\r
\r
- public class PsychlopsMain\r
- {///- Prefix linkto BasicCode1\r
+ public class PsychlopsMain\r
+ {\r
+ ///- Prefix\r
\r
+ ///+ Global\r
+ // Struct for component paremeters\r
+ struct component\r
+ {\r
+ public double contrast;\r
+ public double orientation;\r
+ public double lambda;\r
+ public double tf;\r
+ }\r
+ ///- Global\r
\r
- ///+ Main Routine\r
- //// Psychlops runs at the first line of this function psychlops_main().\r
- public void psychlops_main()\r
- {\r
- ///+ 0 Declaration\r
- ////Prepare global parameters\r
- Canvas window = new Canvas(Canvas.window);\r
- Image img;\r
- Rectangle centerrect = new Rectangle(10, 10);\r
- int imageHsize = 100;\r
- int imageVsize = 60;\r
- double R, G, B;\r
- ///- 0 Declaration\r
-\r
-\r
-\r
- ///+ 1 Initialize\r
- ////Initialize image and set color to each pixel.\r
- img = new Image(imageHsize, imageVsize); //Allocate offscreen in main memory.\r
- Color col = new Color(0,0,0);\r
- for (int i = 0; i < imageHsize; i++)\r
+ ///+ Stimulus drawing function\r
+ //// A function for stimulus drawing (main body)\r
+ void drawgratingmovie(Image[] img, component c1, component c2, double contrast, int start, int maxframe, double bg_lum, double alpha)\r
{\r
- for (int j = 0; j < imageVsize; j++)\r
+ double _xp, _xp2, col1, col2;\r
+ double contrast1, contrast2;\r
+ double imageheight, imagewidth;\r
+\r
+ contrast1 = contrast*c1.contrast/(c1.contrast+c2.contrast);\r
+ contrast2 = contrast*c2.contrast/(c1.contrast+c2.contrast);\r
+\r
+ imageheight = img[0].getHeight();\r
+ imagewidth = img[0].getWidth();\r
+\r
+ for(int frame=start; frame<start+maxframe+1; frame++){\r
+ //Display.progressbar(frame, maxframe+1);\r
+ //img[frame].convert(Image::RGBA);\r
+ for(int i=0; i<imagewidth; i++){\r
+ for(int j=0; j<imageheight; j++){\r
+ _xp = Math.sin(c1.orientation)*(i-imagewidth*0.5) + Math.cos(c1.orientation) * (j-imageheight *0.5);\r
+ _xp2 = Math.sin(c2.orientation)*(i-imagewidth*0.5) + Math.cos(c2.orientation) * (j-imageheight *0.5);\r
+ col1 = bg_lum*contrast1*Math.sin(2*Math.PI*_xp/c1.lambda + 2*Math.PI*c1.tf*frame/(double)refresh);\r
+ col2 = bg_lum*contrast2*Math.sin(2*Math.PI*_xp2/c2.lambda + 2*Math.PI*c2.tf*frame/(double)refresh);\r
+ img[frame].pix(i,j,new Color(col1+col2+bg_lum));\r
+ img[frame].alpha(i,j,alpha);\r
+ }\r
+ }\r
+ //img[frame].cache();\r
+ }\r
+ }\r
+\r
+ ///+ Stimulus drawing function\r
+ //// A function for stimulus drawing (main body)\r
+ void drawplaid() {\r
+ Canvas display = new Canvas(Canvas.window);\r
+ ///+ Preperation\r
+ //// Declare and initialize local variables\r
+ int rect_size = 150;\r
+ double rect_lum = 0.5;\r
+ double bg_lum = 0.2;\r
+ double duration = 400;\r
+\r
+ double[] lambda = new double[2], contrast = new double[2], tf = new double[2];\r
+ double center_orientation = 0.0;\r
+ Image[,] movie = StaticFunctions.NewArray<Image>(2, 120);\r
+ Image[,] component_movie = StaticFunctions.NewArray<Image>(4, 120);\r
+ Image envelope = new Image(), envelope_small = new Image();\r
+\r
+ for(int i=0; i<120; i++)\r
{\r
- ///+ 1.1 set1\r
- ////set colors for each pixels\r
- R = Math.random(1.0) * 0.5; //Set R values. \r
- G = Math.random(1.0) * 0.5; //Set G values.\r
- B = Math.random(1.0) * 0.5; //Set B values. \r
- col.set(R, G, B);\r
- img.pix(i, j, col);\r
- ///- 1.1 set1\r
- centerrect.centering();\r
+ movie[0, i].set(rect_size, rect_size);\r
+ movie[1, i].set(rect_size, rect_size);\r
+ component_movie[0, i].set(rect_size/2, rect_size/2);\r
+ component_movie[1, i].set(rect_size/2, rect_size/2);\r
+ component_movie[2, i].set(rect_size/2, rect_size/2);\r
+ component_movie[3, i].set(rect_size/2, rect_size/2);\r
}\r
+ envelope.set(rect_size, rect_size);\r
+ envelope_small.set(rect_size/2, rect_size/2);\r
+\r
+ Letters let1 = new Letters(), let2 = new Letters(), let3 = new Letters();\r
+ let1.str = "Component1";\r
+ let2.str = "Component2";\r
+ let3.str = "Superposition";\r
+ let1.centering().shift(-rect_size*1.25, -rect_size);\r
+ //let1.cache();\r
+ let2.centering().shift(rect_size*1.25, -rect_size);\r
+ //let2.cache();\r
+ let3.centering().shift(0.0, rect_size*0.75);\r
+ //let3.cache();\r
+\r
+ component c1, c2, c0;\r
+ c0 = new component{ 0.0,0.0,1.0,1.0 }; //dummy for component movie\r
+ ///+ type-I\r
+ // Prepare Type-I plaid movie\r
+ center_orientation = 0.0;\r
+ orientation_offset = Math.PI/6;\r
+ contrast[0] = 1.0, contrast[1] = 1.0;\r
+ lambda[0] = 30.0, lambda[1] = 30.0;\r
+ tf[0] = 1.0; tf[1] = 1.0;\r
+\r
+ c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};\r
+ c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};\r
+\r
+ drawgratingmovie(movie[0],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+ drawgratingmovie(component_movie[0],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+ drawgratingmovie(component_movie[1],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+ ///- type-I\r
+\r
+ ///+ type-II\r
+ // Prepare Type-II plaid movie\r
+ center_orientation = -0.0, orientation_offset = Math.PI/12;\r
+ contrast[0] = 1.0, contrast[1] = 1.0;\r
+ lambda[0] = 30.0, lambda[1] = 30.0;\r
+ tf[0] = 1.0; tf[1] = 4.0;\r
+\r
+ c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};\r
+ c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};\r
+\r
+ drawgratingmovie(movie[1],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+ drawgratingmovie(component_movie[2],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+ drawgratingmovie(component_movie[3],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+ ///- type-II\r
+\r
+ ///+ gaussian\r
+ //draw Gaussian envelopes\r
+ envelope.clear(new Color(bg_lum)); //clear offscreen image\r
+ double _x, _y;\r
+ for(int i=0; i<rect_size; i++){\r
+ _x=i-0.5*rect_size;\r
+ for(int j=0; j<rect_size; j++){\r
+ _y=j-0.5*rect_size;\r
+ envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/6.0, 2.0) ))));\r
+ }\r
}\r
\r
- //img.cache(); //Move offscreen from main memory to video RAM. (Optional)\r
- ///- 1 Initialize\r
+ envelope_small.clear(new Color(bg_lum)); //clear offscreen image\r
+ for(int i=0; i<rect_size*0.5; i++){\r
+ _x=i-0.25*rect_size;\r
+ for(int j=0; j<rect_size*0.5; j++){\r
+ _y=j-0.25*rect_size;\r
+ envelope_small.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/12.0, 2.0) ))));\r
+ }\r
+ }\r
+ envelope.cache(); //send offscreen image from main memory to GPU\r
+ envelope_small.cache(); //send offscreen image from main memory to GPU\r
+ ///- gaussian\r
\r
- ///+ 2 drawing\r
- ////drawing offscreen\r
+ ///+ user interface\r
+ // Draw user interface\r
+ Widgets::SelectBox stimulus_type;\r
+ stimulus_type.area.set(120, 20);\r
+ stimulus_type.append(L"TypeI");\r
+ stimulus_type.append(L"TypeII");\r
+ stimulus_type.centering().shift(-120.0,250.0);\r
\r
- while (!Keyboard.esc.pushed())\r
- {\r
+ Psychlops::Widgets::SelectBox stimulus_type2;\r
+ stimulus_type2.area.set(120, 20);\r
+ stimulus_type2.append(L"Continuous");\r
+ stimulus_type2.append(L"Periodic");\r
+ stimulus_type2.centering().shift(120.0,250.0);\r
+\r
+ Psychlops::Widgets::Slider duration_slider;\r
+ duration_slider.area.set(100,20);\r
+ duration_slider.centering().shift(120,280.0);\r
+ Interval rng = new Interval();\r
+ duration_slider.link(duration, 50<=rng<=950, 50.0, 50.0);\r
+ ///- user interface\r
+ ///- Preperation\r
+\r
+ ///+ Main loop\r
+ int frame = 0;\r
+ int period = refresh_int;\r
+ int movienum;\r
+ while(!Keyboard.esc.pushed()) {\r
+ Display.clear(new Color(bg_lum));\r
+ movienum = stimulus_type.getSelected(); //if "Type-I" is selected, 0, else frame refresh per sec\r
+\r
+ in;\r
+ else period = refresh_int;\r
\r
- window.clear(Color.black); //Clear screen with black\r
- img.centering(); //centering the position to copy offscreen\r
- img.shift(100, 100); //centering the position to copy offscreen\r
- img.draw(); // copy offscreen onto the reverse side of window buffer.\r
- centerrect.draw(Color.red);// draw reference rectangle at the center.\r
- window.flip();\r
+ if(frame>0){\r
+ movie[movienum, frame].centering().draw();\r
+ envelope.centering().draw();\r
+ component_movie[movienum*2, frame].centering().shift(-rect_size*0.5, -rect_size).draw();\r
+ envelope_small.centering().shift(-rect_size*0.5, -rect_size).draw();\r
+ component_movie[movienum*2+1, frame].centering().shift(rect_size*0.5, -rect_size).draw();\r
+ envelope_small.centering().shift(rect_size*0.5, -rect_size).draw();\r
}\r
- ///- 2 drawing\r
\r
- }\r
- ///- Main Routine\r
+ ///+ draw user interface\r
+ let1.draw(0.75);\r
+ let2.draw(0.75);\r
+ let3.draw(0.75);\r
+ stimulus_type.draw();\r
+ stimulus_type2.draw();\r
+ if(stimulus_type2.getSelected())duration_slider.draw();\r
+ ///- draw user interface\r
+ Display.flip();\r
+ if(frame++ >= period) frame -= refresh_int;\r
+ }\r
+ ///- Main loop\r
\r
+ }\r
+ ///- Stimulus drawing function\r
+\r
+ ///+ Main function for demo circumstances\r
+ public void psychlops_main() {\r
+ ///+ Demo circumstances\r
+ //// Spells for run demonstration circumstances\r
+ Procedure p = new Procedure();\r
+ //p.setDesign(Procedure::DEMO); //Designate that this is a demo.\r
+ p.setProcedure(drawplaid); //The argument name is a name of drawing function.\r
+ p.run();\r
+ ///- Demo circumstances\r
+ }\r
}\r
+}\r
+\r
+\r
+\r
\r
+/*\r
+using Psychlops;\r
+//Position Bias Program\r
+namespace PsychlopsSilverlightApp\r
+{\r
+\r
+ public class PsychlopsMain\r
+ {\r
+ Canvas cnvs;\r
+ Image img, img2, img3;\r
+ int isize = 80; \r
+ int frames;\r
+ Psychlops.Widgets.Slider tfreq;\r
+ Psychlops.Widgets.Slider contrast;\r
+ Psychlops.Widgets.Slider lambda;\r
+\r
+ public void psychlops_main()\r
+ {\r
+ cnvs = new Canvas(300, 600);\r
+ Interval rng = new Interval();\r
+ tfreq = new Psychlops.Widgets.Slider("Temporal Frequency(Hz)", -5 <= rng <= 5, 3.0);\r
+ contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.25);\r
+ lambda = new Psychlops.Widgets.Slider("Wave Length", 10.0 <= rng <= 120.0, 30);\r
+\r
+ img = new Image(isize * 2, isize * 2);\r
+ img2 = new Image(isize * 2, isize * 2);\r
+ img3 = new Image(isize * 2, isize * 2);\r
+\r
+\r
+ while (true)\r
+ {\r
+ cnvs.clear(new Color(0.5));\r
+\r
+ Figures.drawGabor(ref img, isize / 6, 1/lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);\r
+ Figures.drawGabor(ref img2, isize / 6, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * -tfreq / 60);\r
+ Figures.drawGabor(ref img3, isize / 6, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);\r
+\r
+ img.centering().shift(0, -isize * 1.5).draw();\r
+ img2.centering().draw();\r
+ img3.centering().shift(0, isize * 1.5).draw();\r
+ \r
+ if (!Mouse.left.pressed()) frames++;\r
+\r
+ cnvs.flip();\r
+ }\r
+ }\r
+ }\r
}\r
+\r
+*/
\ No newline at end of file