3 people like it.

Paper snowflake

Transparent snowflake using polygons and rotational symmetry, based on paper and scissors method.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
31: 
32: 
33: 
34: 
35: 
36: 
37: 
38: 
39: 
40: 
41: 
42: 
43: 
#r "System.Drawing.dll"
#r "System.Windows.Forms.dll"
 
open System
open System.Drawing
open System.Windows.Forms
 
let width, height = 512.0, 512.0

let paperSnowflake () =   
   let image = new Bitmap(int width, int height)
   use graphics = Graphics.FromImage(image)  
   use brush = new SolidBrush(Color.Black)
   graphics.FillRectangle(brush, 0, 0, int width, int height)
   graphics.TranslateTransform(float32 (width/2.0),float32 (height/2.0))   
   let color = Color.FromArgb(128,0,128,255)
   use brush = new SolidBrush(color)
   let rand = Random()
   let polys =
      [for i in 1..12 ->
         let w = rand.Next(20)+1 // width
         let h = rand.Next(20)+1 // height
         let m = rand.Next(h)    // midpoint
         let s = rand.Next(30)   // start
         [|0,s; -w,s+m; 0,s+h; w,s+m|]
      ]
   for i in 0.0..60.0..300.0 do           
      graphics.RotateTransform(float32 60.0)
      let poly points =
         let points = [|for (x,y) in points -> Point(x*5,y*5)|]           
         graphics.FillPolygon(brush,points)
      polys |> List.iter poly 
   image

let show () =
   let image = paperSnowflake ()
   let form = new Form (Text="Paper Snowflake", Width=int width+16, Height=int height+36)  
   let picture = new PictureBox(Dock=DockStyle.Fill, Image=image)
   image.Save(@"C:\temp\Paper.png", Imaging.ImageFormat.Png)
   do  form.Controls.Add(picture)
   form.ShowDialog() |> ignore

show()
namespace System
namespace System.Drawing
namespace System.Windows
namespace System.Windows.Forms
val width : float

Full name: Script.width
val height : float

Full name: Script.height
val paperSnowflake : unit -> Bitmap

Full name: Script.paperSnowflake
val image : Bitmap
Multiple items
type Bitmap =
  inherit Image
  new : filename:string -> Bitmap + 11 overloads
  member Clone : rect:Rectangle * format:PixelFormat -> Bitmap + 1 overload
  member GetHbitmap : unit -> nativeint + 1 overload
  member GetHicon : unit -> nativeint
  member GetPixel : x:int * y:int -> Color
  member LockBits : rect:Rectangle * flags:ImageLockMode * format:PixelFormat -> BitmapData + 1 overload
  member MakeTransparent : unit -> unit + 1 overload
  member SetPixel : x:int * y:int * color:Color -> unit
  member SetResolution : xDpi:float32 * yDpi:float32 -> unit
  member UnlockBits : bitmapdata:BitmapData -> unit
  ...

Full name: System.Drawing.Bitmap

--------------------
Bitmap(filename: string) : unit
   (+0 other overloads)
Bitmap(stream: IO.Stream) : unit
   (+0 other overloads)
Bitmap(original: Image) : unit
   (+0 other overloads)
Bitmap(filename: string, useIcm: bool) : unit
   (+0 other overloads)
Bitmap(type: Type, resource: string) : unit
   (+0 other overloads)
Bitmap(stream: IO.Stream, useIcm: bool) : unit
   (+0 other overloads)
Bitmap(width: int, height: int) : unit
   (+0 other overloads)
Bitmap(original: Image, newSize: Size) : unit
   (+0 other overloads)
Bitmap(width: int, height: int, format: Imaging.PixelFormat) : unit
   (+0 other overloads)
Bitmap(width: int, height: int, g: Graphics) : unit
   (+0 other overloads)
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val graphics : Graphics
type Graphics =
  inherit MarshalByRefObject
  member AddMetafileComment : data:byte[] -> unit
  member BeginContainer : unit -> GraphicsContainer + 2 overloads
  member Clear : color:Color -> unit
  member Clip : Region with get, set
  member ClipBounds : RectangleF
  member CompositingMode : CompositingMode with get, set
  member CompositingQuality : CompositingQuality with get, set
  member CopyFromScreen : upperLeftSource:Point * upperLeftDestination:Point * blockRegionSize:Size -> unit + 3 overloads
  member Dispose : unit -> unit
  member DpiX : float32
  ...
  nested type DrawImageAbort
  nested type EnumerateMetafileProc

Full name: System.Drawing.Graphics
Graphics.FromImage(image: Image) : Graphics
val brush : SolidBrush
Multiple items
type SolidBrush =
  inherit Brush
  new : color:Color -> SolidBrush
  member Clone : unit -> obj
  member Color : Color with get, set

Full name: System.Drawing.SolidBrush

--------------------
SolidBrush(color: Color) : unit
type Color =
  struct
    member A : byte
    member B : byte
    member Equals : obj:obj -> bool
    member G : byte
    member GetBrightness : unit -> float32
    member GetHashCode : unit -> int
    member GetHue : unit -> float32
    member GetSaturation : unit -> float32
    member IsEmpty : bool
    member IsKnownColor : bool
    ...
  end

Full name: System.Drawing.Color
property Color.Black: Color
Graphics.FillRectangle(brush: Brush, rect: Rectangle) : unit
Graphics.FillRectangle(brush: Brush, rect: RectangleF) : unit
Graphics.FillRectangle(brush: Brush, x: int, y: int, width: int, height: int) : unit
Graphics.FillRectangle(brush: Brush, x: float32, y: float32, width: float32, height: float32) : unit
Graphics.TranslateTransform(dx: float32, dy: float32) : unit
Graphics.TranslateTransform(dx: float32, dy: float32, order: Drawing2D.MatrixOrder) : unit
Multiple items
val float32 : value:'T -> float32 (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.float32

--------------------
type float32 = Single

Full name: Microsoft.FSharp.Core.float32

--------------------
type float32<'Measure> = float32

Full name: Microsoft.FSharp.Core.float32<_>
val color : Color
Color.FromArgb(argb: int) : Color
Color.FromArgb(alpha: int, baseColor: Color) : Color
Color.FromArgb(red: int, green: int, blue: int) : Color
Color.FromArgb(alpha: int, red: int, green: int, blue: int) : Color
val rand : Random
Multiple items
type Random =
  new : unit -> Random + 1 overload
  member Next : unit -> int + 2 overloads
  member NextBytes : buffer:byte[] -> unit
  member NextDouble : unit -> float

Full name: System.Random

--------------------
Random() : unit
Random(Seed: int) : unit
val polys : (int * int) [] list
val i : int
val w : int
Random.Next() : int
Random.Next(maxValue: int) : int
Random.Next(minValue: int, maxValue: int) : int
val h : int
val m : int
val s : int
val i : float
Graphics.RotateTransform(angle: float32) : unit
Graphics.RotateTransform(angle: float32, order: Drawing2D.MatrixOrder) : unit
val poly : (seq<int * int> -> unit)
val points : seq<int * int>
val points : Point []
val x : int
val y : int
Multiple items
type Point =
  struct
    new : sz:Size -> Point + 2 overloads
    member Equals : obj:obj -> bool
    member GetHashCode : unit -> int
    member IsEmpty : bool
    member Offset : p:Point -> unit + 1 overload
    member ToString : unit -> string
    member X : int with get, set
    member Y : int with get, set
    static val Empty : Point
    static member Add : pt:Point * sz:Size -> Point
    ...
  end

Full name: System.Drawing.Point

--------------------
Point()
Point(sz: Size) : unit
Point(dw: int) : unit
Point(x: int, y: int) : unit
Graphics.FillPolygon(brush: Brush, points: Point []) : unit
Graphics.FillPolygon(brush: Brush, points: PointF []) : unit
Graphics.FillPolygon(brush: Brush, points: Point [], fillMode: Drawing2D.FillMode) : unit
Graphics.FillPolygon(brush: Brush, points: PointF [], fillMode: Drawing2D.FillMode) : unit
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
  interface IEnumerable
  interface IEnumerable<'T>
  member Head : 'T
  member IsEmpty : bool
  member Item : index:int -> 'T with get
  member Length : int
  member Tail : 'T list
  static member Cons : head:'T * tail:'T list -> 'T list
  static member Empty : 'T list

Full name: Microsoft.FSharp.Collections.List<_>
val iter : action:('T -> unit) -> list:'T list -> unit

Full name: Microsoft.FSharp.Collections.List.iter
val show : unit -> unit

Full name: Script.show
val form : Form
Multiple items
type Form =
  inherit ContainerControl
  new : unit -> Form
  member AcceptButton : IButtonControl with get, set
  member Activate : unit -> unit
  member ActiveMdiChild : Form
  member AddOwnedForm : ownedForm:Form -> unit
  member AllowTransparency : bool with get, set
  member AutoScale : bool with get, set
  member AutoScaleBaseSize : Size with get, set
  member AutoScroll : bool with get, set
  member AutoSize : bool with get, set
  ...
  nested type ControlCollection

Full name: System.Windows.Forms.Form

--------------------
Form() : unit
Multiple items
namespace System.Drawing.Text

--------------------
namespace System.Text
val picture : PictureBox
Multiple items
type PictureBox =
  inherit Control
  new : unit -> PictureBox
  member AllowDrop : bool with get, set
  member BorderStyle : BorderStyle with get, set
  member CancelAsync : unit -> unit
  member CausesValidation : bool with get, set
  member ErrorImage : Image with get, set
  member Font : Font with get, set
  member ForeColor : Color with get, set
  member Image : Image with get, set
  member ImageLocation : string with get, set
  ...

Full name: System.Windows.Forms.PictureBox

--------------------
PictureBox() : unit
type DockStyle =
  | None = 0
  | Top = 1
  | Bottom = 2
  | Left = 3
  | Right = 4
  | Fill = 5

Full name: System.Windows.Forms.DockStyle
field DockStyle.Fill = 5
type Image =
  inherit MarshalByRefObject
  member Clone : unit -> obj
  member Dispose : unit -> unit
  member Flags : int
  member FrameDimensionsList : Guid[]
  member GetBounds : pageUnit:GraphicsUnit -> RectangleF
  member GetEncoderParameterList : encoder:Guid -> EncoderParameters
  member GetFrameCount : dimension:FrameDimension -> int
  member GetPropertyItem : propid:int -> PropertyItem
  member GetThumbnailImage : thumbWidth:int * thumbHeight:int * callback:GetThumbnailImageAbort * callbackData:nativeint -> Image
  member Height : int
  ...
  nested type GetThumbnailImageAbort

Full name: System.Drawing.Image
Image.Save(filename: string) : unit
Image.Save(stream: IO.Stream, format: Imaging.ImageFormat) : unit
Image.Save(filename: string, format: Imaging.ImageFormat) : unit
Image.Save(stream: IO.Stream, encoder: Imaging.ImageCodecInfo, encoderParams: Imaging.EncoderParameters) : unit
Image.Save(filename: string, encoder: Imaging.ImageCodecInfo, encoderParams: Imaging.EncoderParameters) : unit
namespace System.Drawing.Imaging
Multiple items
type ImageFormat =
  new : guid:Guid -> ImageFormat
  member Equals : o:obj -> bool
  member GetHashCode : unit -> int
  member Guid : Guid
  member ToString : unit -> string
  static member Bmp : ImageFormat
  static member Emf : ImageFormat
  static member Exif : ImageFormat
  static member Gif : ImageFormat
  static member Icon : ImageFormat
  ...

Full name: System.Drawing.Imaging.ImageFormat

--------------------
Imaging.ImageFormat(guid: Guid) : unit
property Imaging.ImageFormat.Png: Imaging.ImageFormat
property Control.Controls: Control.ControlCollection
Control.ControlCollection.Add(value: Control) : unit
Form.ShowDialog() : DialogResult
Form.ShowDialog(owner: IWin32Window) : DialogResult
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
Raw view Test code New version

More information

Link:http://fssnip.net/oB
Posted:10 years ago
Author:Phillip Trelford
Tags: snowflake