Commits

Seth Hobson committed 8d37cdf

F# quilting program complete

  • Participants
  • Parent commits 0913554

Comments (0)

Files changed (26)

F#/Quilting/Quilting.sln

+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Quilting", "Quilting\Quilting.fsproj", "{45BBC314-BA2D-4521-9F50-BD19C91B1112}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{45BBC314-BA2D-4521-9F50-BD19C91B1112}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{45BBC314-BA2D-4521-9F50-BD19C91B1112}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{45BBC314-BA2D-4521-9F50-BD19C91B1112}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{45BBC314-BA2D-4521-9F50-BD19C91B1112}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

F#/Quilting/Quilting.v11.suo

Binary file added.

F#/Quilting/Quilting/App.config

+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
+    </startup>
+    <runtime>
+      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+        <dependentAssembly>
+          <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
+          <bindingRedirect oldVersion="4.0.0.0" newVersion="4.3.0.0"/>
+          <bindingRedirect oldVersion="2.3.5.0" newVersion="4.3.0.0"/>
+          <bindingRedirect oldVersion="2.0.0.0" newVersion="4.3.0.0"/>
+          
+        </dependentAssembly>
+      </assemblyBinding>
+    </runtime>	
+</configuration>

F#/Quilting/Quilting/Program.fs

+//SKELETON QUILT PROJECT
+
+
+module Quilting
+open System
+open System.Drawing;;
+
+  type Texture =  | Arcs 
+                  | Bands;;
+
+  type Direction = | NE
+                   | SE
+                   | SW
+                   | NW;;
+                 
+  type square = Texture * Direction;;  // a 2-tuple
+
+  //-----------------------------------------------------
+  // Starting from these two quilts we sew/pile/turn/etc.
+  //  Our quilt is built and converted into an image in the 
+  //  last line of this file.
+  //-----------------------------------------------------
+  let a = [[(Arcs,NE)]];;
+  let b = [[(Bands,NE)]];;
+
+
+  // a useful function for some base cases perhaps
+  let rec emptyquilt q =
+    match q with
+    | [] -> true
+    | []::tl -> emptyquilt tl
+    | hd::tl -> false;;
+
+  // WRITE THIS FUNCTION BASED ON OUR DISCUSSION
+  let clockwise direction = 
+    match direction with
+    | NE -> SE
+    | SE -> SW
+    | SW -> NW
+    | NW -> NE;;
+  
+  // WRITE THIS FUNCTION BASED ON OUR DISCUSSION
+  let turnsq square = 
+    let textur = (fst square)
+    let dir = (snd square)
+    let newdir = clockwise dir
+    (textur, newdir);;
+//    ((fst square) , clockwise (snd square));;
+
+  // WRITE THIS FUNCTION BASED ON OUR DISCUSSION
+  let rec sew q1 q2 = 
+    if emptyquilt q1 && emptyquilt q2 then []
+    else 
+      let head1 = (List.head q1)
+      let head2 = (List.head q2)
+      let tail1 = (List.tail q1)
+      let tail2 = (List.tail q2)
+      (head1 @ head2)::(sew tail1 tail2);;
+
+    
+  // WRITE THIS FUNCTION BASED ON OUR DISCUSSION
+  let rec turn x = 
+    if emptyquilt x then []
+    else
+      let col = (List.map List.head x)
+      let row = (List.rev col)
+      (List.map turnsq row)::turn (List.map List.tail x);;
+
+  // WRITE THIS FUNCTION BASED ON OUR DISCUSSION
+  let unturn x = turn (turn (turn x));;
+ 
+  // WRITE THIS FUNCTION
+  let pile q1 q2 = q1 @ q2;;
+
+  //-----------------------------------------------                 
+  // These types are for image handling purposes.
+  //-----------------------------------------------                 
+  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 };;
+  //-----------------------------------------------                 
+
+ 
+  //-----------------------------------------------                 
+  // These functions are for image handling purposes.
+  //-----------------------------------------------                 
+  let encodeImage square =
+    match square with
+    | Bands,NE ->  new Bitmap(@"bandsNE.jpg");
+    | Bands,SE ->  new Bitmap(@"bandsSE.jpg");
+    | Bands,SW ->  new Bitmap(@"bandsSW.jpg");
+    | Bands,NW ->  new Bitmap(@"bandsNW.jpg");
+    | Arcs,NE -> new Bitmap(@"arcsNE.jpg");
+    | Arcs,SE -> new Bitmap(@"arcsSE.jpg");
+    | Arcs,SW -> new Bitmap(@"arcsSW.jpg");
+    | Arcs,NW -> new Bitmap(@"arcsNW.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;;
+  //-----------------------------------------------                 
+
+
+                         
+  
+  //-----------------------------------------------------
+  // Starting from the two a and b squares made earlier, 
+  //  create slices and quilts!  
+  // Our quilt is converted into an image in the last line of this file.
+  //-----------------------------------------------------
+// UNCOMMENT THIS WHEN PILE/TURN/ETC ARE READY!
+   let slice = 
+     let aa = pile (unturn a) (turn a)
+     let bb = pile b (turn (turn b))
+     let q = sew aa bb
+     pile q q;;
+
+   let our_quilt =
+     let q = sew slice slice
+     sew q slice;;
+  //-----------------------------------------------------
+
+  //-----------------------------------------------                 
+  // We've already constructed the quilt abstractly,
+  //   just do the images now.
+  //-----------------------------------------------                 
+// UNCOMMENT THIS WHEN PILE/TURN/ETC ARE READY!
+  let quiltImage = createQuiltImage our_quilt;; 
+

F#/Quilting/Quilting/Quilting.fsproj

+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>45bbc314-ba2d-4521-9f50-bd19c91b1112</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <RootNamespace>Quilting</RootNamespace>
+    <AssemblyName>Quilting</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <Name>Quilting</Name>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <Tailcalls>false</Tailcalls>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <WarningLevel>3</WarningLevel>
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DocumentationFile>bin\Debug\Quilting.XML</DocumentationFile>
+    <Prefer32Bit>true</Prefer32Bit>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <Tailcalls>true</Tailcalls>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <WarningLevel>3</WarningLevel>
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DocumentationFile>bin\Release\Quilting.XML</DocumentationFile>
+    <Prefer32Bit>true</Prefer32Bit>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="mscorlib" />
+    <Reference Include="FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+      <Private>True</Private>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Numerics" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Program.fs" />
+    <None Include="App.config" />
+  </ItemGroup>
+  <PropertyGroup>
+    <MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
+  </PropertyGroup>
+  <Import Project="$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>