OSDN Git Service

dasdsa
authorunknown <hskwk@.(none)>
Thu, 26 Aug 2010 07:16:40 +0000 (16:16 +0900)
committerunknown <hskwk@.(none)>
Thu, 26 Aug 2010 07:16:40 +0000 (16:16 +0900)
dev4/psychlops/core/graphic/module.cs
test4/PsychlopsMain.cs

index db366c1..6adecfd 100644 (file)
@@ -4,6 +4,48 @@ using System.Windows;
 \r
 namespace Psychlops\r
 {\r
+       public static class StaticFunctions\r
+       {\r
+               public static T[] NewArray<T>(int x)\r
+                       where T : new()\r
+               {\r
+                       T[] t = new T[x];\r
+                       for (int i = 0; i < x; i++)\r
+                       {\r
+                               t[i] = new T();\r
+                       }\r
+                       return t;\r
+               }\r
+               public static T[,] NewArray<T>(int x, int y)\r
+                       where T : new()\r
+               {\r
+                       T[,] t = new T[x,y];\r
+                       for (int i = 0; i < x; i++)\r
+                       {\r
+                               for (int j = 0; j < x; j++)\r
+                               {\r
+                                       t[i,j] = new T();\r
+                               }\r
+                       }\r
+                       return t;\r
+               }\r
+               public static T[,,] NewArray<T>(int x, int y, int z)\r
+                       where T : new()\r
+               {\r
+                       T[,,] t = new T[x, y, z];\r
+                       for (int i = 0; i < x; i++)\r
+                       {\r
+                               for (int j = 0; j < y; j++)\r
+                               {\r
+                                       for (int k = 0; k < z; k++)\r
+                                       {\r
+                                               t[i, j, k] = new T();\r
+                                       }\r
+                               }\r
+                       }\r
+                       return t;\r
+               }\r
+       }\r
 \r
        public partial struct Point\r
        {\r
index 8b16867..bc1169f 100644 (file)
@@ -11,83 +11,87 @@ namespace PsychlopsSilverlight4test
 \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 = Rectangle.Array(maxrectnum);\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 linkto BasicCode3_2a\r
-    ////Prepare variables for movie control;\r
-    int frame=0;\r
-    int motion_dir=1;\r
-    double Horizontal_shift, Vertical_shift;\r
-    ///- 2.1 linkto BasicCode3_2a\r
-\r
-    while(!Keyboard.esc.pushed()){\r
-        window.clear(Color.black);\r
-        for(int i=0; i < rectnum; i++){\r
-         ///+ 2.2 loopset1\r
-         ////set positions and sizes\r
-\r
-         Horizontal_shift=Math.sin(2 * Math.PI * ((double)frame / 30.0/*ID:Period_HPosition 30 240 30*/))*motion_dir * 100.0/*ID:HSpeed 0.0 100.0 10.0*/; //Calculate horizontal displacement from the center.\r
-         Vertical_shift=Math.sin(2 * Math.PI * ((double)frame / 30.0/*ID:Period_HPosition 30 240 30*/))*motion_dir * 0.0/*ID:VSpeed 0.0 100.0 10.0*/;//Calculate vertical displacement from the center.\r
-         rect[i].resize(rectsize, rectsize); //Resize rectangles.\r
-         rect[i].centering(); //Rectangles are moved to the center...\r
-         rect[i].shift(Horizontal_shift + (i-0.5*rectnum) * rectsize * 1.5/*ID:RectHGap 1.0 3.0 0.5*/,\r
-                       Vertical_shift + (i-0.5*rectnum)  *rectsize * 1.5/*ID:RectVGap 1.0 3.0 0.5*/); //and then move to designated positions\r
-         ///- 2.2 loopset1\r
-\r
-         ///+ 2.3 linkto BasicCode3_2a\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 linkto BasicCode3_2a\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
-        frame++;\r
-    }\r
-    ///- 2 drawing\r
+               public void psychlops_main()\r
+               {\r
+                       ///+ 0 linkto BasicCode3_1a\r
+                       ////Prepare global parameters\r
+                       int maxrectnum = 200;\r
+                       int rectnum = 100;\r
+                       double rectsize = 5.0;\r
+                       Rectangle[] rect = StaticFunctions.NewArray<Rectangle>(maxrectnum);\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
+                       {\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,\r
+                                                                                          (i - 0.5 * rectnum) * rectsize * 1.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; //Set R values. Note that "i" is converted to double-type.\r
+                               rectcolorG[i] = Math.random(1.0) * 0.5; //Set G values. Note that "i" is converted to double-type.\r
+                               rectcolorB[i] = Math.random(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
-}\r
-               ///- Main Routine\r
+                       ///+ 2 drawing\r
+                       ////drawing objects\r
+                       ///+ 2.1 linkto BasicCode3_2a\r
+                       ////Prepare variables for movie control;\r
+                       int frame = 0;\r
+                       int motion_dir = 1;\r
+                       double Horizontal_shift, Vertical_shift;\r
+                       ///- 2.1 linkto BasicCode3_2a\r
 \r
+                       while (!Keyboard.esc.pushed())\r
+                       {\r
+                               window.clear(Color.black);\r
+                               for (int i = 0; i < rectnum; i++)\r
+                               {\r
+                                       ///+ 2.2 loopset1\r
+                                       ////set positions and sizes\r
+\r
+                                       Horizontal_shift = Math.sin(2 * Math.PI * ((double)frame / 30.0)) * motion_dir * 100.0; //Calculate horizontal displacement from the center.\r
+                                       Vertical_shift = Math.sin(2 * Math.PI * ((double)frame / 30.0)) * motion_dir * 0.0;//Calculate vertical displacement from the center.\r
+                                       rect[i].resize(rectsize, rectsize); //Resize rectangles.\r
+                                       rect[i].centering(); //Rectangles are moved to the center...\r
+                                       rect[i].shift(Horizontal_shift + (i - 0.5 * rectnum) * rectsize * 1.5,\r
+                                                                 Vertical_shift + (i - 0.5 * rectnum) * rectsize * 1.5); //and then move to designated positions\r
+                                       ///- 2.2 loopset1\r
+\r
+                                       ///+ 2.3 linkto BasicCode3_2a\r
+                                       ////set colors \r
+                                       rectcolorR[i] = Math.random(1.0) * 0.5; //Set R values. Note that "i" is converted to double-type.\r
+                                       rectcolorG[i] = Math.random(1.0) * 0.5; //Set G values. Note that "i" is converted to double-type.\r
+                                       rectcolorB[i] = Math.random(1.0) * 0.5; //Set B values. Note that "i" is converted to double-type.\r
+                                       ///- 2.3 linkto BasicCode3_2a\r
+\r
+                               }\r
+                               ///+ 2.4 linkto BasicCode3_1a\r
+                               for (int i = 0; i < rectnum; i++)\r
+                               {\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
+                               frame++;\r
+                       }\r
+                       ///- 2 drawing\r
+\r
+               }\r
+               ///- Main Routine\r
 \r
 \r
        }\r
@@ -96,6 +100,8 @@ namespace PsychlopsSilverlight4test
 \r
 \r
 \r
+\r
+\r
 /*\r
 using Psychlops;\r
 \r