Created
August 20, 2021 19:47
-
-
Save warvariuc/b7444c5ef86665f7cc6afe059d44bf6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import math | |
import pygame | |
WIDTH = 320 # width of screen | |
HEIGHT = 240 # height of screen | |
FPS = 30 # frames per second setting | |
def draw_frame(pixels): | |
zoom = 1 / len(pixels) | |
_time = time.time() | |
for y, row in enumerate(pixels): | |
yy = y * zoom | |
for x, pixel in enumerate(row): | |
xx = x * zoom | |
# Making and summing components | |
# https://web.archive.org/web/20210119091116/http://www.bidouille.org/prog/plasma | |
v = 0 | |
# Vertical wave | |
v += math.sin((xx * 10 + _time)) | |
# Wave from left to right | |
v += math.sin((yy * 10 + _time) / 2.0) | |
# Diagonal component | |
v += math.sin((xx * 10 + yy * 10 + _time) / 2.0) | |
# Circular component | |
cx = xx + .5 * math.sin(_time / 5.0) | |
cy = yy + .5 * math.cos(_time / 3.0) | |
v += math.sin(math.sqrt(100 * (cx * cx + cy * cy) + 1) + _time) | |
pixel[:] = ( | |
255 * (.5 + .5 * math.sin(math.pi * v)), | |
255 * (.5 + .5 * math.cos(math.pi * v)), | |
0 | |
) | |
def main(): | |
pygame.display.init() | |
fpsClock = pygame.time.Clock() | |
screen = pygame.display.set_mode((WIDTH, HEIGHT), pygame.DOUBLEBUF, 32) | |
pixels = pygame.surfarray.pixels3d(screen) | |
done = False | |
while not done: | |
draw_frame(pixels) | |
pygame.display.update() | |
fpsClock.tick(FPS) | |
for e in pygame.event.get(): | |
if e.type == pygame.QUIT: | |
pygame.quit() | |
done = True | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment