PoshCode Archive  Artifact [541f0eccbb]

Artifact 541f0eccbb2d18141598a90b66311021536e34f2811bdac1c9f8656a4813dc50:

  • File Draw-Circle.ps1 — part of check-in [44b0e6261a] at 2018-06-10 14:14:38 on branch trunk — Draws a circle using Write-Host and one space for each part of the circle. (user: Nathan Estell size: 2405)

# encoding: ascii
# api: powershell
# title: Draw-Circle
# description: Draws a circle using Write-Host and one space for each part of the circle.
# version: 0.1
# type: function
# author: Nathan Estell
# license: CC0
# function: Draw-Circle
# x-poshcode-id: 6382
# x-archived: 2016-10-18T11:00:01
# x-published: 2016-06-14T18:05:00
#
#
function Draw-Circle
{
param
(
		[int]$radius = 20,
		[string]$ForegroundColor = "Green",
		[string]$BackgroundColor = "Black"
)
	for ($RowNum = $radius; $RowNum -gt 0; $RowNum--)
	{
		#[int]$spaces=$radius+12/8*[System.Math]::Sqrt($radius*$radius-$rownum*$rownum)+$radius
		[int]$spaces = 12/8 * ($radius - [System.Math]::Sqrt($radius * $radius - $rownum * $rownum))
		[int]$spaces2 = 2 * 12/8 * [System.Math]::Sqrt($radius * $radius - $rownum * $rownum)
		for ($i = 0; $i -lt $spaces; $i++)
		{
			write-host " " -backgroundcolor $BackgroundColor -nonewline
		}
		Write-Host " " -BackgroundColor $ForegroundColor -nonewline
		for ($i = 0; $i -lt $spaces2; $i++)
		{
			write-host " " -backgroundcolor $BackgroundColor -nonewline
		}
		
		Write-Host " " -BackgroundColor $ForegroundColor -nonewline
		#Write-Host (2 *(12/8) *$radius - ($spaces + $spaces2)),$spaces,$spaces2 -NoNewline
		for ($i = 0; $i -lt (2 * (12/8) * $radius - ($spaces + $spaces2)); $i++)
		{
			write-host " " -backgroundcolor $BackgroundColor -nonewline
		}
		write-host " " -backgroundcolor $BackgroundColor
	}
	for ($RowNum=0;$RowNum -lt ($radius+1);$RowNum++)
{
		#[int]$spaces=$radius+12/8*[System.Math]::Sqrt($radius*$radius-$rownum*$rownum)+$radius
[int]$spaces = 12/8 * ($radius - [System.Math]::Sqrt($radius * $radius - $rownum * $rownum))
[int]$spaces2=2*12/8*[System.Math]::Sqrt($radius*$radius-$rownum*$rownum)
for ($i=0;$i -lt $spaces;$i++)
{
			write-host " " -backgroundcolor $BackgroundColor -nonewline
}
		Write-Host " " -BackgroundColor $ForegroundColor -nonewline
for ($i=0;$i -lt $spaces2;$i++)
{
			write-host " " -backgroundcolor $BackgroundColor -nonewline
}
		
		Write-Host " " -BackgroundColor $ForegroundColor -nonewline
		#Write-Host (2 *(12/8) *$radius - ($spaces + $spaces2)),$spaces,$spaces2 -NoNewline
for ($i = 0; $i -lt (2 *(12/8) *$radius - ($spaces + $spaces2)); $i++)
{
			write-host " " -backgroundcolor $BackgroundColor -nonewline
}
		write-host " " -backgroundcolor $BackgroundColor
}
}