OSDN Git Service

main
[psychlops/silverlight.git] / test5 / PsychlopsMain.cs
index e69a680..f647b34 100644 (file)
-using Psychlops;\r
+\r
+// Lilac Chaser.\r
+// Zaidi Q, Ennis R, Cao D, Lee B (2012)\r
+// Neural locus of color after-image.\r
+// Current Biology, 22, 220-224\r
+///+ Prefix\r
+//// Include Psychlops Package\r
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlightApp\r
+{\r
+\r
+       public class PsychlopsMain\r
+               {\r
+///- Prefix\r
+\r
+\r
+               ///+ Stimulus drawing function\r
+               //// A function for stimulus drawing (main body)\r
+               public void psychlops_main() {\r
+\r
+                       ///+ Preperation\r
+                       //// Declare and initialize local variables\r
+                       Canvas cnvs = new Canvas(Canvas.window); //Prepare drawing window\r
+                       double dotsize = 100;\r
+                       double dot_lum  = 1;\r
+                       double bg_lum    = 0.5;\r
+                       double duration = 8.0;\r
+                       int stroke = 0;\r
+                       bool draw_base_position = false;\r
+\r
+                       var fixate = new Rectangle();\r
+                       Image dot = new Image();\r
+                       Color col = new Color();\r
+                       double xp, yp, radius, a;\r
+\r
+                       Psychlops.Widgets.Slider hue, value;\r
+                       ///- Preperation\r
+\r
+                       ///+ set Independent\r
+                       //// set variables and value ranges for interaction\r
+                       Interval rng = new Interval();\r
+                       hue = new Psychlops.Widgets.Slider("Hue", 0.0 <= rng < 360.0, 1, 12);\r
+                       hue.setValue(300.0);\r
+                       value = new Psychlops.Widgets.Slider("Lightness", 0 <= rng <= 1.0, 0.1, 0.05);\r
+                       value.setValue(0.7);\r
+                       ///- set Independent\r
+\r
+                       dot.set(dotsize, dotsize);\r
+                       double width = dotsize, height = dotsize, sigma = (width / 6.0);\r
+\r
+                       fixate.set(11,11);\r
+\r
+                       int frame = 0;\r
+\r
+                       while (!Keyboard.esc.pushed())\r
+                       {\r
+                               ///+ reflesh dot\r
+                               if (hue.changed)\r
+                               {\r
+                                       Psychlops.ColorSpaces.HSV hsv = new Psychlops.ColorSpaces.HSV();\r
+                                       hsv.H = Math.mod( hue.getValue(), 360);\r
+                                       hsv.S = 1.0;\r
+                                       hsv.V = value.getValue();\r
+                                       dot.each((x, y) =>\r
+                                       {\r
+                                               yp = y - height / 2.0;\r
+                                               xp = x - width / 2.0;\r
+                                               radius = Math.sqrt(xp * xp + yp * yp);\r
+                                               hsv.A = Math.exp(-(radius * radius) / (2.0 * sigma * sigma));\r
+                                               return hsv.toRGB();\r
+                                       });\r
+                               }\r
+                               ///+ reflesh dot\r
+\r
+\r
+                               ///+ stroke count\r
+                               if(frame%((int)duration)==0) {\r
+                                       stroke++; stroke %= 8;\r
+                               }\r
+                               ///- stroke count\r
+\r
+                               cnvs.clear(new Color(bg_lum)); //Clear window\r
+\r
+\r
+                               ///+ Draw dots\r
+                               //// Draw dots at a desinated position.\r
+                               for(int i=0; i<8; i++) {\r
+                                       if(i!=stroke) {\r
+                                               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
+                                       }\r
+                               }\r
+                               ///- Draw dots\r
+\r
+                               fixate.centering().draw();\r
+\r
+                               cnvs.flip(); // Flip frame buffers\r
+                               frame++;\r
+                       }\r
+\r
+               }\r
+               ///- Stimulus drawing function\r
+\r
+       }\r
+\r
+}\r
+\r
+\r
+/*\r
+// Motion with glass patterns.\r
+// Ross, J., Badcock, D. R., and Hayes, A. (2000)\r
+// Coherent global motion in the absence of coherent velocity signals.\r
+// Current Biology, 10, 679-682.\r
+///+ Prefix\r
+//// Include Psychlops Package\r
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlightApp\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+               Psychlops.Widgets.Slider distance, duration, stimulus_type;\r
+               ///- Prefix\r
+\r
+               public void psychlops_main()\r
+               {\r
+                       GlassPattern();\r
+               }\r
+\r
+               readonly int DOTNUM = 512;\r
+\r
+               ///+ Stimulus drawing function\r
+               //// A function for stimulus drawing (main body)\r
+               void GlassPattern() {\r
+\r
+                       ///+ Preperation\r
+                       //// Declare and initialize local variables\r
+                       Canvas cnvs = new Canvas(400,400); //Prepare drawing window\r
+                       double dotsize = 2;\r
+                       double dot_lum  = 1.0;\r
+                       double bg_lum    = 0.2;\r
+                       double fieldsize = 300;\r
+                       double[] orientation = new double[DOTNUM];\r
+                       Rectangle dots = new Rectangle(dotsize, dotsize);\r
+                       Ellipse dot = new Ellipse(dotsize*3, dotsize*3);\r
+                       ///+ prepare dots position\r
+                       //// prepare dots position and paired orientation\r
+                       Matrix positionmat = Matrix.gen(DOTNUM,2);\r
+                       //Math.random(positionmat, -0.5*fieldsize, 0.5*fieldsize);\r
+                       positionmat.each( (v) => Math.random(-0.5*fieldsize, 0.5*fieldsize) );\r
+\r
+                       \r
+                       for(int i=0; i<DOTNUM; i++){orientation[i] = Math.atan2(positionmat[i+1,2], positionmat[i+1,1]);}\r
+                       ///- prepare dots position\r
+\r
+\r
+                       ///+ Draw Gaussian Envelope\r
+                       ////Draw offscreen Gaussian Envelope\r
+                       Image envelope = new Image(fieldsize+100, fieldsize+100);\r
+                       envelope.clear(new Color(bg_lum)); //clear offscreen image\r
+                       double _x, _y;\r
+                       for(int i=0; i<fieldsize+100; i++){\r
+                               _x=i-0.5*fieldsize-50;\r
+                               for(int j=0; j<fieldsize+100; j++){\r
+                                       _y=j-0.5*fieldsize-50;\r
+                                       envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*Math.pow(fieldsize/4.0, 2.0) ))));\r
+                               }\r
+                       }\r
+                       envelope.cache();\r
+                       ///- Draw Gaussian Envelope\r
+                       ///+ set Independent\r
+                       //// set variables and value ranges for interaction\r
+                       Interval rng = new Interval();\r
+                       stimulus_type = new Psychlops.Widgets.Slider("Stimulus Type", 0.0 <= rng <= 5.0, 1, 1);\r
+                       stimulus_type.setValue(0);\r
+                       distance = new Psychlops.Widgets.Slider("distance between pairs", 1 <= rng <= 10, 1, 1);\r
+                       distance.setValue(4.0);\r
+                       duration = new Psychlops.Widgets.Slider("Refresh", 0.0 <= rng <= 30.0, 1, 1);\r
+                       duration.setValue(5);\r
+                       ///- set Independent\r
+\r
+                       int frame = 0;\r
+                       int stroke = 0;\r
+                       bool draw_base_position = false;\r
+                       Color col = new Color();\r
+\r
+\r
+                       ///+ initialize position\r
+                       //// Re-randomize position with a desingated interval\r
+                       //Math.random(positionmat, -0.5 * fieldsize, 0.5 * fieldsize);\r
+                       positionmat.each((v) => Math.random(-0.5 * fieldsize, 0.5 * fieldsize));\r
+                       for (int i = 0; i < DOTNUM; i++) { orientation[i] = Math.atan2(positionmat[i + 1, 2], positionmat[i + 1, 1]); }\r
+                       frame = 0;\r
+                       ///- initialize position\r
+\r
+                       while (!Keyboard.esc.pushed())\r
+                       {\r
+                               ///+ stroke count\r
+                               if (frame % duration == 0)\r
+                               {\r
+                                       stroke++; stroke %= 4;\r
+                                       if (stroke < 2) col.set(dot_lum);\r
+                                       else col.set(1 - dot_lum);\r
+                                       draw_base_position = (stroke % 2 == 0);\r
+                               }\r
+                               ///- stroke count\r
+\r
+                               Display.clear(new Color(bg_lum)); //Clear window\r
+\r
+                               if ((int)stimulus_type <= 1)\r
+                               {\r
+                                       for (int i = -10; i < 11; i++)\r
+                                       {\r
+                                               if (stroke % 2 == 0)\r
+                                                       dot.centering().shift((stimulus_type * 2 - 1) * -distance / 2.0, i * 20);\r
+                                               else\r
+                                                       dot.centering().shift((stimulus_type * 2 - 1) * distance / 2.0, i * 20);\r
+                                               dot.draw(col);\r
+                                       }\r
+\r
+                               } else {\r
+                                       //// Draw DOTNUM pairs of dots\r
+                                       for (int i = 0; i < DOTNUM; i++)\r
+                                       {\r
+                                               ///+ draw first dots\r
+\r
+                                               ///+ switch stimulus type\r
+                                               //// draw the second dots to generate selected stimulu type.\r
+                                               switch ((int)stimulus_type)\r
+                                               {\r
+                                                       ///+ case rotation\r
+                                                       //// Rotation\r
+                                                       case 2:\r
+                                                               dots.centering().shift(positionmat[i + 1, 1], positionmat[i + 1, 2]); // move to center position\r
+                                                               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
+                                                               if (draw_base_position) dots.draw(col); // draw first dot\r
+                                                               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
+                                                               //cnvs.msg("Rotation", cnvs.getCenter().x, cnvs.getHeight() - 20);\r
+                                                               break;\r
+                                                       ///- case rotation\r
+                                                       ///+ case diversion\r
+                                                       ////Diversion\r
+                                                       case 3:\r
+                                                               dots.centering().shift(positionmat[i + 1, 1], positionmat[i + 1, 2]);// move to center position\r
+                                                               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
+                                                               if (draw_base_position) dots.draw(col); // draw first dot\r
+                                                               dots.shift(distance * Math.cos(orientation[i]), distance * Math.sin(orientation[i]));// move to the second position\r
+                                                               break;\r
+                                                       ///- case diversion\r
+                                                       ///+ case spiral\r
+                                                       //// Spiral\r
+                                                       case 4:\r
+                                                               dots.centering().shift(positionmat[i + 1, 1], positionmat[i + 1, 2]);// move to center position\r
+                                                               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
+                                                               if (draw_base_position) dots.draw(col); // draw first dot\r
+                                                               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
+                                                               break;\r
+                                                       ///- case spiral\r
+                                               }\r
+                                               ///- switch stimulus type\r
+\r
+                                               ///- draw first dots\r
+\r
+\r
+                                               ///+ draw second dots\r
+                                               if (!draw_base_position) dots.draw(col); // Draw dots at a desinated position.\r
+                                               ///- draw second dots\r
+\r
+                                       }\r
+                                       ///- Draw dots\r
+                               }\r
+                               envelope.centering().draw();\r
+                               Display.flip(); // Flip frame buffers\r
+                               frame++;\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+*/\r
+\r
+\r
+/*\r
+//Psychlops Code Template\r
+//    Please visit following web site to get sample codes.\r
+//    http://psychlops.sourceforge.jp/ja/?StartCode\r
+//    CodeDresser at following address is also available to view the code.\r
+//    http://visitope.org/Tools/codedresser.html\r
+\r
+///+ 0 Setup Psychlops Circumstances\r
+//// 0 Setup Psychlops Circumstances\r
+using Psychlops;\r
 \r
 namespace PsychlopsSilverlightApp\r
 {\r
 \r
        public class PsychlopsMain\r
        {\r
+               // Psychlops Win32 1.5.5 / 20110927\r
+               ///- 0 Setup Psychlops Circumstances\r
 \r
+               Psychlops.Widgets.Slider SOAFrames, gap, wavelength, contrast;\r
 \r
                public void psychlops_main() {\r
 \r
+                       ///+ 1 Declaration /////////////////////////////////////////////////////////////\r
+                       //// 1 Declaration\r
+                       // declare default window and variables for its parameters\r
+                       Canvas cnvs = new Canvas(600,600, Canvas.window, Display.primary);\r
+                       double CANVAS_FRAMENUM;\r
+                       int CANVAS_REFRESHRATE;\r
+                       Color DEFAULT_BG_COLOR = new Color();\r
+\r
+                       int gratingwidth = 500, gratingheight = 100;\r
+                       double shift=0.0;\r
+                       Color color = new Color(0.0,0.0,0.0);\r
+                       Rectangle grating = new Rectangle();\r
+\r
+\r
+                       Interval rng = new Interval();\r
+\r
+                       //declare local variables around here\r
+\r
+                       ///- 1 Declaration /////////////////////////////////////////////////////////////\r
+\r
+                       ///+ 2 Initialization //////////////////////////////////////////////////////////\r
+                       //// 2 Initialization\r
+\r
+                       // Set initial values for local variables\r
+                       CANVAS_REFRESHRATE = (int)cnvs.getRefreshRate();\r
+                       CANVAS_FRAMENUM = 0;\r
+                       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
+\r
+\r
+                       SOAFrames = new Psychlops.Widgets.Slider("SOA Frames", 1  <=rng<=20  ,  1   , 1);\r
+                       SOAFrames.value = 5;\r
+                       gap = new Psychlops.Widgets.Slider("Grating gap" , 0  <=rng<=200 ,  1   , 10);\r
+                       gap.value = 20;\r
+                       wavelength = new Psychlops.Widgets.Slider("Wave Length", 1 <= rng <= 50, 1, 10);\r
+                       wavelength.value = 30.0;\r
+                       contrast = new Psychlops.Widgets.Slider("Contrast"    , 0.0<=rng<=1.0 ,  0.1 , 0.01);\r
+                       contrast.value = 0.1;\r
+\r
+                       // Draw Offline images around here\r
+\r
+                       // Offline Movie calculation using Image array around here\r
+\r
+                       ///- 2 Initialization //////////////////////////////////////////////////////////\r
+\r
+                       ///+ 3 Drawing /////////////////////////////////////////////////////////////////\r
+                       //// 3 Drawing\r
+                       while(!Keyboard.esc.pushed()) {\r
+                       cnvs.clear(DEFAULT_BG_COLOR);\r
+\r
+                       //Write draw commands for realtime figure calculation and drawing around here\r
+\r
+\r
+                       if(Math.mod(CANVAS_FRAMENUM,SOAFrames) == 0){shift += 1;}\r
+\r
+                       grating.set(1,gratingheight).centering().shift(-gratingwidth/2, 0);\r
+                       for(int i=0; i<gratingwidth; i++) {\r
+                               color.set(\r
+                                                       + 0.25*contrast*Math.sin(2*Math.PI*(i*2.0/wavelength + 0.50 * shift))\r
+                                                       + 0.25*contrast*Math.sin(2*Math.PI*(i*3.0/wavelength + 0.75 * shift))\r
+                                                       +0.5\r
+                                                       );\r
+                               grating.shift(1, 0);\r
+                               grating.draw(color);\r
+                       }\r
+\r
+                       grating.set(1,gratingheight).centering().shift(-gratingwidth/2, -gratingheight-gap);\r
+                       for(int i=0; i<gratingwidth; i++) {\r
+                               color.set(\r
+                                                       + 0.25*contrast*Math.sin(2.0*Math.PI*(i*2.0/wavelength + 0.50 * shift))\r
+                                                       +0.5\r
+                                                       );\r
+                               grating.shift(1,0);\r
+                               grating.draw(color);\r
+                       }\r
+\r
+                       grating.set(1,gratingheight).centering().shift(-gratingwidth/2, gratingheight+gap);\r
+                       for(int i=0; i<gratingwidth; i++) {\r
+                               color.set(\r
+                                                       + 0.25*contrast*Math.sin(2.0*Math.PI*(i*3.0/wavelength + 0.75 * shift))\r
+                                                       +0.5\r
+                                                       );\r
+                               grating.shift(1,0);\r
+                               grating.draw(color);\r
+                       }\r
+\r
+                       cnvs.flip();\r
+                       CANVAS_FRAMENUM++;\r
+                       }\r
+                       ///- 3 Drawing /////////////////////////////////////////////////////////////////\r
+\r
+               }\r
+\r
+\r
+       }\r
+\r
+}\r
+*/\r
+\r
+\r
+/*\r
+               public void psychlops_main() {\r
+\r
        Canvas display = new Canvas(768,768);\r
 \r
        double rect_size = 100;\r
@@ -132,11 +529,12 @@ Math.PI*Math.sin(Math.PI/2*i+2*Math.PI*phase*TF/refresh);
 \r
 }\r
 \r
-\r
-\r
        }\r
 \r
 }\r
+*/\r
+\r
+\r
 /*\r
 \r
 using Psychlops;\r