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;
- namespace majcher_rynski_projekt
- {
- public partial class Form1 : Form
- {
- Timer timer = new Timer();
- int width = 300, height = 300, secHand = 140, minHand = 110, hrHand = 80;
- int cx, cy;
- Bitmap bitmap;
- Graphics g;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- bitmap = new Bitmap(width + 1, height + 1);
- cx = width / 2;
- cy = height / 2;
- this.BackColor = Color.White;
- timer.Interval = 1000;
- timer.Tick += new EventHandler(this.timer_tick);
- timer.Start();
- }
- private void timer_tick(object sender, EventArgs e)
- {
- g = Graphics.FromImage(bitmap);
- int ss = DateTime.Now.Second;
- int mm = DateTime.Now.Minute;
- int hh = DateTime.Now.Hour;
- int[] handCoord = new int[2];
- g.Clear(Color.White);
- g.DrawEllipse(new Pen(Color.Black, 1f), 0, 0, width, height);
- g.DrawString("12", new Font("Arial", 12), Brushes.Black, new Point(140, 2));
- g.DrawString("3", new Font("Arial", 12), Brushes.Black, new Point(286, 140));
- g.DrawString("6", new Font("Arial", 12), Brushes.Black, new Point(142, 282));
- g.DrawString("9", new Font("Arial", 12), Brushes.Black, new Point(0, 140));
- handCoord = ms_coord(ss, secHand);
- g.DrawLine(new Pen(Color.Red, 1f), new Point(cx, cy), new Point(handCoord[0], handCoord[1]));
- handCoord = ms_coord(mm, minHand);
- g.DrawLine(new Pen(Color.Black, 2f), new Point(cx, cy), new Point(handCoord[0], handCoord[1]));
- handCoord = hr_coord(hh%12, mm, hrHand);
- g.DrawLine(new Pen(Color.Gray, 3f), new Point(cx, cy), new Point(handCoord[0], handCoord[1]));
- pictureBox1.Image = bitmap;
- this.Text = "Obecny czas: " + hh + ":" + mm + ":" + ss;
- g.Dispose();
- }
- private int[] ms_coord(int val, int hlen) //KOORDYNATY DLA SEKUND I MINUT
- {
- int[] coord = new int[2];
- val *= 6; //kazda minuta i sekunda to 6 stopni
- if (val >= 0 && val <= 180)
- {
- coord[0] = cx + (int)(hlen * Math.Sin(Math.PI * val / 180));
- coord[1] = cy - (int)(hlen * Math.Cos(Math.PI * val / 180));
- }
- else
- {
- coord[0] = cx - (int)(hlen * -Math.Sin(Math.PI * val / 180));
- coord[1] = cy - (int)(hlen * Math.Cos(Math.PI * val / 180));
- }
- return coord;
- }
- private int[] hr_coord(int hval, int mval, int hlen)
- {
- int[] coord = new int[2];
- int val = (int)((hval * 30) + (mval * 0.5)); //Kazda godzina to 30 stopni
- if (val >= 0 && val <= 180)
- {
- coord[0] = cx + (int)(hlen * Math.Sin(Math.PI * val / 180));
- coord[1] = cy - (int)(hlen * Math.Cos(Math.PI * val / 180));
- }
- else
- {
- coord[0] = cx - (int)(hlen * -Math.Sin(Math.PI * val / 180));
- coord[1] = cy - (int)(hlen * Math.Cos(Math.PI * val / 180));
- }
- return coord;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement