Advertisement
Guest User

Untitled

a guest
Nov 12th, 2012
813
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Diagnostics;
  11.  
  12. namespace lab2
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         Point center = new Point(400, 300);
  17.         PointF[] P = new PointF[4];
  18.         Random r = new Random();
  19.  
  20.         public Form1()
  21.         {
  22.             InitializeComponent();
  23.         }
  24.  
  25.         private void button1_Click(object sender, EventArgs e)
  26.         {
  27.             double w = 600;
  28.             double h = 300;
  29.             int a = 0;
  30.             Random r = new Random();
  31.             drawRectangle(w, h, 0,true);
  32.  
  33.             for (int i = 0; i < 3; i++)
  34.             {
  35.                 w = w / 1.3;
  36.                 h = h / 1.3;
  37.                 drawRectangle(w, h, r.Next(0, 181),false);
  38.             }
  39.  
  40.         }
  41.  
  42.         public void drawRectangle(double Width, double Height, int A, bool pre_defined)
  43.         {
  44.             Graphics g = pictureBox1.CreateGraphics();
  45.             g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  46.             g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
  47.            
  48.             System.Drawing.Brush brush = new System.Drawing.SolidBrush(Color.FromArgb(r.Next(0, 251), r.Next(0, 251), r.Next(0, 251)));
  49.             Pen myPen = new Pen(brush, 2);
  50.             myPen.Width = 2;
  51.             int x = center.X;
  52.             int y = center.Y;
  53.             //top left
  54.             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)));
  55.             //top right
  56.             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)));
  57.             //bottom left
  58.             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)));
  59.             //bottom right
  60.             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)));
  61.  
  62.  
  63.             g.DrawLine(myPen, P[0], P[1]);
  64.             g.DrawLine(myPen, P[1], P[3]);
  65.             g.DrawLine(myPen, P[3], P[2]);
  66.             g.DrawLine(myPen, P[2], P[0]);
  67.  
  68.  
  69.  
  70.         }
  71.  
  72.  
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement