X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=test4%2FPsychlopsMain.cs;h=c61acea34adb5820ff149a2749f9881c2d331c0c;hb=31576ff22c345dea6ef3a1f6d24b031a08a3a62f;hp=120388a6eba0751cf94b0d5eab3266f76b8f2a57;hpb=892d07a825dbe4e84ee7f3e480ece30d1f97a4d8;p=psychlops%2Fsilverlight.git diff --git a/test4/PsychlopsMain.cs b/test4/PsychlopsMain.cs index 120388a..c61acea 100644 --- a/test4/PsychlopsMain.cs +++ b/test4/PsychlopsMain.cs @@ -1,76 +1,295 @@  +/* +//Two types of plaid motion +//E. H. Adelson and J. A. Movshon (1982). +//Phenomenal coherence of moving visual patterns. Nature 300, 523-525 + ///+ Prefix -//// Lines for set up Psychlops environment +//// Include Psychlops Package using Psychlops; -namespace PsychlopsSilverlightApp -{ - - public class PsychlopsMain - {///- Prefix + namespace PsychlopsSilverlightApp + { - ///+ Main Routine - //// Psychlops runs at the first line of this function psychlops_main(). - public void psychlops_main() + public class PsychlopsMain { - ///+ 1 - //// Set a window for drawing stimulus - Canvas window = new Canvas(300, 300); //Create a window. Here, window variables are preset mode. - // You can write this statement as" Canvas window = new Canvas(Canvas.fullscreen); " for fullscreen mode - // or as " Canvas window = new Canvas(1024, 768, 32, 60.0); " This statement changes screenmode to 1024 x 768, 32bit color, 60 Hz refresh. - ///- 1 - - var FIGURE = Psychlops.Widgets.Browser.Element.byID("FIGURE"); - var SIZE_X = Psychlops.Widgets.Browser.Element.byID("SIZE_X"); - var SIZE_Y = Psychlops.Widgets.Browser.Element.byID("SIZE_Y"); - var SHIFT_X = Psychlops.Widgets.Browser.Element.byID("SHIFT_X"); - var SHIFT_Y = Psychlops.Widgets.Browser.Element.byID("SHIFT_Y"); - var COLOR_R = Psychlops.Widgets.Browser.Element.byID("COLOR_R"); - var COLOR_G = Psychlops.Widgets.Browser.Element.byID("COLOR_G"); - var COLOR_B = Psychlops.Widgets.Browser.Element.byID("COLOR_B"); - - - ///+ 2 - //// Set a figure size, position and color. - Rectangle figure = new Rectangle(); - Ellipse figure2 = new Ellipse(); - - window.flip(); // Reflect the drawing for the display by flipping frame buffers. - // Till this point, you will not see drawn figures. - ///- 2 - - ///+ 3 - //// Detect a Keyboard input - while (!Keyboard.esc.pushed()) + ///- Prefix + + ///+ Global + // Struct for component paremeters + struct component { + public double contrast; + public double orientation; + public double lambda; + public double tf; + } + ///- Global - window.clear(); + ///+ Stimulus drawing function + //// A function for stimulus drawing (main body) + void drawgratingmovie(Image[] img, component c1, component c2, double contrast, int start, int maxframe, double bg_lum, double alpha) + { + double _xp, _xp2, col1, col2; + double contrast1, contrast2; + double imageheight, imagewidth; - if ("Rectangle".Equals(FIGURE)) - { - figure.set(SIZE_X, SIZE_Y); // Set the size of figure. - figure.centering(); // Centering the figure in the window - figure.shift(SHIFT_X, SHIFT_Y); // Displacing the figure by designated vector. - figure.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the rectangle with a designated color. + contrast1 = contrast*c1.contrast/(c1.contrast+c2.contrast); + contrast2 = contrast*c2.contrast/(c1.contrast+c2.contrast); + + imageheight = img[0].getHeight(); + imagewidth = img[0].getWidth(); + + for(int frame=start; frame(2, 120); + Image[,] component_movie = StaticFunctions.NewArray(4, 120); + Image envelope = new Image(), envelope_small = new Image(); + + for(int i=0; i<120; i++) { - figure2.set(SIZE_X, SIZE_Y); // Set the size of figure. - figure2.centering(); // Centering the figure in the window - figure2.shift(SHIFT_X, SHIFT_Y); // Displacing the figure by designated vector. - figure2.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the rectangle with a designated color. + movie[0, i].set(rect_size, rect_size); + movie[1, i].set(rect_size, rect_size); + component_movie[0, i].set(rect_size/2, rect_size/2); + component_movie[1, i].set(rect_size/2, rect_size/2); + component_movie[2, i].set(rect_size/2, rect_size/2); + component_movie[3, i].set(rect_size/2, rect_size/2); } + envelope.set(rect_size, rect_size); + envelope_small.set(rect_size/2, rect_size/2); - window.flip(); + Letters let1 = new Letters(), let2 = new Letters(), let3 = new Letters(); + let1.str = "Component1"; + let2.str = "Component2"; + let3.str = "Superposition"; + let1.centering().shift(-rect_size*1.25, -rect_size); + //let1.cache(); + let2.centering().shift(rect_size*1.25, -rect_size); + //let2.cache(); + let3.centering().shift(0.0, rect_size*0.75); + //let3.cache(); - } //exit a program when the escape key is pressed down. - ///- 3 + component c1, c2, c0; + c0 = new component{ 0.0,0.0,1.0,1.0 }; //dummy for component movie + ///+ type-I + // Prepare Type-I plaid movie + center_orientation = 0.0; + orientation_offset = Math.PI/6; + contrast[0] = 1.0, contrast[1] = 1.0; + lambda[0] = 30.0, lambda[1] = 30.0; + tf[0] = 1.0; tf[1] = 1.0; - } - ///- Main Routine + c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]}; + c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]}; - } + drawgratingmovie(movie[0],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0); + drawgratingmovie(component_movie[0],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0); + drawgratingmovie(component_movie[1],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0); + ///- type-I + + ///+ type-II + // Prepare Type-II plaid movie + center_orientation = -0.0, orientation_offset = Math.PI/12; + contrast[0] = 1.0, contrast[1] = 1.0; + lambda[0] = 30.0, lambda[1] = 30.0; + tf[0] = 1.0; tf[1] = 4.0; + + c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]}; + c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]}; + + drawgratingmovie(movie[1],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0); + drawgratingmovie(component_movie[2],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0); + drawgratingmovie(component_movie[3],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0); + ///- type-II + + ///+ gaussian + //draw Gaussian envelopes + envelope.clear(new Color(bg_lum)); //clear offscreen image + double _x, _y; + for(int i=0; i0){ + movie[movienum, frame].centering().draw(); + envelope.centering().draw(); + component_movie[movienum*2, frame].centering().shift(-rect_size*0.5, -rect_size).draw(); + envelope_small.centering().shift(-rect_size*0.5, -rect_size).draw(); + component_movie[movienum*2+1, frame].centering().shift(rect_size*0.5, -rect_size).draw(); + envelope_small.centering().shift(rect_size*0.5, -rect_size).draw(); + } + ///+ draw user interface + let1.draw(0.75); + let2.draw(0.75); + let3.draw(0.75); + stimulus_type.draw(); + stimulus_type2.draw(); + if(stimulus_type2.getSelected())duration_slider.draw(); + ///- draw user interface + Display.flip(); + if(frame++ >= period) frame -= refresh_int; + } + ///- Main loop + + } + ///- Stimulus drawing function + + ///+ Main function for demo circumstances + public void psychlops_main() { + ///+ Demo circumstances + //// Spells for run demonstration circumstances + Procedure p = new Procedure(); + //p.setDesign(Procedure::DEMO); //Designate that this is a demo. + p.setProcedure(drawplaid); //The argument name is a name of drawing function. + p.run(); + ///- Demo circumstances + } + } } +*/ + + + +using Psychlops; +//Position Bias Program +namespace PsychlopsSilverlightApp +{ + + public class PsychlopsMain + { + Canvas cnvs; + Image img, img2, img3; + int isize = 40; + int frames; + Psychlops.Widgets.Slider tfreq; + Psychlops.Widgets.Slider contrast; + Psychlops.Widgets.Slider lambda; + + + + public void psychlops_main() + { + cnvs = new Canvas(300, 600); + Interval rng = new Interval(); + tfreq = new Psychlops.Widgets.Slider("Temporal Frequency(Hz)", -5 <= rng <= 5, 3.0); + contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.25); + lambda = new Psychlops.Widgets.Slider("Wave Length", 10.0 <= rng <= 120.0, 30); + img = new Image(isize * 2, isize * 2); + img2 = new Image(isize * 2, isize * 2); + img3 = new Image(isize * 2, isize * 2); + var gabor1 = StaticFunctions.NewArray(100); + foreach(var g in gabor1) + { + g.setSigma(isize / 8).centering().shift(Math.random(300) - 150, Math.random(600) - 300); + g.orientation = Math.random(2*Math.PI); + } + + while (true) + { + cnvs.clear(new Color(0.5)); + + Figures.drawGabor(ref img, isize / 8, 1/lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60); + Figures.drawGabor(ref img2, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * -tfreq / 60); + Figures.drawGabor(ref img3, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60); + + + //img.centering().shift(0, -isize * 1.5).draw(); + //img2.centering().draw(); + //img3.centering().shift(0, isize * 1.5).draw(); + + + foreach (var g in gabor1) + { + g.wavelength = lambda; + g.phase = (double)frames * 2.0 * Math.PI * tfreq / 60; + g.contrast = contrast; + g.draw(); + } + + if (!Mouse.left.pressed()) frames++; + + cnvs.flip(); + } + } + } +}