Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Added ability to light the trees
Loading branch information
Showing
3 changed files
with
21 additions
and
4 deletions .
+16
−1
AdventTrees2016/MainWindow.xaml
+1
−0
TreeLogic/Program.fs
+4
−3
TreeLogic/Tree.fs
@@ -19,6 +19,9 @@
<i : EventTrigger EventName =" MouseLeftButtonDown" >
<fsxb : EventToCommand Command =" {Binding Decorate}" />
</i : EventTrigger >
<i : EventTrigger EventName =" MouseRightButtonDown" >
<fsxb : EventToCommand Command =" {Binding Light}" />
</i : EventTrigger >
</i : Interaction .Triggers>
<Path DataContext =" {Binding Tree}" Fill =" DarkGreen" Stroke =" DarkGreen" StrokeThickness =" 1" Data =" M 0 -50 L -15 40 L -2 40 L -2 50 L 2 50 L 2 40 L 15 40 Z" RenderTransformOrigin =" 0.5,0.5" >
<Path .RenderTransform>
@@ -38,6 +41,18 @@
</TransformGroup >
</Path .RenderTransform>
</Path >
<Path Canvas.ZIndex=" 2" DataContext =" {Binding Tree}" Visibility =" {Binding Lit, Converter={StaticResource boolToVis}}" Fill =" White" Stroke =" White" StrokeThickness =" 2"
Data =" M 0 -40 L 0 -42 M 2 -30 L 2 -32 M -2 -30 L -2 -32 M 4 -20 L 4 -22 M -4 -20 L -4 -22 M 6 -10 L 6 -12 M -6 -10 L -6 -12 M 4 0 L 4 -2 M -4 0 L -4 -2 M 6 10 L 6 8
M -6 10 L -6 8 M 8 20 L 8 18 M -8 20 L -8 18 M 4 30 L 4 28 M -4 30 L -4 28 M 10 38 L 10 36 M -10 38 L -10 36 M 0 -10 L 0 -8M 0 20 L 0 22
M 15 40 L 14 40 M -15 40 L -14 40 M 2 50 L 1 50 M -2 50 L -1 50" RenderTransformOrigin =" 0.5,0.5" >
<Path .RenderTransform>
<TransformGroup >
<ScaleTransform ScaleX =" 0.15" ScaleY =" 0.1" />
<ScaleTransform ScaleX =" {Binding Height}" ScaleY =" {Binding Height}" />
<TranslateTransform X =" {Binding Position.X}" Y =" {Binding Position.Y}" />
</TransformGroup >
</Path .RenderTransform>
</Path >
</Canvas >
</DataTemplate >
</Window .Resources>
@@ -46,7 +61,7 @@
<RowDefinition Height =" Auto" />
<RowDefinition Height =" *" />
</Grid .RowDefinitions>
<TextBlock HorizontalAlignment =" Center" >Click to add a Tree - Click on a tree to decorate it.</TextBlock >
<TextBlock HorizontalAlignment =" Center" >Click to add a Tree - Left click on a tree to decorate it, right click to light it.</TextBlock >
<ItemsControl
Grid.Row=" 1" HorizontalAlignment =" Stretch" VerticalAlignment =" Stretch"
ItemsSource =" {Binding Forest}"
@@ -13,6 +13,7 @@ module Program =
[
// Create a command that turns into the Decorate message
source |> Binding.createMessage " Decorate" Decorate
source |> Binding.createMessage " Light" Light
]
// Create binding for entire application. This will output all of our messages.
@@ -4,10 +4,10 @@ open System.Runtime.InteropServices
// Our tree types
type Location = { X: float ; Y: float }
type Tree = { Position : Location ; Height : float ; Decorated : bool }
type Tree = { Position : Location ; Height : float ; Decorated : bool ; Lit : bool }
// Update types allowed on a tree
type TreeMessage = | Decorate
type TreeMessage = | Decorate | Light
// Module showing allowed operations on an existing tree
[<CompilationRepresentation( CompilationRepresentationFlags.ModuleSuffix) >]
@@ -16,8 +16,9 @@ module Tree =
let private makeHeight () = 8.0 + rnd.NextDouble() * 4.0
let create location =
{ Position = location ; Height = makeHeight () ; Decorated = false }
{ Position = location ; Height = makeHeight () ; Decorated = false ; Lit = false }
let update msg tree =
match msg with
| Decorate -> { tree with Decorated = true }
| Light -> { tree with Lit = true }
Toggle all file notes