33 lines
776 B
Python
Executable File
33 lines
776 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import os
|
|
import numpy as np
|
|
import pygame
|
|
|
|
Nx = int(sys.argv[1])
|
|
Ny = int(sys.argv[2])
|
|
try:
|
|
frequency = float(sys.argv[3])
|
|
except (IndexError, ValueError):
|
|
frequency = 5
|
|
|
|
fps = 30
|
|
amplitude = 105
|
|
offset = 150
|
|
t = 0
|
|
|
|
x,y = np.meshgrid(np.linspace(0, 2*np.pi * min(1, Nx/Ny), Nx), np.linspace(0, 2*np.pi * min(1, Ny/Nx), Ny))
|
|
kx = x + y
|
|
|
|
clock = pygame.time.Clock()
|
|
|
|
while True:
|
|
t = t + 1e-3
|
|
R = amplitude * np.sin(kx - 2 * np.pi * frequency * t) + offset
|
|
G = amplitude * np.sin(kx - 2 * np.pi * frequency * t + 2*np.pi/3) + offset
|
|
B = amplitude * np.sin(kx - 2 * np.pi * frequency * t + 4*np.pi/3) + offset
|
|
|
|
out = np.dstack((R,G,B)).astype(np.uint8).tobytes()
|
|
os.write(1, out)
|
|
clock.tick_busy_loop(fps) |