Swirl (Code)
class Swirl:
def __init__(self):
self.timestep = 0
self.parameter1 = 0
def update(self):
self.timestep = math.sin(time.time() / 18) * 1500
self.parameter1 = pyxel.mouse_x / WIDTH
def draw(self):
...
if self.swirl(x, y, self.timestep) > 0.2:
col = random.randint(5, 6)
pyxel.pset(x, y, col)
def swirl(self, x, y, step):
x -= (WIDTH/2.0)
y -= (HEIGHT/2.0)
dist = math.sqrt(pow(x, 2) + pow(y, 2))
angle = (step / 10.0) + dist / 1.5
s = math.sin(angle)
c = math.cos(angle)
xs = x * c - y * s
ys = x * s + y * c
r = abs(xs + ys)
val = max(0.0, 0.7 - min(1.0, r/8.0))
return val