Advertisement
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 coordinateX, coordinateY;
- static Graphics graphic;
- public static void Initialize(Graphics newGraphic)
- {
- graphic = newGraphic;
- graphic.SmoothingMode = SmoothingMode.None;
- graphic.Clear(Color.Black);
- }
- public static void SetPosition(float startCoordinateX, float startCoordinateY)
- {
- coordinateX = startCoordinateX;
- coordinateY = startCoordinateY;
- }
- public static void DrawSquare(Pen pen, double length, double angle)
- {
- //Make a step long "lenght" in the direction of the corner "angle" and draw
- var endCoordinateX = (float)(coordinateX + length * Math.Cos(angle));
- var endCoordinateY = (float)(coordinateY + length * Math.Sin(angle));
- graphic.DrawLine(pen, coordinateX, coordinateY, endCoordinateX, endCoordinateY);
- coordinateX = endCoordinateX;
- coordinateY = endCoordinateY;
- }
- public static void ChangeEndCoordinate(double length, double angle)
- {
- coordinateX = (float)(coordinateX + length * Math.Cos(angle));
- coordinateY = (float)(coordinateY + length * Math.Sin(angle));
- }
- }
- public class ImpossibleSquare
- {
- const float SizeSquare = 0.375f;
- const float ThicknessSides = 0.04f;
- const double DiagonalCoordinate = 2;
- const float XCoordinate = 2f;
- const float YCoordinate = 2f;
- public static void ChangeEndCoordinate (float size, double angleChangeFirst, double angleChangeSecond)
- {
- Painter.ChangeEndCoordinate(size * ThicknessSides, angleChangeFirst);
- Painter.ChangeEndCoordinate(size * ThicknessSides * Math.Sqrt(2), angleChangeSecond);
- }
- public static void DrawSides(Pen pen, float size, double angOne, double angTwo, double angThree, double angFour)
- {
- Painter.DrawSquare(pen, size * SizeSquare, angOne);
- Painter.DrawSquare(pen, size * ThicknessSides * Math.Sqrt(2), angTwo);
- Painter.DrawSquare(pen, size * SizeSquare, angThree);
- Painter.DrawSquare(pen, size * SizeSquare - size * ThicknessSides, angFour);
- }
- public static void Draw(int width, int height, double angleRotation, Graphics graphic)
- {
- //"angleRotation" is used later
- Painter.Initialize(graphic);
- var size = Math.Min(width, height);
- var diagonalLength = Math.Sqrt(2) * (size * SizeSquare + size * ThicknessSides) / DiagonalCoordinate;
- var startCoordinateX = (float)(diagonalLength * Math.Cos(5 * Math.PI / 4)) + width / XCoordinate;
- var startCoordinateY = (float)(diagonalLength * Math.Sin(5 * Math.PI / 4)) + height / YCoordinate;
- Painter.SetPosition(startCoordinateX, startCoordinateY);
- DrawSides(Pens.Yellow, size, 0, Math.PI / 4, Math.PI, Math.PI / 2);
- ChangeEndCoordinate(size, -Math.PI, 3 * Math.PI / 4);
- DrawSides(Pens.Yellow, size, -Math.PI / 2, - Math.PI / 4, Math.PI / 2, 0);
- ChangeEndCoordinate(size, -1.5 * Math.PI, Math.PI / 4);
- DrawSides(Pens.Yellow, size, Math.PI, 5 * Math.PI / 4, 2 * Math.PI, 1.5 * Math.PI);
- ChangeEndCoordinate(size, 0, 7 * Math.PI / 4);
- DrawSides(Pens.Yellow, size, Math.PI / 2, 3 * Math.PI / 4, 1.5 * Math.PI, Math.PI);
- ChangeEndCoordinate(size, -Math.PI / 2, 5 * Math.PI / 4);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement