Reihen und Raster 05 : Reihe mit Oszillatoren
Abschlussbedingungen
from time import time
from math import pi, sin, asin, cos
import random
import pgzrun
WIDTH, HEIGHT = 500, 500
teiler = 20
def skaliere_nach(wert, von_min, von_max, nach_min, nach_max):
bereich_von = von_max - von_min
bereich_nach = nach_max - nach_min
return (((wert - von_min) * bereich_nach) / bereich_von) + nach_min
def sinus_oszillator(frequenz, wert_min, wert_max, zeit_versatz=0):
t = time() + zeit_versatz
t = t * pi * 2 * frequenz
wert = sin(t)
return skaliere_nach(wert, -1, 1, wert_min, wert_max)
def update():
pass
def draw():
random.seed(1)
screen.fill("black")
abstand = int(WIDTH / (teiler-1))
radius = int(abstand / 2)
for x in range(0, WIDTH+1, abstand):
frequenz = random.uniform(0.25, 0.5)
mitte = HEIGHT/2
weite = random.uniform(HEIGHT/10, HEIGHT/4)
wert_min = mitte - weite
wert_max = mitte + weite
y = sinus_oszillator(frequenz, wert_min, wert_max)
screen.draw.circle((x, y), radius, "white")
pgzrun.go( )
Zuletzt geändert: Donnerstag, 27. März 2025, 08:26