Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Diagnostics;
- namespace lab2
- {
- public partial class Form1 : Form
- {
- Point center = new Point(400, 300);
- PointF[] P = new PointF[4];
- Random r = new Random();
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- double w = 600;
- double h = 300;
- int a = 0;
- Random r = new Random();
- drawRectangle(w, h, 0,true);
- for (int i = 0; i < 3; i++)
- {
- w = w / 1.3;
- h = h / 1.3;
- drawRectangle(w, h, r.Next(0, 181),false);
- }
- }
- public void drawRectangle(double Width, double Height, int A, bool pre_defined)
- {
- Graphics g = pictureBox1.CreateGraphics();
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
- g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
- System.Drawing.Brush brush = new System.Drawing.SolidBrush(Color.FromArgb(r.Next(0, 251), r.Next(0, 251), r.Next(0, 251)));
- Pen myPen = new Pen(brush, 2);
- myPen.Width = 2;
- int x = center.X;
- int y = center.Y;
- //top left
- P[0] = new PointF((float)Math.Round(x + (Width / 2) * Math.Cos(A) + (Height / 2) * Math.Sin(A)), (float)Math.Round(y - (Height / 2) * Math.Cos(A) + (Width / 2) * Math.Sin(A)));
- //top right
- P[1] = new PointF((float)Math.Round(x - (Width / 2) * Math.Cos(A) + (Height / 2) * Math.Sin(A)), (float)Math.Round(y - (Height / 2) * Math.Cos(A) - (Width / 2) * Math.Sin(A)));
- //bottom left
- P[2] = new PointF((float)Math.Round(x + (Width / 2) * Math.Cos(A) - (Height / 2) * Math.Sin(A)), (float)Math.Round(y + (Height / 2) * Math.Cos(A) + (Width / 2) * Math.Sin(A)));
- //bottom right
- P[3] = new PointF((float)Math.Round(x - (Width / 2) * Math.Cos(A) - (Height / 2) * Math.Sin(A)), (float)Math.Round(y + (Height / 2) * Math.Cos(A) - (Width / 2) * Math.Sin(A)));
- g.DrawLine(myPen, P[0], P[1]);
- g.DrawLine(myPen, P[1], P[3]);
- g.DrawLine(myPen, P[3], P[2]);
- g.DrawLine(myPen, P[2], P[0]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement