OSDN Git Service

6d512f6f9f72461f11312a2209de7c7212324046
[psychlops/silverlight.git] / dev3 / psychlops / extention / standard / figures.cs
1 namespace Psychlops\r
2 {\r
3 \r
4     public static class Figures\r
5     {\r
6         /*\r
7             public static void drawGrating(out Image img, int width , int height, double frequency, double contrast, double orientation, double phase)\r
8             {\r
9                     if(img.width != width || img.height != height) img = new Image(width, height);\r
10                     double xp, yp, r, freq = frequency*2*PI;\r
11                     for(int y=0; y<height; y++) {\r
12                             yp = y-height/2.0;\r
13                             for(int x=0; x<width; x++) {\r
14                                     xp = x-width/2.0;\r
15                                     r = sqrt(xp*xp+yp*yp);\r
16                                     img.pix_raw(x,y,\r
17                                       Color(\r
18                                             0.5+0.5 * contrast* cos(freq* (sin(orientation)*xp-cos(orientation)*yp) + phase)\r
19                                       )\r
20                                     );\r
21                             }\r
22                     }\r
23             }\r
24 \r
25         public static void drawGaussian(out Image img, double sigma, double factor)\r
26             {\r
27             const int width = (int)(sigma * 8), height = (int)(sigma * 8);\r
28             if (img.width != width || img.height != height) img = new Image(width, height);\r
29             double xp, yp, r, r2;\r
30                     for(int y=0; y<height; y++) {\r
31                             yp = y-height/2.0;\r
32                             for(int x=0; x<width; x++) {\r
33                                     xp = x-width/2.0;\r
34                                     r = sqrt(xp*xp+yp*yp);\r
35                                     r2 = -(r*r) / (2.0*sigma*sigma);\r
36                                     img.pix_raw(x,y,Color(factor*(exp(r2))));\r
37                             }\r
38                     }\r
39             }\r
40          * */\r
41 \r
42         public static void drawGabor(out Image img, double sigma, double wavelength, double contrast, double orientation, double phase)\r
43             {\r
44             int width = (int)(sigma * 8), height = (int)(sigma * 8);\r
45             //if (img.width != width || img.height != height)\r
46                 img = new Image(width, height);\r
47             double freq = 2 * Math.PI / wavelength;\r
48                         img.field(\r
49                 (x, y) => new Color(.5 + Math.gaussian(Math.radius(x - width, y - height), width / 8.0) * .5 * Math.sin(phase + x * freq))\r
50                         );\r
51             }\r
52 \r
53     }\r
54 }\r