Guest User

Untitled

a guest
Jan 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. open System.Windows.Forms
  2. open System.Drawing
  3.  
  4. // Prepare window form
  5. let win = new System.Windows.Forms.Form ()
  6. // Set some properties
  7. win.BackColor <- System.Drawing.Color.White
  8. let height = 250
  9. let width = 200
  10. win.Size <- System.Drawing.Size (width, height)
  11.  
  12. // make a timer
  13. let timer = new Timer ()
  14. timer.Interval <- 1000 // create an event every 1000 millisecond
  15. timer.Enabled <- true // activate the timer
  16.  
  17. let getEndPoint degrees =
  18. let t = float 50
  19. let s = float 0
  20. let theta = float degrees * (System.Math.PI / float 180)
  21. let u = (s * (cos theta) + t * (sin theta)) + float 100
  22. let v = (-s * (sin theta) + -t * (cos theta)) + float 100
  23. Point (int u,int v)
  24.  
  25. // Set paint call-back function
  26. let paint (e : PaintEventArgs) (x) : unit =
  27. let pen = new Pen (Color.Black)
  28. let endPoint = getEndPoint x
  29. let points = [|Point (100,100); endPoint|]
  30. e.Graphics.DrawLines (pen, points)
  31.  
  32. let getDegrees =
  33. 360/60*System.DateTime.Now.Second
  34.  
  35. let addPaint degrees =
  36. printfn "Draws with degrees %A" degrees
  37. win.Paint.Add (fun e -> (paint e degrees))
  38.  
  39. win.Paint.Add (fun e -> (paint e 90))
  40. //timer.Tick.Add (fun e -> (addPaint 90)) // Doesn't draw
  41. //timer.Tick.Add (fun e -> (addPaint getDegrees)) // Doesn't draw, updates every second, but doesn't change degrees
  42. //timer.Tick.Add (fun e -> (addPaint (360/60*System.DateTime.Now.Second))) // Doesn't draw, but get correct degrees
  43.  
  44. // Start the event-loop.
  45. System.Windows.Forms.Application.Run win
Add Comment
Please, Sign In to add comment