# glitch.ps1
# Prank/glitch screen effect. Does NOT auto-close.
# Press F12 to exit.
Add-Type -AssemblyName System.Windows.Forms, System.Drawing
# --- Mute system volume (so the jump-scare sound doesn't blast) ---
try {
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class M {
[DllImport("winmm.dll")]
public static extern int waveOutSetVolume(IntPtr h, uint v);
}
"@
[M]::waveOutSetVolume([IntPtr]::Zero, 0) | Out-Null
} catch {}
# --- Set up looping media player ---
$pl = $null
try {
[Windows.Media.Playback.MediaPlayer, Windows.Media, ContentType = WindowsRuntime] | Out-Null
[Windows.Media.Core.MediaSource, Windows.Media.Core, ContentType = WindowsRuntime] | Out-Null
$pl = New-Object Windows.Media.Playback.MediaPlayer
$pl.Source = [Windows.Media.Core.MediaSource]::CreateFromUri([Uri]'https://www.myinstants.com/media/sounds/salewin-exe.mp3')
$pl.IsLoopingEnabled = $true
$pl.Play()
} catch {}
# --- Capture screen ---
$b = [Windows.Forms.Screen]::PrimaryScreen.Bounds
$W = $b.Width
$H = $b.Height
Write-Host "screen: $W x $H"
$script:bmp = New-Object Drawing.Bitmap $W, $H
$g = [Drawing.Graphics]::FromImage($script:bmp)
$g.CopyFromScreen($b.Location, [Drawing.Point]::Empty, $b.Size)
$g.Dispose()
# --- Noise bitmap ---
$script:noise = New-Object Drawing.Bitmap 128, 128
$nr = New-Object Random
for ($y = 0; $y -lt 128; $y++) {
for ($x = 0; $x -lt 128; $x++) {
$script:noise.SetPixel($x, $y, [Drawing.Color]::FromArgb(255, $nr.Next(256), $nr.Next(256), $nr.Next(256)))
}
}
# --- User info and text pools ---
$script:user = (Get-LocalUser -Name $env:USERNAME -EA 0).FullName
if (-not $script:user) { $script:user = $env:USERNAME }
$script:msgs = @('Pegasus', 'Hacked')
$script:fonts = @('Minecraft', 'Minecraftia', 'Consolas')
# --- Pixelate helper ---
function Px($bl) {
$sw = [Math]::Max(1, $bl)
$sh = [Math]::Max(1, [int]($sw * $H / $W))
$sm = New-Object Drawing.Bitmap $sw, $sh
$gs = [Drawing.Graphics]::FromImage($sm)
$gs.InterpolationMode = [Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
$gs.DrawImage($script:bmp, 0, 0, $sw, $sh)
$gs.Dispose()
$px = New-Object Drawing.Bitmap $W, $H
$gp = [Drawing.Graphics]::FromImage($px)
$gp.InterpolationMode = [Drawing.Drawing2D.InterpolationMode]::NearestNeighbor
$gp.PixelOffsetMode = [Drawing.Drawing2D.PixelOffsetMode]::Half
$gp.DrawImage($sm, 0, 0, $W, $H)
$gp.Dispose()
$sm.Dispose()
return $px
}
# --- Glitch effect helper ---
function Fx($base, $inten) {
$o = New-Object Drawing.Bitmap $W, $H
$gr = [Drawing.Graphics]::FromImage($o)
$gr.DrawImage($base, 0, 0, $W, $H)
$mb = [int]($inten * 4) + 2
for ($i = 0; $i -lt $mb; $i++) {
$m = Get-Random -Min 0 -Max 4
$bh = Get-Random -Min 20 -Max 300
$by = Get-Random -Min 0 -Max ($H - $bh)
if ($m -eq 0) {
$dy = Get-Random -Min 100 -Max 800
$sr = New-Object Drawing.Rectangle 0, $by, $W, $bh
$dr = New-Object Drawing.Rectangle 0, ($by + $dy), $W, $bh
if ($dr.Bottom -le $H) {
$gr.DrawImage($base, $dr, $sr, [Drawing.GraphicsUnit]::Pixel)
}
}
elseif ($m -eq 1) {
$dx = Get-Random -Min -600 -Max 600
$sr = New-Object Drawing.Rectangle 0, $by, $W, $bh
$dr = New-Object Drawing.Rectangle $dx, $by, $W, $bh
$gr.DrawImage($base, $dr, $sr, [Drawing.GraphicsUnit]::Pixel)
}
elseif ($m -eq 2) {
$br = New-Object Drawing.SolidBrush ([Drawing.Color]::FromArgb((Get-Random -Min 150 -Max 240), (Get-Random -Min 0 -Max 255), (Get-Random -Min 0 -Max 255), (Get-Random -Min 0 -Max 255)))
$gr.FillRectangle($br, 0, $by, $W, $bh)
$br.Dispose()
}
else {
$bar = New-Object Drawing.SolidBrush ([Drawing.Color]::FromArgb(230, (Get-Random -Min 0 -Max 255), (Get-Random -Min 0 -Max 255), (Get-Random -Min 0 -Max 255)))
$gr.FillRectangle($bar, 0, $by, $W, $bh)
$bar.Dispose()
}
}
$nc = Get-Random -Min 1 -Max 3
for ($k = 0; $k -lt $nc; $k++) {
$gr.DrawImage($script:noise,
(Get-Random -Min -128 -Max $W),
(Get-Random -Min -128 -Max $H),
(Get-Random -Min 300 -Max 800),
(Get-Random -Min 300 -Max 800))
}
$mtxt = $script:msgs[(Get-Random -Min 0 -Max $script:msgs.Count)]
$mf = $script:fonts[(Get-Random -Min 0 -Max $script:fonts.Count)]
$mfont = New-Object Drawing.Font $mf, (Get-Random -Min 80 -Max 240), ([Drawing.FontStyle]::Bold)
$mbrush = New-Object Drawing.SolidBrush ([Drawing.Color]::FromArgb(255, (Get-Random -Min 100 -Max 255), (Get-Random -Min 0 -Max 100), (Get-Random -Min 100 -Max 255)))
$sz = $gr.MeasureString($mtxt, $mfont)
$gr.DrawString($mtxt, $mfont, $mbrush,
(Get-Random -Min 0 -Max ([Math]::Max(1, $W - $sz.Width))),
(Get-Random -Min 0 -Max ([Math]::Max(1, $H - $sz.Height))))
$mfont.Dispose(); $mbrush.Dispose()
$uf = New-Object Drawing.Font $mf, (Get-Random -Min 60 -Max 160), ([Drawing.FontStyle]::Bold)
$ub = New-Object Drawing.SolidBrush ([Drawing.Color]::FromArgb(255, (Get-Random -Min 100 -Max 255), (Get-Random -Min 100 -Max 255), (Get-Random -Min 100 -Max 255)))
$usz = $gr.MeasureString($script:user, $uf)
$gr.DrawString($script:user, $uf, $ub,
(Get-Random -Min 0 -Max ([Math]::Max(1, $W - $usz.Width))),
(Get-Random -Min 0 -Max ([Math]::Max(1, $H - $usz.Height))))
$uf.Dispose(); $ub.Dispose()
if ((Get-Random -Min 0 -Max 100) -lt 40) {
$inv = New-Object Drawing.Bitmap $W, $H
$gi = [Drawing.Graphics]::FromImage($inv)
$at = New-Object Drawing.Imaging.ImageAttributes
$cm = New-Object Drawing.Imaging.ColorMatrix
$cm.Matrix00 = -1; $cm.Matrix11 = -1; $cm.Matrix22 = -1
$cm.Matrix33 = 1; $cm.Matrix40 = 1; $cm.Matrix41 = 1; $cm.Matrix42 = 1
$at.SetColorMatrix($cm)
$gi.DrawImage($o, (New-Object Drawing.Rectangle 0, 0, $W, $H), 0, 0, $W, $H, [Drawing.GraphicsUnit]::Pixel, $at)
$gi.Dispose()
$gr.DrawImage($inv, 0, 0, $W, $H)
$inv.Dispose(); $at.Dispose()
}
$gr.Dispose()
return $o
}
# --- Pre-render frames ---
Write-Host 'pre-rendering 80 frames...'
$script:fr = New-Object System.Collections.ArrayList
$script:N = 80
for ($i = 0; $i -lt $script:N; $i++) {
$e = [Math]::Pow($i / $script:N, 2)
$base = Px ([int](600 - (600 - 12) * $e))
$frm = Fx $base (0.6 + $e * 0.4)
$base.Dispose()
[void]$script:fr.Add($frm)
if ($i % 10 -eq 0) { Write-Host " frame $i/$($script:N)" }
}
Write-Host 'done, opening form'
# --- Build window ---
$f = New-Object Windows.Forms.Form
$f.FormBorderStyle = 'None'
$f.StartPosition = 'Manual'
$f.Location = [Drawing.Point]::Empty
$f.Size = $b.Size
$f.TopMost = $true
$f.ShowInTaskbar = $false
$f.BackColor = [Drawing.Color]::Black
$f.BackgroundImageLayout = 'None'
$f.BackgroundImage = $script:fr[0]
$f.Cursor = [Windows.Forms.Cursors]::Default
$f.KeyPreview = $true
$script:stop = $false
$f.Add_KeyDown({
if ($_.KeyCode -eq [Windows.Forms.Keys]::F12) {
$script:stop = $true
$t.Stop()
$f.Close()
}
})
# --- Frame timer ---
$script:s = 0
$t = New-Object Windows.Forms.Timer
$t.Interval = 1
$t.Add_Tick({
# Only stop if user requested via F12.
# (Removed auto-close on frame exhaustion: we now loop the frames.)
if ($script:stop) {
$t.Stop()
$f.Close()
return
}
$f.BackgroundImage = $script:fr[$script:s]
$script:s++
if ($script:s -ge $script:N) { $script:s = 0 } # loop instead of close
})
$f.Add_Shown({
[Windows.Forms.Cursor]::Hide()
$t.Start()
})
[void]$f.ShowDialog()
# --- Cleanup ---
$t.Dispose()
try { [Windows.Forms.Cursor]::Show() } catch {}
if ($pl) {
try {
$pl.Pause()
$pl.Source = $null
$pl.Dispose()
} catch {}
}
try { [M]::waveOutSetVolume([IntPtr]::Zero, 0xFFFFFFFF) | Out-Null } catch {}
$bmp.Dispose()
$script:noise.Dispose()
foreach ($fr in $script:fr) { $fr.Dispose() }4 views