Advertisement
Guest User

Untitled

a guest
Sep 30th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.35 KB | None | 0 0
  1.  
  2. open System.Windows.Forms
  3. open System.Drawing
  4.  
  5. type MyForm() as this =
  6.     inherit Form()
  7.     do
  8.         this.SetStyle(ControlStyles.DoubleBuffer, true)
  9.         this.SetStyle(ControlStyles.UserPaint, true)
  10.         this.SetStyle(ControlStyles.AllPaintingInWmPaint, true)
  11.  
  12. let f = new MyForm(Text="Porygon", TopMost=true)
  13. f.Show()
  14.  
  15. let mutable n = 3.
  16.  
  17. let disegnaPoli (g:Graphics) n =
  18.     let gradi = 360. / n
  19.     let rad = (gradi / 180.) * System.Math.PI
  20.     let arr: Point[] = Array.zeroCreate (int(n))
  21.     for i=0 to (int(n-1.)) do
  22.         let k = float(i)
  23.         let x = int(200. * cos(rad * k))
  24.         let y = int(200. * sin(rad * k))
  25.         arr.[i] <- Point(x, y)
  26. //        g.RotateTransform(float32(gradi))
  27. //        arr.[i] <- new Point(200, 0)
  28. //        g.DrawLine(Pens.Black, 0, 0, 200, 0)
  29.     g.FillPolygon(Brushes.DarkCyan, arr)
  30.     //g.Restore(s)
  31.  
  32. f.Paint.Add( fun e ->
  33.     let g = e.Graphics
  34.     g.SmoothingMode <- Drawing2D.SmoothingMode.HighQuality
  35.     g.TranslateTransform(350.f, 350.f)
  36.     g.RotateTransform(-90.f)
  37.  //   let s = g.Save()
  38.     disegnaPoli g n
  39.   //  disegnaPoli g 3. s
  40. //    disegnaPoli g 4.
  41.    
  42. )
  43.  
  44. f.Invalidated.Add( fun _ ->
  45.       if (n = 20.)
  46.            then n <- 3.
  47.       else n <- n+1.
  48. )
  49.  
  50. let timer = new Timer(Interval=250)
  51. timer.Tick.Add(fun _ ->
  52.     f.Invalidate()
  53. )
  54. timer.Start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement