December 25th, 2009

A Christmas Tree in WPK

PowerShell Team
PowerShell Team

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

Author

PowerShell Team
PowerShell Team

PowerShell is a task-based command-line shell and scripting language built on .NET. PowerShell helps system administrators and power-users rapidly automate tasks that manage operating systems (Linux, macOS, and Windows) and processes.

0 comments

Discussion are closed.