#!/usr/bin/env python3
# static_noise_fixed.py - Flask generates random noise
import numpy as np
import time
from flask import Flask, Response
app = Flask(__name__)
WIDTH, HEIGHT = 400, 300
frame_count = 0
@app.route('/')
def index():
return '''
Static Noise Animation
📺 Static Noise Animation
Frames: 0
FPS: 0
Status: Loading...
'''
@app.route('/noise')
def get_noise():
"""Generate random static noise"""
global frame_count
# Create random noise
if frame_count % 3 == 0:
noise = np.random.randint(0, 256, (HEIGHT, WIDTH, 3), dtype=np.uint8)
gray = np.random.randint(0, 256, (HEIGHT, WIDTH, 1), dtype=np.uint8)
noise[:, :, :] = gray
elif frame_count % 3 == 1:
noise = np.random.randint(0, 256, (HEIGHT, WIDTH, 3), dtype=np.uint8)
else:
noise = np.random.randint(0, 256, (HEIGHT, WIDTH, 3), dtype=np.uint8)
noise[::4, :, :] = noise[::4, :, :] // 2
# Occasionally add a "glitch"
if np.random.random() < 0.02:
glitch_color = np.random.randint(0, 256, 3)
glitch_height = np.random.randint(20, 100)
glitch_y = np.random.randint(0, HEIGHT - glitch_height)
noise[glitch_y:glitch_y + glitch_height, :, :] = glitch_color
# Convert to bytes
raw_bytes = noise.tobytes()
frame_count += 1
if frame_count % 30 == 0:
print(f"📡 Generated noise frame {frame_count}")
return Response(
raw_bytes,
mimetype='application/octet-stream',
headers={
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Pragma': 'no-cache',
'Expires': '0',
'X-Frame-Count': str(frame_count)
}
)
@app.route('/test')
def test():
"""Test endpoint - returns simple pattern"""
pixels = np.zeros((HEIGHT, WIDTH, 3), dtype=np.uint8)
pixels[:HEIGHT//2, :, 0] = 255
pixels[HEIGHT//2:, :, 1] = 255
for i in range(min(WIDTH, HEIGHT)):
if i < HEIGHT and i < WIDTH:
pixels[i, i, 2] = 255
return Response(
pixels.tobytes(),
mimetype='application/octet-stream',
headers={'Cache-Control': 'no-cache'}
)
if __name__ == "__main__":
print("="*60)
print("📺 STATIC NOISE ANIMATION SERVER")
print("="*60)
print(f"📡 Port: 7860")
print(f"🎨 Resolution: {WIDTH}x{HEIGHT}")
print(f"📊 Data per frame: {WIDTH * HEIGHT * 3} bytes")
print("="*60)
app.run(host='0.0.0.0', port=7860, debug=False, threaded=True)