Advertisement
wandrake

Untitled

Feb 29th, 2012
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.36 KB | None | 0 0
  1. open System.Windows.Forms
  2. open System.Drawing
  3. open System.Timers
  4.  
  5. type ThrobberApple() as x =
  6.     inherit UserControl()
  7.    
  8.     let mutable rotation = 0
  9.     let mutable pensize = 0
  10.     let colors : Color array = Array.zeroCreate 12
  11.  
  12.     do
  13.         let timer = new Timer(Interval = 60.0, Enabled = true)
  14.        
  15.         for i in 0..11 do
  16.             colors.[i] <- Color.FromArgb((i * 20) + 15, Color.Black)
  17.  
  18.         timer.AutoReset <- true
  19.         timer.Elapsed.Add(fun _ ->
  20.             rotation <- (rotation + 1) % 12
  21.             x.Refresh()
  22.         )
  23.  
  24.         x.DoubleBuffered <- true
  25.  
  26.     override x.OnPaint e =
  27.         let graphics = e.Graphics
  28.  
  29.         graphics.SmoothingMode <- Drawing2D.SmoothingMode.HighQuality
  30.  
  31.         let pensize = x.Width / 15
  32.  
  33.         let pen = new Pen(Color.Black, single pensize)
  34.         pen.StartCap <- Drawing2D.LineCap.Round
  35.         pen.EndCap <- Drawing2D.LineCap.Round
  36.  
  37.         let from = int (single (x.Width - 2 * pensize) * 0.28f)
  38.         let len = (x.Width - 2 * pensize) / 2 - from
  39.  
  40.         graphics.TranslateTransform(single (x.Width / 2), single (x.Width / 2))
  41.  
  42.         graphics.RotateTransform(30.f * single rotation)
  43.  
  44.         for i in 0..11 do
  45.             pen.Color <- colors.[i]
  46.             graphics.DrawLine(pen, from, 0, from + len, 0)
  47.             graphics.RotateTransform(30.f)
  48.         done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement