using System; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace Psychlops { public struct Point { public double x, y, z; public Point(double dx, double dy, double dz) { x = dx; y = dy; z = dz; } public Point(double dx, double dy) { x = dx; y = dy; z = 0.0; } public Point set(double dx, double dy, double dz) { x = dx; y = dy; z = dz; return this; } public Point set(double dx, double dy) { x = dx; y = dy; z = 0.0; return this; } public static Point operator +(Point lhs, Point rhs) { return new Point(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z); } public static Point operator -(Point lhs, Point rhs) { return new Point(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z); } public static implicit operator System.Windows.Point(Point d) { return new System.Windows.Point(d.x, d.y); } } public struct Color { public double r, g, b, a; public Color(double lum) { r = g = b = lum; a = 1.0; } public Color(double red, double green, double blue) { r = red; g = green; b = blue; a = 1.0; } public Color(double red, double green, double blue, double alpha) { r = red; g = green; b = blue; a = alpha; } public void set(double lum) { r = g = b = lum; a = 1.0; } public void set(double red, double green, double blue) { r = red; g = green; b = blue; a = 1.0; } public void set(double red, double green, double blue, double alpha) { r = red; g = green; b = blue; a = alpha; } public static implicit operator System.Windows.Media.Color(Color d) { return System.Windows.Media.Color.FromArgb((byte)(d.a * 255), (byte)(d.r * 255), (byte)(d.g * 255), (byte)(d.b * 255)); } public static readonly Color black = new Color(0, 0, 0, 1), red = new Color(1, 0, 0, 1), green = new Color(0, 1, 0, 1), blue = new Color(0, 0, 1, 1), yellow = new Color(1, 1, 0, 1), magenta = new Color(1, 0, 1, 1), cyan = new Color(0, 1, 1, 1), white = new Color(1, 1, 1, 1), gray = new Color(.5, .5, .5, 1); } public interface Drawable { Point getCenter(); void clear(Color col); void pix(int x, int y, Color col); void line(Line drawee, Color col); void rect(Rectangle drawee, Color col); void ellipse(Ellipse drawee, Color col); void polygon(Polygon drawee, Color col); void letters(Letters drawee, Color col); void image(Image drawee); void msg(string s, double x, double y, Color c); } public interface Figure { Figure shift(Point p); Figure centering(Point p); void draw(); } public static class FigureExtention { public static Figure shift(this Figure target, double x, double y) { return target.shift(new Point(x, y)); } public static Figure centering(this Figure target) { return target.centering(Main.drawable.getCenter()); } public static Figure centering(this Figure target, double x, double y) { return target.centering(new Point(x, y)); } } public class Image : Figure { public WriteableBitmap buffer; public Point datum; public Rectangle self_rect; public Image(int wid, int hei) { buffer = new WriteableBitmap(wid, hei); self_rect = new Rectangle(wid, hei); } /*public Image shift(double x, double y) { datum.x += x; datum.y += y; return this; }*/ public Figure shift(Point p) { datum += p; return this; } public Figure centering(Point p) { datum.x = p.x - width / 2.0; datum.y = p.y - height / 2.0; return this; } public void pix(int x, int y, Color col) { buffer.SetPixel(x, y, col); } public void field(System.Func func) { buffer.ForEach(func); } public void field(System.Func func) { buffer.ForEach(func); } public void draw() { Main.drawable.image(this); } public double width { get { return self_rect.width; } } public double height { get { return self_rect.height; } } } }