Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #r "System.Drawing.dll"
- #r "System.Windows.Forms.dll"
- open System
- open System.Drawing
- open System.Windows.Forms
- let width, height = 512, 512
- let black = 0,0,0
- let red = 183,51,32
- let green = 45, 140, 108
- let blue = 68, 116, 178
- let toBrush (r,g,b) =
- let color = Color.FromArgb(255,r,g,b)
- new SolidBrush(color)
- let draw (a:int) =
- let a = (float a * Math.PI) / 180.0
- let image = new Bitmap(width, height)
- use graphics = Graphics.FromImage(image)
- let brush = toBrush black
- graphics.FillRectangle(brush, 0, 0, width, height)
- let n = 50
- let points =
- [|n, -n;
- width+n, n;
- width-n, height+n;
- -n,height-n|]
- |> Array.map (fun (x,y) -> Point(x,y))
- let r = float width / 2.0
- let transform (x,y) = x*cos(a)-y*sin(a), x*sin(a)+y*cos(a)
- let translate (x,y) = Point(int (x*r) + width/2,int (y*r)+height/2)
- let rectangle points color =
- let points =
- points
- |> Array.map transform
- |> Array.map translate
- let brush = toBrush color
- graphics.FillPolygon(brush,points)
- let points =
- [|-1.0,-1.0;
- 1.0,-1.0;
- 1.0, 1.0;
- -1.0, 1.0|]
- rectangle points red
- let points =
- [|-1.0,-2.0;
- 1.0,-2.0;
- 1.0,-1.0;
- -1.0,-1.0|]
- rectangle points blue
- let points =
- [| 1.0,-1.0;
- 2.0,-1.0;
- 2.0, 1.0;
- 1.0, 1.0|]
- rectangle points blue
- let points =
- [| -1.0,-1.0;
- -2.0,-1.0;
- -2.0, 1.0;
- -1.0, 1.0|]
- rectangle points green
- let points =
- [|-1.0, 2.0;
- 1.0, 2.0;
- 1.0, 1.0;
- -1.0, 1.0|]
- rectangle points green
- image
- let show () =
- let image = draw 45
- let form = new Form (Text="Loewensberg Lines", Width=width+16, Height=height+36)
- let picture = new PictureBox(Dock=DockStyle.Fill, Image=image)
- image.Save(@"C:\app\Loewensberg Square.png", Imaging.ImageFormat.Png)
- do form.Controls.Add(picture)
- form.ShowDialog() |> ignore
- show()
- #r @"Gif.Components.dll"
- open Gif.Components
- let encoder = AnimatedGifEncoder()
- if encoder.Start(@"c:\temp\Loewensberg square.gif") then
- encoder.SetFrameRate(10.0f)
- encoder.SetRepeat 0
- for angle in 0..5..360 do
- encoder.AddFrame(draw angle) |> ignore
- encoder.Finish() |> ignore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement