Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- namespace RefactorMe
- {
- class Painter
- {
- static float penСoordinateX, penСoordinateY;
- static Graphics graphics;
- public static void Initialize(Graphics newGraphics)
- {
- graphics = newGraphics;
- graphics.SmoothingMode = SmoothingMode.None;
- graphics.Clear(Color.Black);
- }
- public static void SetPosition(float x0, float y0)
- {
- penСoordinateX = x0;
- penСoordinateY = y0;
- }
- public static void Draw(Pen pen, double length, double angle)
- {
- //Делает шаг длиной length в направлении angle и рисует пройденную траекторию
- var x1 = (float)(penСoordinateX + length * Math.Cos(angle));
- var y1 = (float)(penСoordinateY + length * Math.Sin(angle));
- graphics.DrawLine(pen, penСoordinateX, penСoordinateY, x1, y1);
- penСoordinateX = x1;
- penСoordinateY = y1;
- }
- public static void ChangeСoordinatesPen(double length, double angle)
- {
- penСoordinateX = (float)(penСoordinateX + length * Math.Cos(angle));
- penСoordinateY = (float)(penСoordinateY + length * Math.Sin(angle));
- }
- }
- public class ImpossibleSquare
- {
- const float SizeWidth = 0.375f;
- const float FrameSize = 2f;
- const float SizeCornerLine = 0.04f;
- public static void DrawSide(double drawSize, double angle)
- {
- var penColor = Pens.Red;
- var drawingWidth = drawSize * SizeWidth;
- var cornerDrawingWidth = drawSize * SizeCornerLine;
- Painter.Draw(penColor, drawingWidth, angle);
- Painter.Draw(penColor, cornerDrawingWidth * Math.Sqrt(2), angle + Math.PI / 4);
- Painter.Draw(penColor, drawingWidth, angle + Math.PI);
- Painter.Draw(penColor, drawingWidth - cornerDrawingWidth, angle + Math.PI / 2);
- Painter.ChangeСoordinatesPen(cornerDrawingWidth, angle + Math.PI);
- Painter.ChangeСoordinatesPen(cornerDrawingWidth * Math.Sqrt(2), angle + 3 * Math.PI / 4);
- }
- public static void Draw(int width, int height, double angleRotate, Graphics graphics)
- {
- Painter.Initialize(graphics);
- var minSide = Math.Min(width, height);
- var diagonalLength = Math.Sqrt(2) * (minSide * (SizeWidth + SizeCornerLine)) / 2;
- var x0 = (float)(diagonalLength * Math.Cos(5 * Math.PI / 4)) + width / FrameSize;
- var y0 = (float)(diagonalLength * Math.Sin(5 * Math.PI / 4)) + height / FrameSize;
- //var radius = (float)diagonalLength/2;
- Painter.SetPosition(x0, y0);
- DrawSide(minSide, 0 + angleRotate);
- DrawSide(minSide, -Math.PI / 2 + angleRotate);
- DrawSide(minSide, Math.PI + angleRotate);
- DrawSide(minSide, Math.PI / 2 + angleRotate);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment