Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.VisualBasic;
- using System;
- using System.Drawing;
- using System.Dynamic;
- using System.Reflection.Metadata;
- namespace WinFormsAppPr2
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private const int WWidth = 1280;
- private const int WHeight = 720;
- private const int XCenter = 640;
- private const int YCenter = 360;
- private Graphics graphics;
- private Figure original = new();
- private Figure figure = new();
- private Pen pen = new(Color.Black,3);
- private Point[] points =
- {
- new Point(XCenter + 100, YCenter),
- new Point(XCenter, YCenter - 100),
- new Point(XCenter, YCenter - 30),
- new Point(XCenter - 100, YCenter - 30),
- new Point(XCenter - 100, YCenter + 30),
- new Point(XCenter, YCenter + 30),
- new Point(XCenter, YCenter + 100),
- new Point(XCenter + 100, YCenter),
- };
- private Point[] FirstPoints =
- {
- new Point(XCenter + 100, YCenter),
- new Point(XCenter, YCenter - 100),
- new Point(XCenter, YCenter - 30),
- new Point(XCenter - 100, YCenter - 30),
- new Point(XCenter - 100, YCenter + 30),
- new Point(XCenter, YCenter + 30),
- new Point(XCenter, YCenter + 100),
- new Point(XCenter + 100, YCenter),
- };
- private Point[] TempPoints =
- {
- new Point(XCenter + 100, YCenter),
- new Point(XCenter, YCenter - 100),
- new Point(XCenter, YCenter - 30),
- new Point(XCenter - 100, YCenter - 30),
- new Point(XCenter - 100, YCenter + 30),
- new Point(XCenter, YCenter + 30),
- new Point(XCenter, YCenter + 100),
- new Point(XCenter + 100, YCenter),
- };
- public class Figure
- {
- public void DrawArrow(Graphics graphics, Pen pen, Point[] points)
- {
- graphics.DrawLines(pen, points);
- }
- }
- private void MoveXY(int x, int y)
- {
- for (int i = 0; i < 8; i++)
- {
- points[i].X += x;
- points[i].Y += y;
- }
- ClearScreen();
- figure.DrawArrow(graphics, pen, points);
- }
- private void ToMirrorByOX()
- {
- for (int i = 0; i < 8; i++)
- {
- points[i].Y = 2 * YCenter-points[i].Y;
- }
- ClearScreen();
- figure.DrawArrow(graphics, pen, points);
- }
- private void ToMirrorByOY()
- {
- for (int i = 0; i < 8; i++)
- {
- points[i].X = 2 * XCenter - points[i].X;
- }
- ClearScreen();
- figure.DrawArrow(graphics, pen, points);
- }
- private void ToMirrorByXY()
- {
- int temp;
- for (int i = 0; i < 8; i++)
- {
- temp = points[i].X;
- points[i].X = -points[i].Y + XCenter + YCenter;
- points[i].Y = -temp + XCenter + YCenter;
- }
- ClearScreen();
- figure.DrawArrow(graphics, pen, points);
- }
- private void ToScale(double x, double y)
- {
- for (int i = 0; i < 8; i++)
- {
- points[i].X = (int)Math.Round((points[i].X - XCenter) * x) + XCenter;
- points[i].Y = (int)Math.Round((points[i].Y - YCenter) * y) + YCenter;
- }
- ClearScreen();
- figure.DrawArrow(graphics, pen, points);
- }
- private void ToRotate(Point point, double val)
- {
- for (int i = 0; i < 8; i++)
- {
- points[i].X -= point.X;
- points[i].Y -= point.Y;
- TempPoints[i].X = (int)Math.Round(points[i].X * Math.Cos(val) - points[i].Y * Math.Sin(val)) + point.X;
- TempPoints[i].Y = (int)Math.Round(points[i].X * Math.Sin(val) + points[i].Y * Math.Cos(val)) + point.Y;
- }
- ClearScreen();
- figure.DrawArrow(graphics, pen, TempPoints);
- }
- private void ReturnToOriginal()
- {
- ClearScreen();
- figure.DrawArrow(graphics, pen, FirstPoints);
- Array.Copy(FirstPoints, 0, points, 0, FirstPoints.Length);
- }
- private void DrawGrid()
- {
- int offset = 20;
- int posX = 0;
- int posY = 0;
- while (posX < WWidth)
- {
- graphics.DrawLine(Pens.Gray, posX, posY, posX, WHeight);
- posX += offset;
- }
- posX = 0;
- while (posY < WHeight)
- {
- graphics.DrawLine(Pens.Gray, posX, posY, WWidth, posY);
- posY += offset;
- }
- Pen p = new Pen(Color.Black, 2);
- graphics.DrawLine(p, 0, WHeight / 2, WWidth, WHeight / 2);
- graphics.DrawLine(p, WWidth / 2, 0, WWidth / 2, WHeight);
- }
- private void ClearScreen()
- {
- graphics.Clear(BackColor);
- DrawGrid();
- }
- private void StartButton_Click(object sender, EventArgs e)
- {
- graphics = CreateGraphics();
- StartButton.Dispose();
- DrawGrid();
- original.DrawArrow(graphics, pen, points);
- }
- private void label1_Click(object sender, EventArgs e)
- {
- }
- private void buttonMove_Click(object sender, EventArgs e)
- {
- int newX = Convert.ToInt32(InputX.Text);
- int newY = -Convert.ToInt32(InputY.Text);
- MoveXY(newX, newY);
- }
- private void buttonRefOX_Click(object sender, EventArgs e)
- {
- ToMirrorByOX();
- }
- private void buttonRefOY_Click(object sender, EventArgs e)
- {
- ToMirrorByOY();
- }
- private void buttonRefXY_Click(object sender, EventArgs e)
- {
- ToMirrorByXY();
- }
- private void ToScaleClick(object sender, EventArgs e)
- {
- double SclX = Convert.ToDouble(ScaleX.Text);
- double SclY = Convert.ToDouble(ScaleY.Text);
- ToScale(SclX, SclY);
- }
- private void ToRotate_Click(object sender, EventArgs e)
- {
- Array.Copy(FirstPoints, 0, points, 0, FirstPoints.Length);
- double val = (Convert.ToDouble(AngleInput.Text) * Math.PI) / 180;
- int RotateX = Convert.ToInt32(XRotateInput.Text);
- int RotateY = Convert.ToInt32(YRotateInput.Text);
- Point RotationPoint = new Point(RotateX + XCenter, -RotateY + YCenter);
- ToRotate(RotationPoint, val);
- }
- private void ReturnToOrig_Click(object sender, EventArgs e)
- {
- ReturnToOriginal();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement