A Christmas Tree in WPK

A Christmas Tree in WPK

  • Comments 4

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:

XmasTree

and Here’s the script:

Import-Module WPK            
            
New-Polygon -Points {            
    # Start from the top            
    "87.5,0"            
    # Left Side of Tree            
    "0,150"             
    "75,140"            
    # Bottom of Tree            
    "75,175"            
    "95,175"            
    # Right Side of Tree            
    "95,140"            
    "175,150"            
    # Back to the top            
    "87.5,0"            
} -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,

James

Leave a Comment
  • Please add 7 and 3 and type the answer here:
  • Post
  • curse you, James!  Now I'll always see my mouse cursor as a white Christmas tree that's leaning to the left.

    Speaking of which, add a drop shadow! :)

  • James

    Does this EVER help !  NOW I'm getting a bad desire to do WPK.  I feel so... so... so NON ItPro.  I feel "DEVilish".

    I feel I am crossing to ... "The Dark Side"...

    Mmmm.... coookies :)

  • Hey guy's ..... happy christmas to all, I am celabraiting with my family, I am so happy about it, Marry christmas to all..............!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • Merry Christmas to you all from me.

Page 1 of 1 (4 items)