| 商朝の時計です (C#) |
|---|
|
商朝の単位制による時計のソースコードです
Download source files: http://www.jkofsp.net/files/ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Takaku.ShangUnit; namespace ClockShangUnit { public partial class Form1 : Form { public Form1() { InitializeComponent(); } ShangDateTime T; private void Form1_Shown(object sender, EventArgs e) { Refresh(); } private void timer1_Tick(object sender, EventArgs e) { Refresh(); } void Refresh() { T = new ShangDateTime(DateTime.Now); textBox1.Text = T.Year.ToString() + "年" + T.Month.ToString() + "月" + T.Day.ToString() + "日 [" + ((int)T.DayOfShangWeek).ToString() + "]"; textBox2.Text = T.Hour.ToString("D2") + ":" + T.Minute.ToString("D2") + ":" + T.Second.ToString("D2") + "." + T.Millisecond.ToString("D3"); pictureBox1.Refresh(); } private void pictureBox1_Resize(object sender, EventArgs e) { Refresh(); } private void pictureBox1_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; int size = Math.Min(pictureBox1.Width, pictureBox1.Height); g.DrawEllipse(new Pen(Color.Black, 2.0f), pictureBox1.Width / 2 - size / 2 + 10, pictureBox1.Height / 2 - size / 2 + 10, size - 20, size - 20); Point center = new Point(pictureBox1.Width / 2, pictureBox1.Height / 2); int _size = size - 20; for (int i = 0; i < 100; i++) { float r = (float)((i / 100.0) * (Math.PI * 2)); if (i % 10 != 0) { Point p = new Point((int)(Math.Sin(r) * (_size * 0.95 / 2)), (int)(Math.Cos(r) * (_size * 0.95 / 2))); g.DrawRectangle(Pens.Black, p.X + center.X, -p.Y + center.Y, 1, 1); } else { Point p = new Point((int)(Math.Sin(r) * (_size * 0.95 / 2)), (int)(Math.Cos(r) * (_size * 0.95 / 2))); Point p_ = new Point((int)(Math.Sin(r) * (_size * 0.85 / 2)), (int)(Math.Cos(r) * (_size * 0.85 / 2))); g.DrawLine(new Pen(Color.Black, 2.0f), new Point(p.X + center.X, -p.Y + center.Y), new Point(p_.X + center.X, -p_.Y + center.Y)); } } float rHourHand = (float)(((T.Hour * 10000 + T.Minute * 100 + T.Second) / 100000.0) * (Math.PI * 2)); Point hourHand = new Point((int)(Math.Sin(rHourHand) * (_size * 0.6 / 2)), (int)(Math.Cos(rHourHand) * (_size * 0.6 / 2))); g.DrawLine(new Pen(Color.Black, 2.0f), center, new Point(hourHand.X + center.X, - hourHand.Y + center.Y)); float rMinuteHand = (float)(((T.Minute * 100 + T.Second) / 10000.0) * (Math.PI * 2)); Point minuteHand = new Point((int)(Math.Sin(rMinuteHand) * (_size * 0.8 / 2)), (int)(Math.Cos(rMinuteHand) * (_size * 0.8 / 2))); g.DrawLine(new Pen(Color.Black, 2.0f), center, new Point(minuteHand.X + center.X, -minuteHand.Y + center.Y)); float rSecondHand = (float)(((T.Second * 1000 + T.Millisecond) / 100000.0) * (Math.PI * 2)); Point secondHand = new Point((int)(Math.Sin(rSecondHand) * (_size * 0.8 / 2)), (int)(Math.Cos(rSecondHand) * (_size * 0.8 / 2))); g.DrawLine(new Pen(Color.Red, 1.0f), center, new Point(secondHand.X + center.X, -secondHand.Y + center.Y)); } } } |