Commits

Seth Hobson committed 0913554

F# quilting program complete

Comments (0)

Files changed (1)

F#/Quilting.fs

-module Program
-
-open System
-open System.Drawing
-
-//SKELETON QUILT PROJECT
-
-type Texture =  | Arcs
-                | Bands;;
-
-type Direction = | NE
-                 | SE
-                 | SW
-                 | NW;;
-                 
-type square = Texture * Direction;;
-                 
-type Square = 
-  val square : Texture * Direction  
-  new (tex,dir) = { square = (tex,dir) };;
-  
-type Row = 
-  val row : List<Square>
-  new (list) = { row = list };;
-  
-type Quilt = 
-  val quilt : List<Row>
-  new (list) = { quilt = list };;
-   
-let clockwise dir = 
-// WRITE THIS FUNCTION;;
-  
-let turnsq square =
-// WRITE THIS FUNCTION;;
-  
-let rec emptyquilt q =
-  match q with
-  | [] -> true
-  | []::tl -> emptyquilt tl
-  | hd::tl -> false;;
-  
-let rec sew quiltOne quiltTwo = 
-// WRITE THIS FUNCTION;;
-    
-let rec turn x = 
-// WRITE THIS FUNCTION;;
-    
-let unturn x = 
-// WRITE THIS FUNCTION;;
- 
-let pile x y = 
-// WRITE THIS FUNCTION;;
-  
-let a = [[(Arcs,NE)]];;
-let b = [[(Bands,NE)]];;
-
-let slice = 
-  let aa = pile a (turn (turn a))
-  let bb = pile (unturn b) (turn b)
-  let p = sew bb aa
-  let q = sew aa bb
-  pile p q;;
-    
-let encodeImage square =
-  match square with
-  | Arcs,NE ->  new Bitmap(@"carpetNE.JPG")
-  | Arcs,SE ->  new Bitmap(@"carpetSE.JPG")
-  | Arcs,SW ->  new Bitmap(@"carpetSW.JPG")
-  | Arcs,NW ->  new Bitmap(@"carpetNW.JPG")
-  | Bands,NE -> new Bitmap(@"carpet2NE.JPG")
-  | Bands,SE -> new Bitmap(@"carpet2SE.JPG")
-  | Bands,SW -> new Bitmap(@"carpet2SW.JPG")
-  | Bands,NW -> new Bitmap(@"carpet2NW.JPG");;
-  
-let stitchRowImage r = List.map encodeImage r;;  
-
-let rec calcWidth (r : List<Bitmap>) width = 
-  match r with
-  | [] -> width
-  | hd::td -> let r = calcWidth td width
-              hd.Width + r;;
-              
-let rec calcHeight x = 
-  match x with 
-  | [] -> 0
-  | hd::td -> 80 + calcHeight td;;
-                        
-let calcRowWidth r = calcWidth r 0 ;;
-
-let saveFinalImage (bitmaps : List<List<Bitmap>>) (final : Bitmap) = 
-  let g = Graphics.FromImage(final)
-  let mutable widthOffset = 0
-  let mutable heightOffset = 0
-  for row in bitmaps do
-    widthOffset <- 0
-    for b in row do
-      g.DrawImage(b, new Rectangle(widthOffset, heightOffset, 80, 80))
-      widthOffset <- widthOffset + 80;
-    heightOffset <- heightOffset + 80  
-  final.Save(@"stitchedImage.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);;
-      
-  
-let createQuiltImage x = let bitmaps = List.map stitchRowImage x
-                         let width = calcRowWidth (List.head bitmaps)
-                         let height = calcHeight bitmaps
-                         let final = new Bitmap(width, height)
-                         saveFinalImage bitmaps final;;
-                         
-let quilt1 =
-  let q = sew slice slice
-  sew q slice;;
-  
-let quiltImage = createQuiltImage quilt1;;
-
-[<EntryPoint>]
-let main args = 
-    Console.WriteLine("Hello world!")
-    0
-