OSDN Git Service

xsdsz
[psychlops/silverlight.git] / test4 / PsychlopsMain.cs
1 \r
2 ///+ Prefix linkto BasicCode1\r
3 //// Lines for set up Psychlops environment\r
4 using Psychlops;\r
5 \r
6 namespace PsychlopsSilverlightApp\r
7 {\r
8 \r
9         public class PsychlopsMain\r
10         {///- Prefix linkto BasicCode1\r
11 \r
12 \r
13                 ///+ Main Routine\r
14                 //// Psychlops runs at the first line of this function psychlops_main().\r
15                 public void psychlops_main()\r
16                 {\r
17                         ///+ 0 Declaration\r
18                         ////Prepare global parameters\r
19                         Canvas window = new Canvas(Canvas.window);\r
20                         Image img;\r
21                         Rectangle centerrect = new Rectangle(10, 10);\r
22                         int imageHsize = 100;\r
23                         int imageVsize = 60;\r
24                         double R, G, B;\r
25                         ///- 0 Declaration\r
26 \r
27 \r
28 \r
29                         ///+ 1 Initialize\r
30                         ////Initialize image and set color to each pixel.\r
31                         img = new Image(imageHsize, imageVsize); //Allocate offscreen in main memory.\r
32                         Color col = new Color(0,0,0);\r
33                         for (int i = 0; i < imageHsize; i++)\r
34                         {\r
35                                 for (int j = 0; j < imageVsize; j++)\r
36                                 {\r
37                                         ///+ 1.1 set1\r
38                                         ////set colors for each pixels\r
39                                         R = Math.random(1.0) * 0.5; //Set R values. \r
40                                         G = Math.random(1.0) * 0.5; //Set G values.\r
41                                         B = Math.random(1.0) * 0.5; //Set B values. \r
42                                         col.set(R, G, B);\r
43                                         img.pix(i, j, col);\r
44                                         ///- 1.1 set1\r
45                                         centerrect.centering();\r
46                                 }\r
47                         }\r
48 \r
49                         //img.cache(); //Move offscreen from main memory to video RAM. (Optional)\r
50                         ///- 1 Initialize\r
51 \r
52                         ///+ 2 drawing\r
53                         ////drawing offscreen\r
54 \r
55                         while (!Keyboard.esc.pushed())\r
56                         {\r
57 \r
58                                 window.clear(Color.black); //Clear screen with black\r
59                                 img.centering(); //centering the position to copy offscreen\r
60                                 img.shift(100, 100); //centering the position to copy offscreen\r
61                                 img.draw(); // copy offscreen onto the reverse side of window buffer.\r
62                                 centerrect.draw(Color.red);// draw reference rectangle at the center.\r
63                                 window.flip();\r
64                         }\r
65                         ///- 2 drawing\r
66 \r
67                 }\r
68                 ///- Main Routine\r
69 \r
70         }\r
71 \r
72 }\r