Advertisement
Guest User

Untitled

a guest
Oct 1st, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.47 KB | None | 0 0
  1.  
  2.  
  3. open System.Windows.Forms
  4. open System.Drawing
  5.  
  6. type MyForm() as this =
  7.     inherit Form()
  8.     do
  9.         this.SetStyle(ControlStyles.DoubleBuffer, true)
  10.         this.SetStyle(ControlStyles.UserPaint, true)
  11.         this.SetStyle(ControlStyles.AllPaintingInWmPaint, true)
  12.  
  13.  
  14. let f = new MyForm(Text="Clock", TopMost=true)
  15. f.Show()
  16.  
  17. let cx, cy = 100, 100
  18.  
  19. let drawTick (g:Graphics) (p:Pen) r l a =
  20.     let a1 = (a / 180.) * System.Math.PI
  21.     let x1 = int(r * cos(a1))
  22.     let y1 = int(r * sin(a1))
  23.     let x2 = int((r + l) * cos(a1))
  24.     let y2 = int((r + l) * sin(a1))
  25.     g.DrawLine(p, cx + x1, cy + y1, cx + x2, cy + y2)
  26.  
  27.  
  28. let drawLine (g:Graphics) p l a =
  29.    drawTick g p 0. 10. (a + 180.)
  30.    drawTick g p 0. l a
  31.  
  32. let drawTime (g:Graphics) (t:System.DateTime) =
  33.    let ah = float(t.Hour % 12) * 30. - 90.
  34.    let am = float(t.Minute) * 6. - 90.
  35.    let asec = float(t.Second) * 6. - 84.
  36.    use hp = new Pen(Color.Black, Width=5.f)
  37.    use mp = new Pen(Color.Black, Width=2.f)
  38.    drawLine g hp 60. ah
  39.    drawLine g mp 75. am
  40.    drawLine g Pens.Red 75. asec
  41.  
  42. let font = new Font("Times New Roman", 12.0f)
  43.  
  44. f.Paint.Add(fun e ->
  45.     let g = e.Graphics
  46.     g.SmoothingMode <- Drawing2D.SmoothingMode.HighQuality
  47.     g.FillEllipse(Brushes.Aquamarine, 0, 0, cx + 100, cy + 100)
  48.     for a in 0. .. 6. .. 360. do
  49.         drawTick g Pens.Black 95. 5. a
  50.     for a in 0. .. 30. .. 360. do
  51.         drawTick g Pens.Black 85. 15. a
  52.     g.DrawEllipse(Pens.Black, 0, 0, cx + 100, cy + 100)
  53.     g.FillEllipse(Brushes.Black, cx - 5, cy - 5, 10, 10)
  54.     drawTime g (System.DateTime.Now)
  55.     g.DrawString(System.DateTime.Now.ToString(), font, Brushes.Black, single(30), single(225))
  56. )
  57.  
  58. let timer = new Timer(Interval=1000)
  59. timer.Tick.Add(fun _ ->
  60.     f.Invalidate()
  61. )
  62. timer.Start()
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74. ////done by me
  75. //f.Paint.Add(fun e ->
  76. //    let g1 = e.Graphics
  77. //    g1.DrawEllipse(Pens.Black, 0, 0, cx + 100, cy + 100)
  78. //    g1.FillEllipse(Brushes.Black, cx - 5, cy - 5, 10, 10)
  79. //    g1.FillEllipse(Brushes.Blue, 0, 0, cx + 100, cy + 100 )
  80. //    for a in 0. .. 6. .. 360. do
  81. //        drawTick g1 Pens.Black 95. 5. a
  82. //    g1.DrawLine(Pens.Black, cx - 15, cy, cx + 50, cy)
  83. //    g1.DrawLine(Pens.Black, cx, cy + 15, cx, cy - 75)
  84. //    f.Invalidate()
  85. //)
  86.  
  87. //f.Paint.Add(fun e ->
  88. //    let g2 = e.Graphics
  89. //  
  90. //)
  91. //
  92. //f.Paint.Add(fun e ->
  93. //    let g3 = e.Graphics
  94. //    
  95. //)
  96. //
  97. //f.Paint.Add(fun e ->
  98. //    let g4 = e.Graphics
  99. //    
  100. //)
  101. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement