Advertisement
ptrelford

15 lines

Oct 26th, 2014
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.51 KB | None | 0 0
  1. let colors = [  
  2.    230,229,15
  3.    243,209,0
  4.    246,132,0
  5.    239,55,1
  6.    219,29,3
  7.    194,8,83
  8.    117,26,123
  9.    56,24,100
  10.    43,38,161
  11.    2,98,208
  12.    0,153,179
  13.    0,174,66
  14.    39,185,22
  15.    103,196,2
  16.    173,214,0]
  17.  
  18. #r "System.Drawing.dll"
  19. open System.Drawing
  20.  
  21. let brushes =
  22.    colors |> List.map (fun (r,g,b) -> new SolidBrush(Color.FromArgb(255,r,g,b)) )
  23.  
  24. let xs = [3;2;1;4;2;1;4;2;1;4;2;1;4;2;1]
  25. let ys = [0;10;14;8;11;6;9;4;7;2;5;12;4;13;1]
  26. let width,height=476,450
  27. let w,h = 14,30
  28.  
  29. let draw k =
  30.    let image = new Bitmap(width,height)
  31.    use graphics = Graphics.FromImage(image)
  32.    for y = 0 to 14 do
  33.       List.zip xs ys
  34.       |> List.mapi (fun i xy -> i,xy)
  35.       |> List.scan (fun x (i,(dx,dy)) ->
  36.          let k = if i%2 = 0 then -k else k
  37.          let brush = brushes.[(15+(y + dy+k))%15]
  38.          graphics.FillRectangle(brush, x*w, y*h, w*dx,h)
  39.          x + dx
  40.       ) 0 |> ignore
  41.    image
  42.  
  43. (*
  44. #r "System.Windows.Forms.dll"
  45. open System.Windows.Forms
  46.  
  47. let show () =
  48.    let image = draw ()
  49.    let form = new Form (Text="15", Width=width+16, Height=height+36)  
  50.    let picture = new PictureBox(Dock=DockStyle.Fill, Image=image)
  51.    do  form.Controls.Add(picture)
  52.    form.ShowDialog() |> ignore
  53.  
  54. show()
  55. *)
  56.  
  57. #r @"Gif.Components.dll"
  58.  
  59. open Gif.Components
  60.  
  61. let encoder = AnimatedGifEncoder()
  62. if encoder.Start(@"c:\app\15.gif") then
  63.    encoder.SetFrameRate(2.0f)
  64.    encoder.SetRepeat(0)
  65.    for i = 0 to 15 do
  66.       encoder.AddFrame(draw i) |> ignore
  67.    encoder.Finish() |> ignore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement