Skip to content

Instantly share code, notes, and snippets.

@DJStompZone
Created June 16, 2025 12:34
Show Gist options
  • Save DJStompZone/4159261e05ce3db0aee7e85c6747def4 to your computer and use it in GitHub Desktop.
Save DJStompZone/4159261e05ce3db0aee7e85c6747def4 to your computer and use it in GitHub Desktop.
Powershell Art
Set-Alias -Name gr -value Get-Random;$COLORMAP=@{0='Black';1='DarkBlue';2='DarkGreen';3='DarkCyan';4='DarkRed';5='DarkMagenta';6='DarkYellow';7='Gray';8='Blue';9='Green';10='DarkGray';11='Cyan';12='Red';13='Magenta';14='Yellow';15='White';};function RandomColorPair(){$_TMPR = (gr)%16; return @($COLORMAP[$_TMPR],$COLORMAP[(15-$_TMPR)])}; function Colorize(){$_TMPC = RandomColorPair ; $console.BackgroundColor = $_TMPC[0] ; $console.ForegroundColor = $_TMPC[1] ; clear-host; python -c "import os;from random import randint as ri;exec(r'''ts,g,ln,N=(os.get_terminal_size(),lambda:' '*ri(3,9),[],ri(10,25));__=[ln.append(g().join([str(ri(10000,99999)) for _ in range(ri(2,5))]+[str(ri(10000,99999)) for _ in range(ri(2,5))][::-1]).center(ts.columns)) for _ in range(N)];m=len(ln)<(ts.lines/3);ln+=(ln[::-1] if m else []);p=max(ts.lines-len(ln),0);t=p//2;b=p-t;print('\n'*t+'\n'.join(ln)+'\n'*b)''')"};$console=$Host.UI.RawUI;Register-EngineEvent PowerShell.Exiting -Action{$console.BackgroundColor='Black';$console.ForegroundColor='White'};$STOPFLAG=$False;[Console]::TreatControlCAsInput = $true;while($STOPFLAG -ne $True){if ([Console]::KeyAvailable){$key = [System.Console]::ReadKey($true);if (($key.Modifiers -band [ConsoleModifiers]::Control) -and ($key.Key -eq "C")){[Console]::TreatControlCAsInput = $false;$console.BackgroundColor=$COLORMAP[0];$console.ForegroundColor=$COLORMAP[15];break;}};Colorize;if(((gr)%999) -eq ((gr)%999)){write-host "You won!";$STOPFLAG=$True;$console.BackgroundColor=$COLORMAP[0];$console.ForegroundColor=$COLORMAP[15]}else{sleep((((gr) % 32)+ 4)/7)}}
@DJStompZone
Copy link
Author

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment