Advertisement
ptrelford

Loewensberg concentric circles

Nov 2nd, 2014
623
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 2.70 KB | None | 0 0
  1. #r "System.Drawing.dll"
  2. #r "System.Windows.Forms.dll"
  3.  
  4. open System
  5. open System.Drawing
  6. open System.Drawing.Drawing2D
  7. open System.Windows.Forms
  8.  
  9. let width, height = 512, 512
  10.  
  11. let white = 229,233,225
  12. let yellow = 230, 202, 59
  13. let sand = 224, 158, 1
  14. let orange = 240, 104, 54
  15. let red = 234, 67, 78
  16.  
  17. let blue1 = 122, 139, 254
  18. let blue2 = 138, 121, 213
  19. let purple = 166, 114, 192
  20.  
  21. let toPen (r,g,b) =
  22.    new Pen(Color.FromArgb(255,r,g,b))
  23.  
  24. let toBrush (r,g,b) =
  25.    let color = Color.FromArgb(255,r,g,b)
  26.    new SolidBrush(color)
  27.  
  28. let draw (n1:int) (n2:int) =
  29.    let image = new Bitmap(width, height)
  30.    use graphics = Graphics.FromImage(image)
  31.    graphics.SmoothingMode <- System.Drawing.Drawing2D.SmoothingMode.AntiAlias
  32.    let brush = toBrush white
  33.    graphics.FillRectangle(brush, 0, 0, width, height)  
  34.  
  35.    [yellow;sand;orange;red;white]
  36.    |> List.iteri (fun i color ->
  37.       let brush = toBrush color
  38.       let k = 40+i*30
  39.       graphics.FillPie(brush,k,k,width-k*2,height-k*2,0,360)
  40.    )
  41.  
  42.    [red; purple; blue2; blue1 ;white]
  43.    |> List.iteri (fun i color ->
  44.       let brush = toBrush color
  45.       let k = 40+i*30
  46.       let path = new GraphicsPath()
  47.       path.AddLine(0,512, 0, 100)
  48.       let x1, x2 = k+30+n1, k-30-n2+(width-k*2)
  49.       path.AddLine(x1 ,  0, x1 ,256)      
  50.       path.AddLine(x1 ,256, x2 ,256)
  51.       path.AddLine(x2 ,256, x2 ,  0)
  52.       path.AddLine(x2 ,  0, 512, 0)
  53.       path.AddLine(512, 0,  512,512)      
  54.       graphics.SetClip(path)
  55.       graphics.FillPie(brush,k,k,width-k*2,height-k*2,0,360)
  56.    )
  57.      
  58.    let brush = toBrush white
  59.    let k = 40+4*30
  60.    graphics.FillPie(brush,k,k,width-k*2,height-k*2,0,360)  
  61.  
  62.    image
  63.  
  64. let show () =
  65.    let image = draw 30 30
  66.    let form = new Form (Text="Loewensberg Lines", Width=width+16, Height=height+36)  
  67.    let picture = new PictureBox(Dock=DockStyle.Fill, Image=image)
  68.    image.Save(@"C:\app\Loewensberg Square.png", Imaging.ImageFormat.Png)
  69.    do  form.Controls.Add(picture)
  70.    form.ShowDialog() |> ignore
  71.  
  72. //show()
  73.  
  74. #r @"Gif.Components.dll"
  75. open Gif.Components
  76.  
  77. let encoder = AnimatedGifEncoder()
  78.  
  79. if encoder.Start(@"c:\temp\Loewensberg circles shakeup.gif") then
  80.    encoder.SetFrameRate(20.0f)
  81.    encoder.SetRepeat 0
  82.    for n = 0 to 15 do
  83.       encoder.AddFrame(draw (15+n) (15-n)) |> ignore
  84.    for n = 15 downto -15 do
  85.       encoder.AddFrame(draw (15+n) (15-n)) |> ignore
  86.    for n = -15 to 0 do
  87.       encoder.AddFrame(draw (15+n) (15-n)) |> ignore
  88.    for n = 15 to 45 do
  89.       encoder.AddFrame(draw (n) (n)) |> ignore
  90.    for n = 45 downto 0 do
  91.       encoder.AddFrame(draw (n) (n)) |> ignore
  92.    for n = 0 to 15 do
  93.       encoder.AddFrame(draw (n) (n)) |> ignore
  94.    encoder.Finish() |> ignore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement