OSDN Git Service

948aecc964ff8a47cd3b76cd3f62f5164bc071f4
[psychlops/silverlight.git] / dev5 / psychlops / extention / standard / figures.cs
1 \r
2 using System.Windows.Media.Imaging;\r
3 namespace Psychlops\r
4 {\r
5 \r
6     public static partial class Figures\r
7     {\r
8 \r
9                 public static void drawGrating(ref Image img, int width, int height, double wavelength, double contrast, double orientation, double phase)\r
10             {\r
11                         double width_half = width / 2.0, height_half = height / 2.0;\r
12             if (img==null || img.width != width || img.height != height)\r
13                 img = new Image(width, height);\r
14             double freq = 2 * Math.PI / wavelength;\r
15                         img.field(\r
16                                 (x, y) => new Color(.5 + contrast * .5 * Math.sin(phase + (Math.sin(orientation)*x-Math.cos(orientation)*y) * freq))\r
17                         );\r
18             }\r
19                 public static void drawGaussian(ref Image img, double sigma, double factor)\r
20                 {\r
21                         int width = (int)(sigma * 8), height = (int)(sigma * 8);\r
22                         double width_half = width / 2.0, height_half = height / 2.0;\r
23                         if (img == null || img.width != width || img.height != height)\r
24                                 img = new Image(width, height);\r
25                         img.field(\r
26                                 (x, y) => new Color(factor * Math.gaussian(Math.radius(x - width_half, y - height_half), width / 8.0))\r
27                         );\r
28                 }\r
29 \r
30                 public static void drawGabor(ref Image img, double sigma, double frequency, double contrast, double orientation, double phase)\r
31             {\r
32             int width = (int)(sigma * 8), height = (int)(sigma * 8);\r
33                         double width_half = width / 2.0, height_half = height / 2.0;\r
34             if (img==null || img.width != width || img.height != height)\r
35                 img = new Image(width, height);\r
36             double freq = 2 * Math.PI * frequency;\r
37                         img.field(\r
38                                 (x, y) => new Color(.5 + contrast * Math.gaussian(Math.radius(x - width_half, y - height_half), width / 8.0) * .5 * Math.sin(phase + (Math.sin(orientation) * x - Math.cos(orientation) * y) * freq))\r
39                         );\r
40             }\r
41 \r
42     }\r
43 }\r