ptrelford

Sechs Serigraphien Animation

Oct 26th, 2014
220
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let design0 = """YYYYYYYYYB
  2. PPPPPPPPYB
  3. PRPYYYYYYB
  4. PRPPPPYBYB
  5. PRPRBRYBYB
  6. PRPRYPYBYB
  7. PRPRBBBBYB
  8. PRRRRRRBYB
  9. PRBBBBBBBB
  10. PRRRRRRRRR"""
  11.  
  12. let design1 = """YYYYYYYYYB
  13. PPPPPPPPYB
  14. PRPYYYYYYB
  15. PRPPBPYBYB
  16. PRPRBRRBYB
  17. PRPYYPYBYB
  18. PRPRBPBBYB
  19. PRRRRRRBYB
  20. PRBBBBBBBB
  21. PRRRRRRRRR"""
  22.  
  23. let design2 = """YYYYYYYYYB
  24. PPPPPPPPYB
  25. PRPYYYYYYB
  26. PRPBBBRBYB
  27. PRPYBRRBYB
  28. PRPYYPRBYB
  29. PRPYPPPBYB
  30. PRRRRRRBYB
  31. PRBBBBBBBB
  32. PRRRRRRRRR"""
  33.  
  34. let design3 = """YYYYYYYYYB
  35. PPPPPPPPYB
  36. PRBRRRRRYB
  37. PRBBBBRPYB
  38. PRBYBRRPYB
  39. PRBYYPRPYB
  40. PRBYPPPPYB
  41. PRYYYYYPYB
  42. PRBBBBBBBB
  43. PRRRRRRRRR"""
  44.  
  45. let design4 = """YYYYYYYYYB
  46. PBBBBBBBRB
  47. PYBRRRRRRB
  48. PYBBBBRPRB
  49. PYBYBRRPRB
  50. PYBYYPRPRB
  51. PYBYPPPPRB
  52. PYYYYYYPRB
  53. PYPPPPPPPB
  54. PRRRRRRRRR"""
  55.  
  56. let design5 = """RRRRRRRRRP
  57. BBBBBBBBRP
  58. BYBRRRRRRP
  59. BYBBBBRPRP
  60. BYBYBRRPRP
  61. BYBYYPRPRP
  62. BYBYPPPPRP
  63. BYYYYYYPRP
  64. BYPPPPPPPP
  65. BYYYYYYYYY"""
  66.  
  67. #r "System.Drawing.dll"
  68.  
  69. open System
  70. open System.Drawing
  71.  
  72. let toColor = function
  73.    | 'R' -> Color.FromArgb(255,245,117,26)
  74.    | 'Y' -> Color.FromArgb(255,238,241,0)
  75.    | 'P' -> Color.FromArgb(255,161,129,228)
  76.    | 'B' -> Color.FromArgb(255,80,170,241)
  77.    | _ -> Color.White
  78.  
  79. let toBrush c = new SolidBrush(toColor c) :> Brush
  80.  
  81. let create (design:string) =
  82.    let image = new Bitmap(500, 500)
  83.    use graphics = Graphics.FromImage(image)
  84.    let lines = design.Split([|'\n'|])
  85.    let k = 50
  86.    lines |> Seq.iteri (fun y line ->
  87.       line |> Seq.iteri (fun x c ->
  88.          let brush = toBrush c
  89.          graphics.FillRectangle(brush, x*k, y*k, k, k)
  90.       )      
  91.    )
  92.    image
  93.  
  94. #r @"Gif.Components.dll"
  95.  
  96. open Gif.Components
  97.  
  98. let encoder = AnimatedGifEncoder()
  99. if encoder.Start(@"c:\app\.gif") then
  100.    encoder.SetFrameRate(5.0f)
  101.    encoder.SetRepeat(0)
  102.    [design0;design0;design1;design2;design3;design4;design5;design5;design5;design5;design4;design3;design2;design1;design0;design0;]
  103.    |> List.iter (fun design -> encoder.AddFrame(create design) |> ignore)
  104.    encoder.Finish() |> ignore
RAW Paste Data