0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

cscの作法 その35 アナログ時計

0
Last updated at Posted at 2020-01-04

概要

cscの作法、調べてみた。
練習問題やってみた。

練習問題

アナログ時計。

写真

image

サンプルコード

using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing.Drawing2D;


class form1: Form {
	form1() {
		Text = "clock";
		Opacity = 0.7;
		ClientSize = new Size(150, 150);
		Timer timer = new Timer();
		timer.Interval = 1000; 
		timer.Tick += new EventHandler(timerTick);
		timer.Start();
	}
	protected override void OnPaint(PaintEventArgs e) {
		Graphics g = e.Graphics;
		g.TranslateTransform(ClientSize.Width / 2, ClientSize.Height / 2, MatrixOrder.Append);
		Pen BPen = new Pen(Color.Blue, 5);
		Pen GPen = new Pen(Color.Green, 5);
		Pen RPen = new Pen(Color.Red, 3);
		Point center = new Point(0, 0);
		DateTime time = DateTime.Now;
		double secAng = 2.0 * Math.PI * time.Second / 60.0;
		double minAng = 2.0 * Math.PI * (time.Minute + time.Second / 60.0) / 60.0;
		double hourAng = 2.0 * Math.PI * (time.Hour + time.Minute / 60.0) / 12.0;
		int r = Math.Min(ClientSize.Width, ClientSize.Height) / 2;
		int secHandLength = (int) (0.9 * r);
		int minHandLength = (int) (0.9 * r);
		int hourHandLength = (int) (0.7 * r);
		Point secHand = new Point((int) (secHandLength * Math.Sin(secAng)), (int) (-secHandLength * Math.Cos(secAng)));
		Point minHand = new Point((int) (minHandLength * Math.Sin(minAng)), (int) (-minHandLength * Math.Cos(minAng)));
		Point hourHand = new Point((int) (hourHandLength * Math.Sin(hourAng)), (int) (-hourHandLength * Math.Cos(hourAng)));
		g.DrawLine(RPen, center, secHand);
		g.DrawLine(GPen, center, minHand);
		g.DrawLine(BPen, center, hourHand);
	}
	void timerTick(object sender, EventArgs e) {
		this.Invalidate();
	}
	[STAThread]
	public static void Main() {
		Application.Run(new form1());
	}
}




以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?