Advertisement
Schnuk

Untitled

Sep 18th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.66 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Drawing2D;
  4.  
  5. namespace RefactorMe
  6. {
  7.     class Painter
  8.     {
  9.         static float coordinateX, coordinateY;
  10.         static Graphics graphic;
  11.  
  12.         public static void Initialize(Graphics newGraphic)
  13.         {
  14.             graphic = newGraphic;
  15.             graphic.SmoothingMode = SmoothingMode.None;
  16.             graphic.Clear(Color.Black);
  17.         }
  18.  
  19.         public static void SetPosition(float startCoordinateX, float startCoordinateY)
  20.         {
  21.             coordinateX = startCoordinateX;
  22.             coordinateY = startCoordinateY;
  23.         }
  24.  
  25.         public static void DrawSquare(Pen pen, double length, double angle)
  26.         {
  27.             //Make a step long "lenght" in the direction of the corner "angle" and draw
  28.             var endCoordinateX = (float)(coordinateX + length * Math.Cos(angle));
  29.             var endCoordinateY = (float)(coordinateY + length * Math.Sin(angle));
  30.             graphic.DrawLine(pen, coordinateX, coordinateY, endCoordinateX, endCoordinateY);
  31.             coordinateX = endCoordinateX;
  32.             coordinateY = endCoordinateY;
  33.         }
  34.  
  35.         public static void ChangeEndCoordinate(double length, double angle)
  36.         {
  37.             coordinateX = (float)(coordinateX + length * Math.Cos(angle));
  38.             coordinateY = (float)(coordinateY + length * Math.Sin(angle));
  39.         }
  40.     }
  41.  
  42.     public class ImpossibleSquare
  43.     {
  44.         const float SizeSquare = 0.375f;
  45.         const float ThicknessSides = 0.04f;
  46.         const double DiagonalCoordinate = 2;
  47.         const float XCoordinate = 2f;
  48.         const float YCoordinate = 2f;
  49.  
  50.         public static void ChangeEndCoordinate (float size, double angleChangeFirst, double angleChangeSecond)
  51.         {
  52.             Painter.ChangeEndCoordinate(size * ThicknessSides, angleChangeFirst);
  53.             Painter.ChangeEndCoordinate(size * ThicknessSides * Math.Sqrt(2), angleChangeSecond);
  54.         }
  55.  
  56.         public static void DrawSides(Pen pen, float size, double angOne, double angTwo, double angThree, double angFour)
  57.         {
  58.             Painter.DrawSquare(pen, size * SizeSquare, angOne);
  59.             Painter.DrawSquare(pen, size * ThicknessSides * Math.Sqrt(2), angTwo);
  60.             Painter.DrawSquare(pen, size * SizeSquare, angThree);
  61.             Painter.DrawSquare(pen, size * SizeSquare - size * ThicknessSides, angFour);
  62.         }
  63.  
  64.         public static void Draw(int width, int height, double angleRotation, Graphics graphic)
  65.         {
  66.             //"angleRotation" is used later
  67.             Painter.Initialize(graphic);
  68.             var size = Math.Min(width, height);
  69.             var diagonalLength = Math.Sqrt(2) * (size * SizeSquare + size * ThicknessSides) / DiagonalCoordinate;
  70.             var startCoordinateX = (float)(diagonalLength * Math.Cos(5 * Math.PI / 4)) + width / XCoordinate;
  71.             var startCoordinateY = (float)(diagonalLength * Math.Sin(5 * Math.PI / 4)) + height / YCoordinate;
  72.  
  73.             Painter.SetPosition(startCoordinateX, startCoordinateY);
  74.  
  75.             DrawSides(Pens.Yellow, size, 0, Math.PI / 4, Math.PI, Math.PI / 2);
  76.             ChangeEndCoordinate(size, -Math.PI, 3 * Math.PI / 4);
  77.             DrawSides(Pens.Yellow, size, -Math.PI / 2, - Math.PI / 4, Math.PI / 2, 0);
  78.             ChangeEndCoordinate(size, -1.5 * Math.PI, Math.PI / 4);
  79.             DrawSides(Pens.Yellow, size, Math.PI, 5 * Math.PI / 4, 2 * Math.PI, 1.5 * Math.PI);
  80.             ChangeEndCoordinate(size, 0, 7 * Math.PI / 4);
  81.             DrawSides(Pens.Yellow, size, Math.PI / 2, 3 * Math.PI / 4, 1.5 * Math.PI, Math.PI);
  82.             ChangeEndCoordinate(size, -Math.PI / 2, 5 * Math.PI / 4);
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement