Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.58 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;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace _06_Hodiny
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         Thread thread;
  17.         Graphics graphics01;
  18.         Graphics graphics02;
  19.         Bitmap bitmap;
  20.  
  21.         bool drawing = true;
  22.  
  23.         public Form1()
  24.         {
  25.             InitializeComponent();
  26.         }
  27.  
  28.         private void Form1_Load(object sender, EventArgs e)
  29.         {
  30.             bitmap = new Bitmap(580, 580);
  31.             graphics01 = Graphics.FromImage(bitmap);
  32.             graphics02 = CreateGraphics();
  33.             thread = new Thread(Draw);
  34.             thread.IsBackground = true;
  35.             thread.Start();
  36.  
  37.             //graphics01.RotateTransform(-99);
  38.             //graphics02.RotateTransform(-99);
  39.         }
  40.  
  41.         public void Draw()
  42.         {
  43.             float angle = 0.0f;
  44.             float angleM = 0.0f;
  45.             float angleH = 0.0f;
  46.             PointF pointF = new PointF(250, 250);
  47.             float rad = 250;
  48.             Pen pen = new Pen(Color.Azure, 3.0f);
  49.             RectangleF area = new RectangleF(30, 30, 500, 500);
  50.             RectangleF circle = new RectangleF(0, 0, 50, 50);
  51.             RectangleF circleM = new RectangleF(0, 0, 50, 50);
  52.             RectangleF circleH = new RectangleF(0, 0, 50, 50);
  53.  
  54.             PointF loc = PointF.Empty;
  55.             PointF img = new PointF(20, 20);
  56.  
  57.             graphics02.Clear(Color.Black);
  58.  
  59.             while (drawing)
  60.             {
  61.                 graphics01.Clear(Color.Black);
  62.  
  63.                 graphics01.DrawEllipse(pen, area);
  64.                 loc = CirclePoint(rad, angle, pointF);
  65.  
  66.                 circle.X = loc.X - (circle.Width / 2) + area.X;
  67.                 circle.Y = loc.Y - (circle.Height / 2) + area.Y;
  68.  
  69.                 loc = CirclePoint(rad, angleM, pointF);
  70.  
  71.                 circleM.X = loc.X - (circleM.Width / 2) + area.X;
  72.                 circleM.Y = loc.Y - (circleM.Height / 2) + area.Y;
  73.  
  74.                 loc = CirclePoint(rad, angleH, pointF);
  75.  
  76.                 circleH.X = loc.X - (circleH.Width / 2) + area.X;
  77.                 circleH.Y = loc.Y - (circleH.Height / 2) + area.Y;
  78.  
  79.                 //graphics01.DrawEllipse(pen, circle);
  80.                 graphics01.DrawLine(pen, 275, 275, circle.X + 25, circle.Y + 25);
  81.                 graphics01.DrawLine(pen, 275, 275, circleM.X + 25, circleM.Y + 25);
  82.                 graphics01.DrawLine(pen, 275, 275, circleH.X + 25, circleH.Y + 25);
  83.  
  84.                 graphics02.DrawImage(bitmap, img);
  85.  
  86.                 if (angle < 360)
  87.                 {
  88.                     angle += 6;
  89.                 }
  90.                 else if (angle == 360)
  91.                 {
  92.                     angle = 0;
  93.                     angleM += 6;
  94.                 }
  95.                 else if (angleM == 360)
  96.                 {
  97.                     angleM = 0;
  98.                     angleH += 6;
  99.                 }
  100.                 else if (angleH == 360)
  101.                 {
  102.                     angleH = 0;
  103.                 }
  104.  
  105.                 Thread.Sleep(1000);
  106.             }
  107.         }
  108.  
  109.         public PointF CirclePoint(float radius, float angleIsDangre, PointF original)
  110.         {
  111.             float x = (float)(radius * Math.Cos(angleIsDangre * Math.PI / 180F)) + original.X;
  112.             float y = (float)(radius * Math.Sin(angleIsDangre * Math.PI / 180F)) + original.Y;
  113.  
  114.             return new PointF(x, y);
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement