#!/usr/bin/env python3 # checker_pattern.py - Simple raw data checker pattern import numpy as np import time import os from flask import Flask, Response # ===== 1. SETUP ===== PORT = int(os.getenv('PORT', 7860)) WIDTH, HEIGHT = 400, 300 TILE_SIZE = 40 # Size of each checker tile print(f"๐Ÿš€ Starting checker pattern server on port {PORT}") # ===== 2. CREATE FLASK APP ===== app = Flask(__name__) # ===== 3. SIMPLE HTML WITH CANVAS ===== HTML = ''' Checker Pattern Test

โœ… CHECKER PATTERN TEST - MUST SHOW BELOW

If you see a black/white checker pattern below, it's WORKING!

Debug Info:

Server Time: -
Data Size: 0 bytes
Status: Loading...
Last Update: Never
''' @app.route('/') def index(): return HTML @app.route('/checker') def get_checker(): """Return raw RGB bytes of a checker pattern""" print("๐ŸŽฒ Generating checker pattern...") # Create checker pattern using numpy pattern = np.zeros((HEIGHT, WIDTH, 3), dtype=np.uint8) # Create grid of tile indices y_indices, x_indices = np.mgrid[:HEIGHT, :WIDTH] tile_x = x_indices // TILE_SIZE tile_y = y_indices // TILE_SIZE # Checker pattern: (tile_x + tile_y) % 2 == 0 -> white, else black checker_mask = ((tile_x + tile_y) % 2 == 0) # White tiles: RGB = [255, 255, 255] pattern[checker_mask] = [255, 255, 255] # Black tiles: already [0, 0, 0] from zeros initialization # Convert to raw bytes raw_bytes = pattern.tobytes() print(f"๐Ÿ“ค Serving checker pattern: {len(raw_bytes)} bytes") return Response( raw_bytes, mimetype='application/octet-stream', headers={ 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Content-Type': 'application/octet-stream', 'X-Pattern': 'checker' } ) @app.route('/image') def get_image(): """Return the same checker pattern as a JPEG image""" print("๐Ÿ–ผ๏ธ Generating checker image...") # Create checker pattern pattern = np.zeros((HEIGHT, WIDTH, 3), dtype=np.uint8) y_indices, x_indices = np.mgrid[:HEIGHT, :WIDTH] tile_x = x_indices // TILE_SIZE tile_y = y_indices // TILE_SIZE checker_mask = ((tile_x + tile_y) % 2 == 0) pattern[checker_mask] = [255, 255, 255] # Convert to JPEG using PIL from PIL import Image import io img = Image.fromarray(pattern, 'RGB') buffer = io.BytesIO() img.save(buffer, format='JPEG', quality=90) buffer.seek(0) print(f"๐Ÿ“ค Serving JPEG image: {buffer.getbuffer().nbytes} bytes") return Response( buffer.getvalue(), mimetype='image/jpeg', headers={'Cache-Control': 'no-cache'} ) @app.route('/raw') def get_raw(): """Simple raw data test - returns colored stripes""" print("๐ŸŒˆ Generating colored stripes...") # Create colored stripes pattern pattern = np.zeros((HEIGHT, WIDTH, 3), dtype=np.uint8) # Red stripe pattern[:, :WIDTH//3, 0] = 255 # Green stripe pattern[:, WIDTH//3:2*WIDTH//3, 1] = 255 # Blue stripe pattern[:, 2*WIDTH//3:, 2] = 255 raw_bytes = pattern.tobytes() return Response( raw_bytes, mimetype='application/octet-stream', headers={'Cache-Control': 'no-cache'} ) @app.route('/test') def test(): """Simple test endpoint""" return { 'status': 'ok', 'time': time.time(), 'width': WIDTH, 'height': HEIGHT, 'tile_size': TILE_SIZE, 'data_size': WIDTH * HEIGHT * 3 } # ===== 4. MAIN ===== def main(): print("="*60) print("๐ŸŽฏ CHECKER PATTERN SERVER") print("="*60) print(f"๐Ÿ“ก Port: {PORT}") print(f"๐ŸŽจ Resolution: {WIDTH}x{HEIGHT}") print(f"๐Ÿงฑ Tile size: {TILE_SIZE}") print(f"๐Ÿ“Š Data size per frame: {WIDTH * HEIGHT * 3} bytes") print("="*60) print("โœ… Server ready! Open in browser:") print(f" http://localhost:{PORT}") print("="*60) try: app.run( host='0.0.0.0', port=PORT, debug=False, threaded=True, use_reloader=False ) except Exception as e: print(f"โŒ Server error: {e}") if __name__ == "__main__": main()