## Scratch file for the fireworks script. ## http://www.emperorxlii.com/fireworks $so = $true # - hide cursor # - $ErrorActionPreference = 'Stop' #trap { $_ | select *; break } #$space = New-Object System.Management.Automation.Host.BufferCell #$space.Character = ' ' #$space.ForegroundColor = $host.ui.rawui.ForegroundColor #$space.BackgroundColor = $host.ui.rawui.BackgroundColor #$rect = New-Object System.Management.Automation.Host.Rectangle #$rect.Top = $rect.Bottom = $rect.Right = $rect.Left = -1 #$origin = New-Object System.Management.Automation.Host.Coordinates #$Host.UI.RawUI.CursorPosition = $origin #$Host.UI.RawUI.SetBufferContents($rect, $space) #$s = ' . • · ˙ : … ̇ ̣ ͘ ' #$s = '·' $s = $Host.UI.RawUI.WindowSize $w = $s.Width-1 $h = $s.Height-3 $o = $Host.UI.RawUI.WindowPosition [int[]]$ps = ,0*9 $sp = $w/$ps.Length 0..($ps.Length-1) | % { $ps[$_] = $sp/2 + $_*$sp } $n = 0 $b = [Array]::CreateInstance( [Management.Automation.Host.BufferCell], $h+3, $w+1 ) 0..$w | % { $c = $b[($h+1),$_] $d = $b[($h+2),$_] $c.ForegroundColor = $d.ForegroundColor = 7 $c.Character='_' $p = $ps[$n] if($_ -eq $p-1) { $d.Character='|' } elseif($_ -eq $p) { $d.Character="$($n+1)" } elseif($_ -eq $p+1) { ++$n; $d.Character='|' } $b[($h+1),$_] = $c $b[($h+2),$_] = $d } if($so){$Host.UI.RawUI.SetBufferContents($o,$b)} #$fps = " .'`n:_\"," *'`n*_\"," .::`n::::"," ###`n #####`n######"," :`n'.\'`n-= o",".\'`n> o" $fps = " .'`n:_\"," *'`n*_\"," .::`n::::"," :`n'.\'`n-= o",".\'`n> o" function fv($ch) { switch($ch) { '.' { return "'" } "'" { return '.' } '_' { return ' ' } '\' { return '/' } '/' { return '\' } default { return $ch } } } function fh($ch) { switch($ch) { '\' { return '/' } '/' { return '\' } '>' { return '<' } '<' { return '>' } default { return $ch } } } function flh($l,$i) { $a = $l.ToCharArray() | % { fh $_ } [Array]::Reverse($a) $s = new-object String(,$a) $(if($i -ge 2) { $s.Substring(1) } else { $s }) } function flv($l) { $a = $l.ToCharArray() | % { fv $_ } new-object String(,$a) } function s($i) { $fp = $fps[$i].Split("`n") | % { $_ + (flh $_ $i) } $l = $fp.Length-1 $fp += 0..$l | % { @(if($_ -eq 0 -and $i -ge 3){}else{ flv $fp[$l-$_] }) } $fp } function v($ch) { -not '_|/\<>=-o'.Contains($ch) } $yu = [Math]::Round($h*3/80 + 3.6) function nf($i) { --$i $vx = $(if($i-lt6){1}else{-1})*(get-random -min 2 -max ($yu-1)) $vy = (get-random -min 3 -max $yu) @{ ex=$false; x=$ps[$i]; y=0; vx=$vx; vy=$vy; t=0 } } $bct = [Enum]::Parse([Management.Automation.Host.BufferCellType],'3') [int]$ln = [Math]::Min(1, [DateTime]::Today.Day%10) $fs = ,(nf $ln) $ss = @{} do { $gs = @() $fs | % { $k = New-Object Management.Automation.Host.Coordinates($_.x,($h-$_.y)) if( $_.ex ) { $fp = s (get-random -max ($fps.Length - 1)) $fph = $fp.Length - 1 [int]$fpho = [Math]::Ceiling($fp.Length/2) $fpw = $fp[0].Length - 1 [int]$fpwo = [Math]::Floor($fp[0].Length/2) $cl = get-random -min 9 -max 14 0..$fpw | % { $x = $_ 0..$fph | % { $y = $_ $fk = New-Object Management.Automation.Host.Coordinates(($k.x+$x-$fpwo),($k.y+$y-$fpho)) $ch = $fp[$y][$x] $lcl = $(if(v $ch) { $cl } else { 7 }) $ss[$fk] = New-Object Management.Automation.Host.BufferCell($ch,$lcl,0,2) } } } else { $ss[$k] = New-Object Management.Automation.Host.BufferCell('·',7,0,$bct) $_.t += 0.4 $_.x += $_.vx $oy = $_.y $_.y += $_.vy*$_.t - 3*$_.t*$_.t/2 # y = (U_y * t) + (t^2)*g/2 if($_.y -le $oy) { $_.ex = $true } $gs += $_ } } $fs = $gs $ks = @($ss.Keys) $ks | % { $c = $ss[$_] $r = [int]$c.BufferCellType - 1 $rm = $false if($r -ge 0) { $c.BufferCellType = $r } else { switch($c.Character) { { v $_ } { if( $c.ForegroundColor -eq 15 ) { $c.ForegroundColor = get-random -min 2 -max 4 } elseif( $c.ForegroundColor -ge 9 ) { $c.ForegroundColor = 15 } else { $c.ForegroundColor = 0 $rm = $true } } default { if(($c.ForegroundColor = [int]$c.ForegroundColor + 1) -gt 8) { $c.ForegroundColor = 0 $rm = $true } break } } } $ss[$_] = $c if( $_.x -ge 0 -and $_.y -ge 0 -and $_.x -le $w -and $_.y -le $h ) { $b[$_.y,$_.x] = $c } if($rm) { $ss.Remove($_) } } if($so){$Host.UI.RawUI.SetBufferContents($o,$b)} sleep -m 200 if($Host.UI.RawUI.KeyAvailable) { $ki = $Host.UI.RawUI.ReadKey(14) $Host.UI.RawUI.FlushInputBuffer() if($ki.KeyDown) { $ch = $ki.Character if($ln = $(if([char]::IsDigit($ch)){[int]"$ch"}else{0})) { $fs += nf $ln } #"$ki >> $ch > $ln" } } #write-host -no '.' } while( $fs -or $ss.Count -or $ln ) #[Threading.Thread]::Sleep([TimeSpan]::FromSeconds(1.5)) write-host "$w x $h > $yu; $ln" #@" # .''. # :_\/_: # : /\ : # '..' # # .:::. # ::::::: # ::::::: # ':::' # # *''* # *_\/_* # * /\ * # *..* # # : # '.\'/.' # -= o =- # .'/.\'. # : # # .\'/. # > o < # '/.\' # # ##### # ######### # ########### # ########### # ######### # ##### #"@