OSDN Git Service

xsdsz
[psychlops/silverlight.git] / test4 / PsychlopsMain.cs
index 32ba5e8..859b016 100644 (file)
 \r
+///+ Prefix linkto BasicCode1\r
+//// Lines for set up Psychlops environment\r
 using Psychlops;\r
 \r
-namespace PsychlopsSilverlight4test\r
+namespace PsychlopsSilverlightApp\r
 {\r
+\r
        public class PsychlopsMain\r
-       {\r
-               public void psychlops_main()\r
-               {\r
-                       var figure_type = Psychlops.Widgets.Browser.Element.byID("FIGURE");\r
-                       var size_x = Psychlops.Widgets.Browser.Element.byID("SIZE_X");\r
-                       var size_y = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");\r
-                       var shift_x = Psychlops.Widgets.Browser.Element.byID("SHIFT_X");\r
-                       var shift_y = Psychlops.Widgets.Browser.Element.byID("SHIFT_Y");\r
-                       var color_r = Psychlops.Widgets.Browser.Element.byID("COLOR_R");\r
-                       var color_g = Psychlops.Widgets.Browser.Element.byID("COLOR_G");\r
-                       var color_b = Psychlops.Widgets.Browser.Element.byID("COLOR_B");\r
+       {///- Prefix linkto BasicCode1\r
 \r
-                       Canvas window = new Canvas(300, 300);\r
 \r
-                       var figure_r = new Rectangle();\r
-                       var figure_e = new Ellipse();\r
-                       Shape figure = figure_r;\r
-                       \r
-                       while (!Keyboard.esc.pushed())\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
                        {\r
-                               if (System.String.Compare(figure_type, "Rectangle") == 0)\r
+                               for (int j = 0; j < imageVsize; j++)\r
                                {\r
-                                       figure_r.set(size_x, size_y);\r
-                                       figure = figure_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
                                }\r
-                               else\r
-                               {\r
-                                       figure_e.set(size_x, size_y);\r
-                                       figure = figure_e;\r
-                               }\r
-                               figure.fill = new Color(color_r, color_g, color_b);\r
-\r
-                               window.clear(Color.black);\r
-                               figure.centering().shift(shift_x, shift_y).draw();\r
-                               window.flip();\r
                        }\r
-               }\r
-       }\r
 \r
-}\r
+                       //img.cache(); //Move offscreen from main memory to video RAM. (Optional)\r
+                       ///- 1 Initialize\r
 \r
+                       ///+ 2 drawing\r
+                       ////drawing offscreen\r
 \r
-\r
-/*\r
-using Psychlops;\r
-\r
-namespace Psychlops\r
-{\r
-\r
-       public class RandomDots\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
-                       dot.fill = Color.white;\r
-                       foreach (Point p in cood)\r
+                       while (!Keyboard.esc.pushed())\r
                        {\r
-                               dot.centering(p).draw();\r
-                       }\r
-               }\r
-       }\r
 \r
-}\r
-\r
-\r
-namespace PsychlopsSilverlight4test\r
-{\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
-                               {\r
-                                       dots.cood[i].set(Math.random(500), Math.random(500));\r
-                               }\r
-                               dots.draw();\r
-\r
-                               cnvs.flip();\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
                        }\r
+                       ///- 2 drawing\r
+\r
                }\r
+               ///- Main Routine\r
+\r
        }\r
 \r
 }\r
-*/
\ No newline at end of file