Advertisement
ptrelford

Loewensberg Lines

Oct 31st, 2014
475
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #r "System.Drawing.dll"
  2. #r "System.Windows.Forms.dll"
  3.  
  4. open System
  5. open System.Drawing
  6. open System.Windows.Forms
  7.  
  8. let width, height = 512, 512
  9.  
  10. let blue = (2, 89, 148)
  11. let yellow = (252, 173, 6)
  12. let red = (200, 1, 44)
  13. let purple = (116, 56, 119)
  14.  
  15. let pattern w h = [
  16.    (-1, 0), (0,0);
  17.    ( 0, 1), (0,h-1);
  18.    ( 1, 0), (w-1,h-1);
  19.    ( 0,-1), (w-1,4)
  20.    (-1, 0), (4,4)
  21.    ]
  22.  
  23. let path w h =
  24.    let x, y = ref (w-1), ref 0
  25.    [for (dx,dy), (x1,y1) in pattern w h do
  26.       while !x <> x1 || !y <> y1 do            
  27.          yield !x,!y
  28.          x := !x + dx
  29.          y := !y + dy
  30.    ]
  31.  
  32. let draw () =
  33.    let image = new Bitmap(width, height)
  34.    use graphics = Graphics.FromImage(image)
  35.    let color = Color.FromArgb(255,234,236,232)
  36.    let brush = new SolidBrush(color)
  37.    graphics.FillRectangle(brush, 0, 0, width, height)
  38.    
  39.    let colors = [blue; yellow; red; purple]
  40.    for i = 0 to 3 do
  41.       let w,h = 25-i*2, 25 - i*2
  42.       let points = path w h
  43.       let n = points.Length
  44.       for (x,y) in points |> Seq.take (n-(i+2)*1) |> Seq.skip ((3-i)*3) do
  45.          let r,g,b = colors.[i]
  46.          let color = Color.FromArgb(255,r,g,b)
  47.          let brush = new SolidBrush(color)
  48.          graphics.FillRectangle(brush, (1+x+i)*19, (1+y+i)*19, 19, 19)
  49.    image
  50.  
  51. let show () =
  52.    let image = draw ()
  53.    let form = new Form (Text="Loewensberg Lines", Width=320+16, Height=320+36)  
  54.    let picture = new PictureBox(Dock=DockStyle.Fill, Image=image)
  55.    image.Save(@"C:\temp\Loewensberg Lines.png", Imaging.ImageFormat.Png)
  56.    do  form.Controls.Add(picture)
  57.    form.ShowDialog() |> ignore
  58.  
  59. show()
Advertisement
RAW Paste Data Copied
Advertisement