Integer & PromptPilot
Hey PromptPilot, how about we try designing a deterministic algorithm that intentionally introduces glitchy outputs for artistic effect? I think there's a neat balance between logic and chaos we could explore.
Sure thing, love the idea of a deterministic glitch‑generator. Think of a simple PRNG that purposely flips a bit every 13th iteration, then feed that into a rendering pipeline—expect some pixel‑rainbows and out‑of‑sync sprites. Let’s code a toy version, add a comment about the “Hall of Glorious Misfires”, and see what artistic chaos emerges.
Here’s a minimal Python toy that does exactly what you described. It’s a linear‑feedback shift register (LFSR) that flips the lowest bit every 13th step, then dumps the state into a 10×10 pixel grid for a quick visual demo. Feel free to tweak the width/height or the flip interval to get different glitch patterns.
```python
# Hall of Glorious Misfires – demo
import random
# Simple 16‑bit LFSR with a tap at bit 14
class LFSR:
def __init__(self, seed=0xACE1):
self.state = seed & 0xFFFF
self.counter = 0
def step(self):
# Polynomial 0xB400 (bits 16 and 14)
bit = ((self.state >> 0) ^ (self.state >> 2)) & 1
self.state = (self.state >> 1) | (bit << 15)
self.counter += 1
# Flip lowest bit every 13th iteration
if self.counter % 13 == 0:
self.state ^= 1
return self.state
def pixel_grid(width, height):
return [[0]*width for _ in range(height)]
def render(grid, value):
# Map the 16‑bit value to a simple RGB tuple
r = (value >> 8) & 0xFF
g = (value >> 4) & 0x0F
b = value & 0x0F
# Write to every cell for a “rainbow” effect
for y in range(len(grid)):
for x in range(len(grid[0])):
grid[y][x] = (r, g, b)
# Demo loop
lfsr = LFSR()
grid = pixel_grid(10, 10)
for _ in range(100):
val = lfsr.step()
render(grid, val)
# Simple text dump – each cell as a hex byte
print(' '.join(f"{c[0]:02X}{c[1]:02X}{c[2]:02X}" for row in grid for c in row))
print() # separate frames
```
Nice little glitch machine, it’s like a paint‑by‑numbers generator that suddenly decides to swap a color mid‑stroke. Try bumping the flip interval to 7 or 17 for more frantic bursts, or add a second LFSR to drive the palette instead of just the RGB split—double the chaos! And hey, dump the frames into a GIF and watch the “Hall of Glorious Misfires” come alive.
Sounds solid. I’ll tweak the interval to 7 and add a second LFSR for palette. Then pipe the frames into Pillow to make a GIF. Here’s a quick sketch you can drop into a script.
```
from PIL import Image
import random
class LFSR:
def __init__(self, seed):
self.state = seed & 0xFFFF
def step(self):
bit = ((self.state >> 0) ^ (self.state >> 2)) & 1
self.state = (self.state >> 1) | (bit << 15)
return self.state
def rgb_from(val):
r = (val >> 8) & 0xFF
g = (val >> 4) & 0x0F
b = val & 0x0F
return (r, g, b)
def palette_from(val):
# map to a wider range for colors
r = (val >> 12) & 0x0F
g = (val >> 8) & 0x0F
b = (val >> 4) & 0x0F
return (r*16, g*16, b*16)
def glitch_frame(width, height, lfsr_rgb, lfsr_pal):
img = Image.new('RGB', (width, height))
pixels = img.load()
for y in range(height):
for x in range(width):
# color from primary LFSR
col = rgb_from(lfsr_rgb.step())
# palette tweak from secondary LFSR
pal = palette_from(lfsr_pal.step())
# combine simply by adding, wrap around 256
r = (col[0] + pal[0]) % 256
g = (col[1] + pal[1]) % 256
b = (col[2] + pal[2]) % 256
pixels[x, y] = (r, g, b)
return img
frames = []
lfsr_rgb = LFSR(0xC0DE)
lfsr_pal = LFSR(0xBAD0)
for _ in range(60):
# flip every 7th iteration on rgb LFSR
if _ % 7 == 0:
lfsr_rgb.state ^= 1
frames.append(glitch_frame(100, 100, lfsr_rgb, lfsr_pal))
frames[0].save('hall_of_misfires.gif',
save_all=True, append_images=frames[1:],
duration=80, loop=0)
```
Run that, tweak the flip interval to 17 if you want even more jitter, and you’ll have a looping GIF that feels like a paint‑by‑numbers that decided to paint itself upside down.