-using Psychlops;\r
+\r
+/*\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
-namespace Psychlops\r
-{\r
+///+ Prefix\r
+//// Include Psychlops Package\r
+using Psychlops;\r
\r
- public class RandomDots\r
+ namespace PsychlopsSilverlightApp\r
{\r
- Rectangle dot;\r
- public Point[] cood;\r
- public RandomDots()\r
- {\r
- cood = new Point[250];\r
- dot = new Rectangle(5, 5);\r
- }\r
- public void draw()\r
+\r
+ public class PsychlopsMain\r
{\r
- dot.fill = Color.white;\r
- foreach (Point p in cood)\r
+ ///- Prefix\r
+\r
+ ///+ Global\r
+ // Struct for component paremeters\r
+ struct component\r
{\r
- dot.centering(p).draw();\r
+ public double contrast;\r
+ public double orientation;\r
+ public double lambda;\r
+ public double tf;\r
}\r
- }\r
- }\r
+ ///- Global\r
\r
-}\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
+ 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
-namespace PsychlopsSilverlight3test\r
-{\r
+ imageheight = img[0].getHeight();\r
+ imagewidth = img[0].getWidth();\r
\r
- public class PsychlopsMain\r
- {\r
- Canvas cnvs;\r
- Image img;\r
- Rectangle fixation;\r
- Shape shape;\r
- Color col;\r
- int isize = 100;\r
- double tfreq = 1;\r
- int frames;\r
- RandomDots dots;\r
-\r
- public void psychlops_main()\r
- {\r
- cnvs = new Canvas(500, 500);\r
- img = new Image(isize * 2, isize * 2);\r
- fixation = new Rectangle(10, 10);\r
- fixation.fill = Color.red;\r
- //var poly = new Rectangle(100, 100);\r
- var poly = new Letters("日本語");\r
- //var poly = new Polygon(); poly.append(0, 100); poly.append(-100, 0); poly.append(0, -100); poly.append(100, 0);\r
- //var poly = new Ellipse(100, 100);\r
- //var poly = new Line(0,0,100, 0);\r
- poly.fill = Color.red;\r
- poly.stroke = new Stroke { color = Color.yellow, thick = 1 };\r
- shape = poly;\r
-\r
- var rng = new Interval();\r
- var slider = new Psychlops.Widgets.Slider("tesrt", 0 <= rng <= 5);\r
-\r
- dots = new RandomDots();\r
-\r
-\r
- while(true) {\r
- frames++;\r
- \r
- cnvs.clear(new Color(Mouse.left.pressed() ? 0.75 : 0.5));\r
- col.set(Math.random(1.0));\r
-\r
- fixation.centering();\r
- fixation.draw(Color.red);\r
-\r
- //Figures.drawGabor(ref img, 20, 100, 1, 0, frames * 2.0 * Math.PI / tfreq / 60);\r
- //Figures.drawGaussian(ref img, 20, 1);\r
- Figures.drawGrating(ref img, 30, 30, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
- img.centering(Mouse.position);\r
- img.draw();\r
-\r
- shape.centering(Mouse.position).shift(100,0);\r
- shape.draw();\r
- if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100);\r
-\r
- cnvs.var(frames, 20, 20);\r
- slider.value = frames/100.0;\r
-\r
- fixation.shift(100,100);\r
- fixation.draw(new Stroke(Color.blue, 3));\r
-\r
- for (int i=0; i<dots.cood.Length; i++)\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
- dots.cood[i].set(Math.random(500), Math.random(500));\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
- dots.draw();\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
+ 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
- cnvs.flip();\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
+ 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
+ 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
+\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
+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 = 40; \r
+ int frames;\r
+ Psychlops.Widgets.Slider tfreq;\r
+ Psychlops.Widgets.Slider contrast;\r
+ Psychlops.Widgets.Slider lambda;\r
+ \r
+\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
+ Figures.ShaderGabor[] gabor1 = StaticFunctions.NewArray<Figures.ShaderGabor>(100);\r
+ foreach(var g in gabor1)\r
+ {\r
+ g.setSigma(isize / 8).centering().shift(Math.random(300) - 150, Math.random(600) - 300);\r
+ g.orientation = Math.random(2*Math.PI);\r
+ }\r
+\r
+ while (true)\r
+ {\r
+ cnvs.clear(new Color(0.5));\r
+\r
+ Figures.drawGabor(ref img, isize / 8, 1/lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);\r
+ Figures.drawGabor(ref img2, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * -tfreq / 60);\r
+ Figures.drawGabor(ref img3, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);\r
+\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
+\r
+ foreach (var g in gabor1)\r
+ {\r
+ g.wavelength = lambda;\r
+ g.phase = (double)frames * 2.0 * Math.PI * tfreq / 60;\r
+ g.contrast = contrast;\r
+ g.draw();\r
+ }\r
+ \r
+ if (!Mouse.left.pressed()) frames++;\r
\r
+ cnvs.flip();\r
+ }\r
+ }\r
+ }\r
}\r