A Christmas Tree in WPK

Merry Christmas.  To celebrate the holiday, here’s a quick Christmas tree written in WPK (the WPF PowerShell Kit).  You can get WPK as part of the PowerShellPack (http://code.msdn.microsoft.com/PowerShellPack).

Here’s a screenshot:


and Here’s the script:

Import-Module WPK            
New-Polygon -Points {            
    # Start from the top            
    # Left Side of Tree            
    # Bottom of Tree            
    # Right Side of Tree            
    # Back to the top            
} -On_SizeChanged {            
    if ($_.PreviousSize.Width -eq 0 -and            
        $_.PreviousSize.Height -eq 0) {            
        $this.Resources.OriginalSize = $_.NewSize            
    } else {            
        $originalSize = $this.Resources.OriginalSize            
        $ScaleX = $_.NewSize.Width  /$originalSize.Width             
        $ScaleY = $_.NewSize.Height / $originalSize.Height             
        $this.RenderTransform = New-ScaleTransform -ScaleX $ScaleX -ScaleY $ScaleY            
} -BitmapEffect {             
    New-BevelBitmapEffect -BevelWidth 1            
} -Fill DarkGreen -AsJob                                    

It’s only about 30 lines, but this script has tons of Christmas goodies.  It shows an example of how to create any random polygon with a simple list of points, how to resize that polygon to whatever size the control need to be, and how to apply a quick bitmap effect to an image.

Hope this Helps,