|
| 1 | +function Get-Gradient { |
| 2 | + <# |
| 3 | + .SYNOPSIS |
| 4 | + Gets a Gradient |
| 5 | + .DESCRIPTION |
| 6 | + Gets a Gradient between one or more inputs. |
| 7 | + |
| 8 | + A gradient can be rendered as CSS or SVG. |
| 9 | +
|
| 10 | + If a gradient type is not specified, it will be a radial gradient. |
| 11 | +
|
| 12 | + Conic gradients are not supported in SVG. |
| 13 | + .NOTES |
| 14 | + Get-Gradient is implemented a function with no dependencies. |
| 15 | +
|
| 16 | + To use it in your projects, you can simply include it inline. |
| 17 | + .EXAMPLE |
| 18 | + Gradient '#4488ff', '#224488' # We can easily generate gradients |
| 19 | + .EXAMPLE |
| 20 | + "$(Gradient '#4488ff', '#224488')" # Stringifying a gradient returns the CSS |
| 21 | + .EXAMPLE |
| 22 | + # Make a a page with just a gradient |
| 23 | + @( |
| 24 | + $gradient = Gradient '#4488ff', '#224488' |
| 25 | + "<html><head><style>" |
| 26 | + "body { max-width: 100vw; width: 100vh; background:$gradient}" |
| 27 | + "</style></head></html>" |
| 28 | + ) > ./gradient.html |
| 29 | + .EXAMPLE |
| 30 | + # Make a a page with a random gradient |
| 31 | + |
| 32 | + $gradient = @( |
| 33 | + # Make 2 to 4 random colors |
| 34 | + foreach ($n in 1..(Get-Random -Min 2 -Max 4)) { |
| 35 | + "#{0:x6}" -f (Get-Random -Max 0xffffff) |
| 36 | + } |
| 37 | + ) | gradient |
| 38 | + # Generate a minimal page with the gradient |
| 39 | + @( |
| 40 | + |
| 41 | + "<html><head><style>" |
| 42 | + "body { max-width: 100vw; width: 100vh; background:$gradient}" |
| 43 | + "</style></head></html>" |
| 44 | + ) > ./randomgradient.html |
| 45 | + .EXAMPLE |
| 46 | + # Make a page with a random conic gradient |
| 47 | + |
| 48 | + $gradient = @( |
| 49 | + "conic" |
| 50 | + # Make 2 to 4 random colors |
| 51 | + foreach ($n in 1..(Get-Random -Min 2 -Max 4)) { |
| 52 | + "#{0:x6}" -f (Get-Random -Max 0xffffff) |
| 53 | + } |
| 54 | + ) | gradient |
| 55 | + # Generate a minimal page with the gradient |
| 56 | + @( |
| 57 | + |
| 58 | + "<html><head><style>" |
| 59 | + "body { max-width: 100vw; width: 100vh; background:$gradient}" |
| 60 | + "</style></head></html>" |
| 61 | + ) > ./randomconicgradient.html |
| 62 | + .EXAMPLE |
| 63 | + # Make a page with a random linear gradient |
| 64 | + |
| 65 | + $gradient = @( |
| 66 | + "linear" |
| 67 | + # Make 2 to 4 random colors |
| 68 | + foreach ($n in 1..(Get-Random -Min 2 -Max 4)) { |
| 69 | + "#{0:x6}" -f (Get-Random -Max 0xffffff) |
| 70 | + } |
| 71 | + ) | gradient |
| 72 | + # Generate a minimal page with the gradient |
| 73 | + @( |
| 74 | + |
| 75 | + "<html><head><style>" |
| 76 | + "body { max-width: 100vw; width: 100vh; background:$gradient}" |
| 77 | + "</style></head></html>" |
| 78 | + ) > ./randomlineargradient.html |
| 79 | + .EXAMPLE |
| 80 | + '#4488ff', '#224488' | Gradient # We can pipe into gradient |
| 81 | + |
| 82 | + #> |
| 83 | + [Alias('Gradient')] |
| 84 | + param() |
| 85 | + |
| 86 | + # All this function does is gather all of the input and arguments |
| 87 | + $allIn = @($input) + @($args) |
| 88 | + |
| 89 | + # and create a custom object. |
| 90 | + [PSCustomObject]@{ |
| 91 | + PSTypeName = 'Gradient' |
| 92 | + Input = $allIn |
| 93 | + } |
| 94 | + |
| 95 | + # This allows us to accept any input, and modify the gradient after it has been created. |
| 96 | + |
| 97 | + # The implementation of the Gradient logic is in PowerShell extended types. |
| 98 | +} |
0 commit comments