2 using System.Windows;
\r
3 using System.Windows.Controls;
\r
4 using System.Windows.Documents;
\r
5 using System.Windows.Input;
\r
6 using System.Windows.Media;
\r
7 using System.Windows.Media.Animation;
\r
8 using System.Windows.Media.Imaging;
\r
9 using System.Windows.Shapes;
\r
18 public double x, y, z;
\r
19 public Point(double dx, double dy, double dz)
\r
25 public Point(double dx, double dy)
\r
31 public Point set(double dx, double dy, double dz)
\r
38 public Point set(double dx, double dy)
\r
46 public static Point operator +(Point lhs, Point rhs)
\r
48 return new Point(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z);
\r
50 public static Point operator -(Point lhs, Point rhs)
\r
52 return new Point(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z);
\r
54 public static implicit operator System.Windows.Point(Point d)
\r
56 return new System.Windows.Point(d.x, d.y);
\r
63 public double r, g, b, a;
\r
64 public Color(double lum)
\r
69 public Color(double red, double green, double blue, double alpha)
\r
76 public static implicit operator System.Windows.Media.Color(Color d)
\r
78 return System.Windows.Media.Color.FromArgb((byte)(d.a * 255), (byte)(d.r * 255), (byte)(d.g * 255), (byte)(d.b * 255));
\r
81 public static readonly Color
\r
82 black = new Color(0, 0, 0, 1),
\r
83 red = new Color(1, 0, 0, 1),
\r
84 green = new Color(0, 1, 0, 1),
\r
85 blue = new Color(0, 0, 1, 1),
\r
86 yellow = new Color(1, 1, 0, 1),
\r
87 magenta = new Color(1, 0, 1, 1),
\r
88 cyan = new Color(0, 1, 1, 1),
\r
89 white = new Color(1, 1, 1, 1),
\r
90 gray = new Color(.5, .5, .5, 1);
\r
95 public interface Drawable
\r
98 void clear(Color col);
\r
99 void pix(int x, int y, Color col);
\r
100 void line(Line drawee, Color col);
\r
101 void rect(Rectangle drawee, Color col);
\r
102 void ellipse(Ellipse drawee, Color col);
\r
103 void image(Image drawee);
\r
104 void polygon(Polygon drawee, Color col);
\r
109 public interface Figure
\r
111 Figure shift(Point p);
\r
112 Figure centering(Point p);
\r
115 public static class FigureExtention
\r
117 public static Figure shift(this Figure target, double x, double y)
\r
119 return target.shift(new Point(x, y));
\r
121 public static Figure centering(this Figure target)
\r
123 return target.centering(Main.drawable.getCenter());
\r
129 public class Image : Figure
\r
131 public WriteableBitmap buffer;
\r
132 public Point datum;
\r
133 public Rectangle self_rect;
\r
135 public Image(int wid, int hei)
\r
137 buffer = new WriteableBitmap(wid, hei);
\r
138 self_rect = new Rectangle(wid, hei);
\r
141 /*public Image shift(double x, double y)
\r
147 public Figure shift(Point p)
\r
152 public Figure centering(Point p)
\r
154 datum.x = p.x - width / 2.0;
\r
155 datum.y = p.y - height / 2.0;
\r
159 public void pix(int x, int y, Color col)
\r
161 buffer.SetPixel(x, y, col);
\r
165 public void field(System.Func<int,int,System.Windows.Media.Color> func)
\r
167 buffer.ForEach(func);
\r
169 public void field(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)
\r
171 buffer.ForEach(func);
\r
176 Main.drawable.image(this);
\r
179 public double width { get { return self_rect.width; } }
\r
180 public double height { get { return self_rect.height; } }
\r