Advertisement
ptrelford

Four Similar Groups

Oct 27th, 2014
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 5.84 KB | None | 0 0
  1. // Richard P. Lohse, Four Similar Groups
  2.  
  3. let design = "! | ! ! ! !
  4. @*+-@*@*+-@*
  5. | | | ! | |
  6. @-+-+-+-+-+*
  7. ! | | | | !
  8. @*@-+-+-+*@*
  9. ! ! | | | !
  10. @*+-+-+-+-@*
  11. ! | | | | |
  12. +-+-+*@-+-+-
  13. ! | ! ! | !
  14. @*+*@*@*@+@+"
  15.  
  16. let lines = design.Split([|'\n'|])
  17.  
  18. let toName = function
  19.    | '@' -> "Red"
  20.    | '*' -> "Blue"
  21.    | '!' -> "Pink"
  22.    | '|' -> "LightPink"
  23.    | '+' -> "White"
  24.    | '-' -> "Grey"
  25.    | _ -> "Black"
  26.  
  27. let toColor = function
  28.    | "Red" -> 190, 28, 0
  29.    | "Blue" -> 41, 68, 176
  30.    | "Pink" -> 201, 102, 165
  31.    | "LightPink" -> 221, 199, 218
  32.    | "White" -> 238, 234, 247
  33.    | "Grey" -> 205, 205, 232
  34.    | "Black" -> 7, 11, 18
  35.    | _ -> invalidOp ""
  36.  
  37. #r "System.Drawing.dll"
  38. open System
  39. open System.Drawing
  40.  
  41. let toBrush c =
  42.    c |> toName |> toColor |> fun (r,g,b) -> new SolidBrush(Color.FromArgb(255,r,g,b))
  43.  
  44. let draw (lines:string[]) =  
  45.    let w,h = 40, 40
  46.    let image = new Bitmap(11*40, 12*40)  
  47.    use graphics = Graphics.FromImage(image)
  48.    graphics.FillRectangle(toBrush ' ', 0, 0, 800, 800)  
  49.    lines |> Seq.iteri (fun y line ->
  50.       line |> Seq.iteri (fun x c ->
  51.          let brush = toBrush c
  52.          graphics.FillRectangle(brush, x*w, y*h, w, h)
  53.       )      
  54.    )
  55.    image  
  56.  
  57.  
  58. #r @"Gif.Components.dll"
  59. open Gif.Components
  60.  
  61. let encoder = AnimatedGifEncoder()
  62. if encoder.Start(@"c:\temp\Four Similar Groups.gif") then
  63.    encoder.SetFrameRate(10.0f)
  64.    encoder.SetRepeat(0)
  65.    let deltas = [
  66.       []
  67.       [4,1, '+'; 4,2, '@']
  68.       [4,1, '+'; 4,3, '@']
  69.       [4,1, '+'; 4,4, '@']
  70.       [4,1, '+'; 4,5, '@']
  71.       [4,1, '+'; 4,6, '@']
  72.       [4,1, '+'; 4,7, '@']
  73.       [4,1, '+'; 4,8, '@']
  74.       [4,1, '+'; 4,9, '@']
  75.  
  76.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,8, '@']
  77.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,7, '@']
  78.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,6, '@']
  79.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,5, '@']
  80.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,4, '@']
  81.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@']
  82.  
  83.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 3,5, '@']
  84.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 4,5, '@']
  85.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 5,5, '@']
  86.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 6,5, '@']
  87.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 7,5, '@']
  88.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@']
  89.  
  90.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  9,7, '@']
  91.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  8,7, '@']
  92.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  7,7, '@']
  93.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  6,7, '@']
  94.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  5,7, '@']
  95.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  4,7, '@']
  96.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  3,7, '@']
  97.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  98.  
  99.       [4,1, '+'; 4,9, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  100.       [4,1, '+'; 4,8, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  101.       [4,1, '+'; 4,7, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  102.       [4,1, '+'; 4,6, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  103.       [4,1, '+'; 4,5, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  104.       [4,1, '+'; 4,4, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  105.       [4,1, '+'; 4,3, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  106.       [4,1, '+'; 4,2, '@'; 6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  107.  
  108.       [                    6,9, '+'; 6,3, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  109.       [                    6,9, '+'; 6,4, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  110.       [                    6,9, '+'; 6,5, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  111.       [                    6,9, '+'; 6,6, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  112.       [                    6,9, '+'; 6,7, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  113.       [                    6,9, '+'; 6,8, '@'; 2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  114.  
  115.       [                                        2,5, '+'; 8,5, '@'; 10,7, '+';  2,7, '@']
  116.       [                                        2,5, '+'; 7,5, '@'; 10,7, '+';  2,7, '@']
  117.       [                                        2,5, '+'; 6,5, '@'; 10,7, '+';  2,7, '@']
  118.       [                                        2,5, '+'; 5,5, '@'; 10,7, '+';  2,7, '@']
  119.       [                                        2,5, '+'; 4,5, '@'; 10,7, '+';  2,7, '@']
  120.       [                                        2,5, '+'; 3,5, '@'; 10,7, '+';  2,7, '@']
  121.  
  122.       [                                                            10,7, '+';  2,7, '@']
  123.       [                                                            10,7, '+';  3,7, '@']
  124.       [                                                            10,7, '+';  4,7, '@']
  125.       [                                                            10,7, '+';  5,7, '@']
  126.       [                                                            10,7, '+';  6,7, '@']
  127.       [                                                            10,7, '+';  7,7, '@']
  128.       [                                                            10,7, '+';  8,7, '@']
  129.       [                                                            10,7, '+';  9,7, '@']
  130.       []
  131.  
  132.       ]
  133.  
  134.    deltas |> List.iter (fun xs ->
  135.       let ys = lines |> Array.map (fun line -> line.ToCharArray())
  136.       for x,y,c in xs do
  137.          ys.[y].[x] <- c
  138.       let lines = ys |> Array.map (fun chars -> String(chars))
  139.       encoder.AddFrame(draw lines) |> ignore
  140.    )
  141.    encoder.Finish() |> ignore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement