From 246587bb4cb0291fa3ee3ec8ed377d4234a6d1af Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 26 Aug 2010 16:16:40 +0900 Subject: [PATCH] dasdsa --- dev4/psychlops/core/graphic/module.cs | 42 +++++++++ test4/PsychlopsMain.cs | 156 ++++++++++++++++++---------------- 2 files changed, 123 insertions(+), 75 deletions(-) diff --git a/dev4/psychlops/core/graphic/module.cs b/dev4/psychlops/core/graphic/module.cs index db366c1..6adecfd 100644 --- a/dev4/psychlops/core/graphic/module.cs +++ b/dev4/psychlops/core/graphic/module.cs @@ -4,6 +4,48 @@ using System.Windows; namespace Psychlops { + public static class StaticFunctions + { + public static T[] NewArray(int x) + where T : new() + { + T[] t = new T[x]; + for (int i = 0; i < x; i++) + { + t[i] = new T(); + } + return t; + } + public static T[,] NewArray(int x, int y) + where T : new() + { + T[,] t = new T[x,y]; + for (int i = 0; i < x; i++) + { + for (int j = 0; j < x; j++) + { + t[i,j] = new T(); + } + } + return t; + } + public static T[,,] NewArray(int x, int y, int z) + where T : new() + { + T[,,] t = new T[x, y, z]; + for (int i = 0; i < x; i++) + { + for (int j = 0; j < y; j++) + { + for (int k = 0; k < z; k++) + { + t[i, j, k] = new T(); + } + } + } + return t; + } + } public partial struct Point { diff --git a/test4/PsychlopsMain.cs b/test4/PsychlopsMain.cs index 8b16867..bc1169f 100644 --- a/test4/PsychlopsMain.cs +++ b/test4/PsychlopsMain.cs @@ -11,83 +11,87 @@ namespace PsychlopsSilverlight4test ///+ Main Routine //// Psychlops runs at the first line of this function psychlops_main(). - public void psychlops_main() { - ///+ 0 linkto BasicCode3_1a - ////Prepare global parameters - const int maxrectnum = 200; - int rectnum = 100/*ID:rectnumber 25.0 200.0 25.0*/; - double rectsize = 5.0/*ID:dotsize 1.0 10.0 1.0*/; - Rectangle[] rect = Rectangle.Array(maxrectnum); - double[] rectcolorR = new double[maxrectnum]; - double[] rectcolorG = new double[maxrectnum]; - double[] rectcolorB = new double[maxrectnum]; - ///- 0 linkto BasicCode3_1a - - Canvas window = new Canvas(Canvas.window); - - ///+ 1 linkto BasicCode3_1a - ////Initialize - for(int i=0; i < rectnum; i++){ - ///+ 1.1 set1 - ////set positions and sizes - rect[i].set(rectsize, rectsize); //Set a size of rectangles. - rect[i].centering(); - rect[i].shift((i - 0.5 *rectnum) * rectsize* 1.5/*ID:RectHGap 1.0 3.0 0.5*/, - (i-0.5*rectnum) * rectsize * 1.5/*ID:RectVGap 1.0 3.0 0.5*/); //Move Rectangles to initial positions - ///- 1.1 set1 - ///+ 1.2 set2 - ////set colors - 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. - 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. - 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. - ///- 1.2 set2 - } - ///- 1 linkto BasicCode3_1a - - ///+ 2 drawing - ////drawing objects - ///+ 2.1 linkto BasicCode3_2a - ////Prepare variables for movie control; - int frame=0; - int motion_dir=1; - double Horizontal_shift, Vertical_shift; - ///- 2.1 linkto BasicCode3_2a - - while(!Keyboard.esc.pushed()){ - window.clear(Color.black); - for(int i=0; i < rectnum; i++){ - ///+ 2.2 loopset1 - ////set positions and sizes - - 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. - 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. - rect[i].resize(rectsize, rectsize); //Resize rectangles. - rect[i].centering(); //Rectangles are moved to the center... - rect[i].shift(Horizontal_shift + (i-0.5*rectnum) * rectsize * 1.5/*ID:RectHGap 1.0 3.0 0.5*/, - Vertical_shift + (i-0.5*rectnum) *rectsize * 1.5/*ID:RectVGap 1.0 3.0 0.5*/); //and then move to designated positions - ///- 2.2 loopset1 - - ///+ 2.3 linkto BasicCode3_2a - ////set colors - 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. - 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. - 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. - ///- 2.3 linkto BasicCode3_2a - - } - ///+ 2.4 linkto BasicCode3_1a - for(int i=0; i < rectnum; i++){ - rect[i].draw(new Color(rectcolorR[i], rectcolorG[i], rectcolorB[i])); //draw objects by designated colors. - } - window.flip(); - ///- 2.4 linkto BasicCode3_1a - frame++; - } - ///- 2 drawing + public void psychlops_main() + { + ///+ 0 linkto BasicCode3_1a + ////Prepare global parameters + int maxrectnum = 200; + int rectnum = 100; + double rectsize = 5.0; + Rectangle[] rect = StaticFunctions.NewArray(maxrectnum); + double[] rectcolorR = new double[maxrectnum]; + double[] rectcolorG = new double[maxrectnum]; + double[] rectcolorB = new double[maxrectnum]; + ///- 0 linkto BasicCode3_1a + + Canvas window = new Canvas(Canvas.window); + + ///+ 1 linkto BasicCode3_1a + ////Initialize + for (int i = 0; i < rectnum; i++) + { + ///+ 1.1 set1 + ////set positions and sizes + rect[i].set(rectsize, rectsize); //Set a size of rectangles. + rect[i].centering(); + rect[i].shift((i - 0.5 * rectnum) * rectsize * 1.5, + (i - 0.5 * rectnum) * rectsize * 1.5); //Move Rectangles to initial positions + ///- 1.1 set1 + ///+ 1.2 set2 + ////set colors + rectcolorR[i] = Math.random(1.0) * 0.5; //Set R values. Note that "i" is converted to double-type. + rectcolorG[i] = Math.random(1.0) * 0.5; //Set G values. Note that "i" is converted to double-type. + rectcolorB[i] = Math.random(1.0) * 0.5; //Set B values. Note that "i" is converted to double-type. + ///- 1.2 set2 + } + ///- 1 linkto BasicCode3_1a -} - ///- Main Routine + ///+ 2 drawing + ////drawing objects + ///+ 2.1 linkto BasicCode3_2a + ////Prepare variables for movie control; + int frame = 0; + int motion_dir = 1; + double Horizontal_shift, Vertical_shift; + ///- 2.1 linkto BasicCode3_2a + while (!Keyboard.esc.pushed()) + { + window.clear(Color.black); + for (int i = 0; i < rectnum; i++) + { + ///+ 2.2 loopset1 + ////set positions and sizes + + Horizontal_shift = Math.sin(2 * Math.PI * ((double)frame / 30.0)) * motion_dir * 100.0; //Calculate horizontal displacement from the center. + Vertical_shift = Math.sin(2 * Math.PI * ((double)frame / 30.0)) * motion_dir * 0.0;//Calculate vertical displacement from the center. + rect[i].resize(rectsize, rectsize); //Resize rectangles. + rect[i].centering(); //Rectangles are moved to the center... + rect[i].shift(Horizontal_shift + (i - 0.5 * rectnum) * rectsize * 1.5, + Vertical_shift + (i - 0.5 * rectnum) * rectsize * 1.5); //and then move to designated positions + ///- 2.2 loopset1 + + ///+ 2.3 linkto BasicCode3_2a + ////set colors + rectcolorR[i] = Math.random(1.0) * 0.5; //Set R values. Note that "i" is converted to double-type. + rectcolorG[i] = Math.random(1.0) * 0.5; //Set G values. Note that "i" is converted to double-type. + rectcolorB[i] = Math.random(1.0) * 0.5; //Set B values. Note that "i" is converted to double-type. + ///- 2.3 linkto BasicCode3_2a + + } + ///+ 2.4 linkto BasicCode3_1a + for (int i = 0; i < rectnum; i++) + { + rect[i].draw(new Color(rectcolorR[i], rectcolorG[i], rectcolorB[i])); //draw objects by designated colors. + } + window.flip(); + ///- 2.4 linkto BasicCode3_1a + frame++; + } + ///- 2 drawing + + } + ///- Main Routine } @@ -96,6 +100,8 @@ namespace PsychlopsSilverlight4test + + /* using Psychlops; -- 2.11.0