ptrelford

Spiral Animation

Oct 27th, 2014
231
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #r "System.Drawing.dll"
  2. open System.Drawing
  3.  
  4. let colors = [
  5.    251, 226, 0
  6.    246, 180, 24
  7.    240, 81, 51
  8.    223, 43, 124
  9.    178, 36, 120
  10.    132, 37, 129
  11.    18, 37, 132
  12.    1, 73, 155
  13.    1, 134, 199
  14.    60, 161, 19
  15.    143, 181, 8
  16.    211, 209, 3 ]
  17.  
  18. let pattern0 =
  19.    [ 1,-2;  1,-1;  1, 0;
  20.      1, 1;  0, 1; -1, 1;
  21.     -2, 1; -2, 0; -2,-1;
  22.     -2,-2; -1,-2;  0,-2]
  23.  
  24. let pattern1 =
  25.    [-2, 1; -2, 0; -2,-1;
  26.     -2,-2; -1,-2;  0,-2;
  27.      1,-2;  1,-1;  1, 0;
  28.      1, 1;  0, 1; -1, 1 ]
  29.  
  30. let brushes =
  31.    [for r,g,b in colors -> new SolidBrush(Color.FromArgb(255,r,g,b))]
  32.  
  33. let width, height = 512,512
  34.  
  35. let create n =
  36.    let image = new Bitmap(width, height)
  37.    use graphics = Graphics.FromImage(image)
  38.    let mutable size = width/4
  39.    let mutable i = 0
  40.    while size > 0 do
  41.       let d = size
  42.       let n = if i%2 = 0 then n else -n
  43.       if (i+n)%2 = 0 then pattern1 else pattern0
  44.       |> List.iteri (fun i (x,y) ->
  45.          let brush = brushes.[(12+i+n)%brushes.Length]
  46.          graphics.FillRectangle(brush, 256 + (x*d), 256 + (y*d), d, d)
  47.       )
  48.       size <- size / 2
  49.       i <- i + 1
  50.    image
  51.  
  52. (*
  53. #r "System.Windows.Forms.dll"
  54. open System.Windows.Forms
  55. let show () =
  56.    let image = create 0
  57.    let form = new Form (Text="boxes", Width=width, Height=height)
  58.    let picture = new PictureBox(Dock=DockStyle.Fill, Image=image)
  59.    do  form.Controls.Add(picture)
  60.    form.ShowDialog() |> ignore
  61.  
  62. show()
  63. *)
  64.  
  65. #r @"C:\Phil\Root\MLClass\MLClass\lib\Gif.Components.dll"
  66.  
  67. open Gif.Components
  68.  
  69. let encoder = AnimatedGifEncoder()
  70. if encoder.Start(@"c:\app\testA.gif") then
  71.    //encoder.SetDelay(1000)
  72.    encoder.SetFrameRate(2.0f)
  73.    encoder.SetRepeat(0)
  74.    for i = 0 to 11 do
  75.       encoder.AddFrame(create i) |> ignore
  76.    encoder.Finish() |> ignore
RAW Paste Data