using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing; namespace Zelvaci { class Zelvak{ private Graphics g; private Image img; private int angle = -90; private PointF pt; private Pen pen; private int width; private Color color; public Zelvak(int width, int height) { img = new Bitmap(width, height); g = Graphics.FromImage(img); g.FillRectangle(Brushes.White, 0, 0, width, height); pt = new PointF(width/2f, height/2f); color = System.Drawing.Color.Black; } public void Left(int angle) { this.angle = this.angle - angle; while (this.angle < 0) this.angle += 360; this.angle %= 360; } public void Right(int angle) { Left(-angle); } public void Pen(int width) { if (width <= 0) pen = null; else { this.width = width; pen = new Pen(color, width); } } public bool IsPen(){ return pen != null; } public void Forward(int steps) { PointF next = new PointF(pt.X + steps * (float)Math.Cos(ToRadians(angle)), pt.Y + steps * (float)Math.Sin(ToRadians(angle))); if (IsPen()) g.DrawLine(pen, pt, next); pt = next; } public void Color(int red, int green, int blue) { this.color = System.Drawing.Color.FromArgb(red, green, blue); pen = new Pen(color, width); } private float ToRadians(int angle) { return ((float)angle) * 0.017453292519943295769111452467007f; } public Image GetImage() { return img; } } }