Skip to content

Instantly share code, notes, and snippets.

@mhudasch
Created September 20, 2016 22:19
Show Gist options
  • Save mhudasch/214d4fe4b13a57e38bacf054e8751451 to your computer and use it in GitHub Desktop.
Save mhudasch/214d4fe4b13a57e38bacf054e8751451 to your computer and use it in GitHub Desktop.
Draw a waiting wall-e
Function Robot {
$overallIndex = 0;
$cx = $Host.UI.RawUI.CursorPosition.X;
$cy = $Host.UI.RawUI.CursorPosition.Y;
$left = 0;
$right = $Host.UI.RawUI.BufferSize.Width;
$sIdx = 0;
$uIdx = 0;
$stg = "walk";
$clk = 200;
$e = " ";
$s = [char]0x2736;
$cl = @(@($e, $e, $e, $e, $e, $e),@($e, $e, $e, $e, $e, $e),
@($e, $e, $e, $e, $e, $e),@($e, $e, $e, $e, $e, $e));
$bt = @(@($e, $e, $e, $e, $e, $e),@($e, [char]0x250F, [char]0x25A1, $e, $e, $e),
@($e, "[", "―", "]", [char]0x00AC, $e), @($e, "o", "o", "o", $e, $e));
$bbt = @(@($e, $e, $e, [char]0x266B, $e, $e),@($e, $e, $e, [char]0x25A1, [char]0x2513, $e),
@($s, "<", "[", "―", "]", $e),@($e, $e, "o", "o", "o", $e));
$r = @(); ($bt | ForEach-Object{ $r += ,$_.Clone(); });
while($true) {
###
### Check state and break
###
if(($sIdx + $bt.Count) -ge $right) { $sIdx = 0; }
#go back
Start-Sleep -Milliseconds $clk;
$Host.UI.RawUI.CursorPosition = New-Object System.Management.Automation.Host.Coordinates $cx, $cy
#draw the bot
$r | ForEach-Object {
$l = $_;
"".PadLeft($sIdx + $left, $e) | Write-Host -NoNewline;
$l | ForEach-Object { if($_ -eq $s){ Write-Host $_ -NoNewline -ForegroundColor Cyan }
else { Write-Host $_ -NoNewline; } };
Write-Host "";
};
if($stg -eq "walk") {
$uIdx = 0;
$r[3] = @($e, "o", "o", "o", $e, $e)
$r[3][(1 + $sIdx % ($r.Count - 1))] = "0";
$r[3][(1 + ($sIdx + 1) % ($r.Count - 1))] = "O";
$sIdx++;
if($sIdx -ge (Get-Random -Minimum (($r.Count / 2)+5) -Maximum (($right / 2) - ($r.Count / 2)))) { $stg = "unpack"; }
} elseif($stg -eq "unpack") {
switch -Regex ($uIdx.ToString()){
"^[012]$" { $r[3][5] = [char]0x02FD; $r[0][2] = "?" }
"^[345]$" { $r[3][5] = [char]0x2584; $r[1][1] = [char]0x037C; $r[1][2] = [char]0x037D; }
"^[678]$" { $r[3][5] = [char]0x25A0; $r[2][2] = "\"; $r[2][4] = $e; $r[3][4] = [char]0x035F; }
"^9|1[01]$" { $r[3][5] = [char]0x2580; $r[3][4] = [char]0x0305; }
"^1[234]$" { $r[3][5] = $e; $r[2][2] = "―"; $r[2][4] = ">"; $r[2][5] = [char]0x2584; $r[3][4] = $e; }
"^1[567]$" { $r[2][5] = [char]0x25A0; }
"^1[89]|20$" { $r[1][1] = [char]0x250F; $r[1][2] = [char]0x25A1; }
"^2[1235]$" { $r[2][5] = $s; $r[1][1] = [char]0x03FE; $r[1][2] = [char]0x03FF; $r[0][2] = "!"; }
"^26$" {
$r = @(); ($bbt | ForEach-Object{ $r += ,$_.Clone(); });
$stg = "walkback";
}
}
$uIdx++;
} elseif($stg -eq "walkback") {
$r[3] = @($e, $e, "o", "o", "o", $e)
$r[3][(2 + $sIdx % ($r.Count - 1))] = "0";
$r[3][(2 + ($sIdx + 1) % ($r.Count - 1))] = "O";
$sIdx--;
if($sIdx -eq 0) {
$r = @(); ($bt | ForEach-Object{ $r += ,$_.Clone(); });
$stg = "walk";
}
}
$overallIndex++;
}
$Host.UI.RawUI.CursorPosition = New-Object System.Management.Automation.Host.Coordinates $cx, $cy
$cl | ForEach-Object {
"".PadLeft($right, $e) | Write-Host -NoNewline;
Write-Host "";
};
$Host.UI.RawUI.CursorPosition = New-Object System.Management.Automation.Host.Coordinates $cx, $cy
}
Robot;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment