48 lines
1.1 KiB
Plaintext
48 lines
1.1 KiB
Plaintext
"""
|
|
Plasmas with Palette Looping
|
|
https://lodev.org/cgtutor/plasma.html#Plasmas_with_Palette_Looping_
|
|
"""
|
|
|
|
pal = [0] * 128
|
|
r = 42
|
|
g = 84
|
|
b = 126
|
|
rd = gd = bd = False
|
|
|
|
def setup():
|
|
global buffer
|
|
size(600, 600)
|
|
frameRate(25)
|
|
buffer = [None] * width * height
|
|
for x in range(width):
|
|
for y in range(width):
|
|
value = int(((128 + (128 * sin(x / 32.0)))
|
|
+ (128 + (128 * cos(y / 32.0)))
|
|
+ (128 + (128 * sin(sqrt((x * x + y * y)) / 32.0)))) / 4)
|
|
buffer[x + y * width] = value
|
|
|
|
def draw():
|
|
global r, g, b, rd, gd, bd
|
|
if r > 128: rd = True
|
|
if not rd: r += 1
|
|
else: r-=1
|
|
if r < 0: rd = False
|
|
if g > 128: gd = True
|
|
if not gd: g += 1
|
|
else: g- = 1
|
|
if r < 0: gd = False
|
|
if b > 128: bd = True
|
|
if not bd: b += 1
|
|
else: b- = 1
|
|
if b < 0: bd = False
|
|
|
|
for i in range(128):
|
|
s_1 = sin(i * PI / 25)
|
|
s_2 = sin(i * PI / 50 + PI / 4)
|
|
pal[i] = color(r + s_1 * 128, g + s_2 * 128, b + s_1 * 128)
|
|
|
|
loadPixels()
|
|
for i, b in enumerate(buffer):
|
|
pixels[i] = pal[(b + frameCount) % 127]
|
|
updatePixels()
|