OSDN Git Service

2121
[psychlops/silverlight.git] / test4 / PsychlopsMain.cs
index e7b6754..261c75d 100644 (file)
@@ -1,4 +1,174 @@
-/*using Psychlops;\r
+///+ Prefix linkto BasicCode1\r
+//// Lines for set up Psychlops environment\r
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlight4test\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {///- Prefix linkto BasicCode1\r
+\r
+\r
+               ///+ Main Routine\r
+               //// Psychlops runs at the first line of this function psychlops_main().\r
+               public void psychlops_main() {\r
+    ///+ 0 linkto BasicCode3_1a\r
+    ////Prepare global parameters\r
+     const int maxrectnum = 200;\r
+     int rectnum = 100/*ID:rectnumber 25.0 200.0 25.0*/;\r
+     double rectsize = 5.0/*ID:dotsize 1.0 10.0 1.0*/;\r
+     Rectangle[] rect = new Rectangle[maxrectnum];\r
+        for (int i = 0; i < maxrectnum; i++) { rect[i] = new Rectangle(); }\r
+     double[] rectcolorR = new double[maxrectnum];\r
+     double[] rectcolorG = new double[maxrectnum];\r
+     double[] rectcolorB = new double[maxrectnum];\r
+    ///- 0 linkto BasicCode3_1a\r
+\r
+        Canvas window = new Canvas(Canvas.window);\r
+\r
+     ///+ 1 linkto BasicCode3_1a\r
+     ////Initialize\r
+     for(int i=0; i < rectnum; i++){\r
+         ///+ 1.1 set1\r
+         ////set positions and sizes\r
+         rect[i].set(rectsize, rectsize); //Set a size of rectangles.\r
+         rect[i].centering();\r
+         rect[i].shift((i - 0.5 * rectnum) * rectsize* 1.5/*ID:RectHGap 1.0 3.0 0.5*/,\r
+                                        (i - 0.5*rectnum) * rectsize * 1.5/*ID:RectVGap 1.0 3.0 0.5*/); //Move Rectangles to initial positions\r
+         ///- 1.1 set1\r
+         ///+ 1.2 set2\r
+         ////set colors\r
+         rectcolorR[i]=Math.random(1.0) * 0.5/*ID: RGain 0.0 1.0 0.5*/; //Set R values. Note that "i" is converted to double-type.\r
+         rectcolorG[i]=Math.random(1.0) * 0.5/*ID: GGain 0.0 1.0 0.5*/; //Set G values. Note that "i" is converted to double-type.\r
+         rectcolorB[i]=Math.random(1.0) * 0.5/*ID: BGain 0.0 1.0 0.5*/; //Set B values. Note that "i" is converted to double-type.\r
+         ///- 1.2 set2\r
+         }\r
+    ///- 1 linkto BasicCode3_1a\r
+\r
+    ///+ 2 drawing\r
+    ////drawing objects\r
+    ///+ 2.1 setlocal\r
+    ////Prepare variables for movie control;\r
+    int frame = 0;\r
+    int motion_dir = 1;\r
+    double Horizontal_shift, Vertical_shift;\r
+    ///- 2.1 setlocal\r
+\r
+    while(!Keyboard.esc.pushed()){\r
+        window.clear(Color.black);\r
+\r
+        if(frame % 30/*ID:Period_Position 30 240 30*/ ==0){ // motion direction will reverse at designated frames.\r
+               motion_dir *= -1;\r
+        }\r
+\r
+        for(int i=0; i < rectnum; i++){\r
+         ///+ 2.2 loopset1\r
+         ////set positions and sizes\r
+\r
+         Horizontal_shift=motion_dir * 1.0/*ID:HSpeed 0.0 5.0 1.0*/;\r
+         Vertical_shift=motion_dir * 0.0/*ID:VSpeed 0.0 5.0 1.0*/;\r
+\r
+         rect[i].resize(rectsize, rectsize); //Resize rectangles.\r
+         rect[i].shift(Horizontal_shift, Vertical_shift);\r
+         ///- 2.2 loopset1\r
+\r
+         ///+ 2.3 loopset2\r
+         ////set colors\r
+         rectcolorR[i]=Math.random(1.0)* 0.5/*ID:RGain 0.0 1.0 0.5*/; //Set R values. Note that "i" is converted to double-type.\r
+         rectcolorG[i]=Math.random(1.0)* 0.5/*ID:GGain 0.0 1.0 0.5*/; //Set G values. Note that "i" is converted to double-type.\r
+         rectcolorB[i]=Math.random(1.0)* 0.5/*ID:BGain 0.0 1.0 0.5*/; //Set B values. Note that "i" is converted to double-type.\r
+         ///- 2.3 loopset2\r
+\r
+         }\r
+               \r
+               ///+ 2.4 linkto BasicCode3_1a\r
+        for(int i=0; i < rectnum; i++){\r
+            rect[i].draw(new Color(rectcolorR[i], rectcolorG[i], rectcolorB[i])); //draw objects by designated colors.\r
+        }\r
+        window.flip();\r
+        ///- 2.4 linkto BasicCode3_1a\r
+        \r
+        frame++;\r
+    }\r
+    ///- 2 drawing\r
+\r
+}\r
+               ///- Main Routine\r
+\r
+\r
+       }\r
+\r
+}\r
+\r
+\r
+/*\r
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlight4test\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+\r
+               Psychlops.Widgets.Slider rect_size;\r
+               Psychlops.Widgets.Slider rect_lum;\r
+               Psychlops.Widgets.Slider bg_lum;\r
+\r
+\r
+               void RectLuminance()\r
+               {\r
+                       Canvas display = new Canvas(Canvas.window);\r
+                       Interval rng = new Interval();\r
+                       rect_size = new Psychlops.Widgets.Slider("Rect Size", 1 < rng < 500, 10.0);\r
+                       rect_lum = new Psychlops.Widgets.Slider("Rect Luminance", 0.0 <= rng <= 1.0, 0.1);\r
+                       bg_lum = new Psychlops.Widgets.Slider("BG Luminance", 0.0 <= rng <= 1.0, 0.1);\r
+                       Ellipse drawee = new Ellipse(100, 100);\r
+                       display.showFPS();\r
+                       display.watchFPS();\r
+\r
+                       Rectangle rect = new Rectangle(rect_size, rect_size);\r
+                       rect.centering();\r
+\r
+\r
+                       Clock before = new Clock(), after = new Clock();\r
+                       while (!Keyboard.esc.pushed())\r
+                       {\r
+                               Display.clear(bg_lum);\r
+                               rect.resize(rect_size, rect_size).draw(rect_lum);\r
+                               after.update();\r
+                               display.var((after - before).at_msec(), 100, 100, Color.green);\r
+                               display.var((after - before).at_msec(), 100, 200, Color.green);\r
+                               drawee.centering().shift(Math.random(100), 0);\r
+                               drawee.draw(Color.black);\r
+                               Display.flip();\r
+                       }\r
+\r
+               }\r
+\r
+\r
+               public void psychlops_main()\r
+               {\r
+                       RectLuminance();\r
+               }\r
+\r
+\r
+       }\r
+\r
+}\r
+*/\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+/*\r
+ using Psychlops;\r
 \r
 namespace PsychlopsSilverlight4test\r
 {\r
@@ -14,12 +184,25 @@ namespace PsychlopsSilverlight4test
                double TargetEcce = 100.0, TargetSize = 5.0, TargetNumber = 5, Rotate = 0.0;\r
 \r
                //Set Background Initial Value\r
-               double DotNumber = 50, thetaSpeed = 3.0, Axis = 0.0, BGRadii = 150, BGSize = 5.0;\r
+               double Axis = 0.0, BGRadii = 150, BGSize = 5.0;\r
+               Psychlops.Widgets.Slider thetaSpeed, DotNumber;\r
+               Image img;\r
+\r
+\r
 \r
                public void psychlops_main()\r
                {\r
                        cnvs = new Canvas(500, 500);\r
 \r
+                       Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);\r
+\r
+\r
+                       img = new Image("Resources/logo.png");\r
+\r
+                       Interval rng = new Interval();\r
+                       thetaSpeed = new Psychlops.Widgets.Slider("Label", -10 <= rng <= 10, 3.0);\r
+                       DotNumber  = new Psychlops.Widgets.Slider("DotNum",   0 <= rng <= 100, 50.0);\r
+\r
                        //Declare background dots and target\r
                        Rectangle[] BGDot = new Rectangle[2048];\r
                        for(int i=0; i<2048; i++){\r
@@ -56,11 +239,11 @@ namespace PsychlopsSilverlight4test
                        for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize);\r
 \r
                        double COS, SIN;\r
-                       DotNumber = 200;\r
+                       //DotNumber = 200;\r
                        //Main stimulus loop\r
                        while(true){\r
                                //Clear the main window\r
-                               cnvs.clear(Color.green);\r
+                               cnvs.clear();\r
 \r
 \r
                                temp=Axis/360*2*Math.PI;\r
@@ -101,6 +284,11 @@ namespace PsychlopsSilverlight4test
                                        Target[i].draw();\r
                                }\r
 \r
+                               img.centering(Mouse.position).draw();\r
+\r
+                               cnvs.var(Mouse.position.x, 100, 100);\r
+                               cnvs.var(Mouse.position.y, 100, 140);\r
+\r
                                //Reflect drawing at the next frame;\r
                                cnvs.flip();\r
                        }\r
@@ -110,6 +298,7 @@ namespace PsychlopsSilverlight4test
 }\r
 */\r
 \r
+\r
 /*using Psychlops;\r
 \r
 namespace PsychlopsSilverlight4test\r
@@ -156,10 +345,10 @@ namespace PsychlopsSilverlight4test
 \r
 }\r
 \r
-*/\r
 \r
 \r
 \r
+/*\r
 using Psychlops;\r
 \r
 namespace Psychlops\r
@@ -224,7 +413,7 @@ namespace PsychlopsSilverlight4test
                        shape = poly;\r
 \r
                        var rng = new Interval();\r
-                       var slider = new Psychlops.Widgets.Slider("tesrt", 0 <= rng <= 5);\r
+                       var slider = new Psychlops.Widgets.Slider("tesrt", -100 <= rng <= 100);\r
 \r
                        dots = new RandomDots();\r
 \r
@@ -241,36 +430,37 @@ namespace PsychlopsSilverlight4test
                                {\r
                                        fixation.centering().shift(100, 100);\r
                                        fixation.draw(new Stroke(Color.blue, 3));\r
-                               }*/\r
+                               }* /\r
 \r
-                               fixation.centering();\r
+                               fixation.centering().shift(slider, 0);\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, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
-                               img.centering(Mouse.position);\r
-                               img.draw();\r
-                               //g.centering(Mouse.position).draw();\r
-                               //g.rotation += 1;\r
+                               //img.centering(Mouse.position);\r
+                               //img.draw();\r
+                               g.centering(Mouse.position).draw();\r
+                               g.rotation += 1;\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, 0, 20);\r
-                               slider.value = frames / 100.0;\r
+                               //slider.value = frames / 100.0;\r
 \r
                                /*if (frames % 2 != 0)\r
                                {\r
                                        fixation.shift(100, 100);\r
                                        fixation.draw(new Stroke(Color.green, 3));\r
-                               }*/\r
+                               }* /\r
 \r
                                for (int i = 0; i < dots.cood.Length; i++)\r
                                {\r
                                        dots.cood[i].set(Math.random(500), Math.random(500));\r
                                }\r
+                               cnvs.var((double)slider, 200, 200);\r
                                dots.draw();\r
 \r
                                cnvs.flip();\r
@@ -279,3 +469,45 @@ namespace PsychlopsSilverlight4test
        }\r
 }\r
 \r
+**/\r
+\r
+\r
+/*\r
+\r
+using Psychlops;\r
+namespace PsychlopsSilverlight4test\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+               Canvas cnvs;\r
+               Rectangle[] rect;\r
+               int n;\r
+\r
+               public void psychlops_main()\r
+               {\r
+                       n = 1;\r
+                       cnvs = new Canvas(500, 500);\r
+                       rect = new Rectangle[n];\r
+                       for (int i = 0; i < n; i++)\r
+                       {\r
+                               rect[i] = new Rectangle(10, 10);\r
+                               rect[i].fill = Color.red;\r
+                       }\r
+                       Interval rng = new Interval();\r
+                       var slider = new Psychlops.Widgets.Slider("Label", -100 <= rng <= 100);\r
+\r
+                       while (true)\r
+                       {\r
+                               cnvs.clear();\r
+                               for (int i = 0; i < n; i++)\r
+                               {\r
+                                       rect[i].centering().shift(slider * i*3, i*3).draw();\r
+                               }\r
+                               cnvs.flip();\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+*/
\ No newline at end of file