params, offset, dark bg

gui
Felix Pankratz 3 years ago
parent da56786825
commit 97201be02f

@ -4,9 +4,19 @@ import cairo
import math import math
from utils import random_color from utils import random_color
WIDTH, HEIGHT = 256, 256
WAVES = 8
# dimensions of the output image
WIDTH, HEIGHT = 1024, 1024
# numbers of waves
WAVES = 10
# how much should the phases be offset?
WAVE_OFFSET = -0.7
# amplitude of the sine wave
AMPLITUDE = 25
# only 1 color with shades?
MONOCHROME = True
# background black? White otherwise:
DARK_BG = True
def main(): def main():
@ -17,21 +27,34 @@ def main():
wave_height = 1/WAVES wave_height = 1/WAVES
lastpoints = [(x/1000, 0) for x in range(1000)] lastpoints = [(x/1000, 0) for x in range(1000)]
if DARK_BG:
# make bg black
ctx.rectangle(0, 0, 1, 1)
ctx.set_source_rgb(0, 0, 0)
ctx.fill()
for num in range(WAVES): if MONOCHROME:
r, g, b = random_color() r, g, b = random_color()
alpha_step = 1/WAVES
for num in range(WAVES+1):
if not MONOCHROME:
r, g, b = random_color()
points = [] points = []
x = 0 x = 0
while x < 1: while x < 1:
y = math.sin(x*50) * 0.1 y = math.sin(x*AMPLITUDE + (num * WAVE_OFFSET) ) * 0.1
points.append((x, ( (y/4) + ((0.5+num)*wave_height)))) points.append((x, ( (y/4) + ((0.5+num)*wave_height))))
x += 0.001 x += 0.001
if not MONOCHROME:
ctx.set_source_rgb(r, g, b)
else:
ctx.set_source_rgba(r, g, b, 1 - (alpha_step * num)) # make more transparent toward bottom
# draw waves # draw waves
ctx.move_to(*points[0]) ctx.move_to(*points[0])
for p in points[1:]: for p in points[1:]:
ctx.line_to(*p) ctx.line_to(*p)
ctx.set_line_width(0.002) ctx.set_line_width(0.002)
ctx.set_source_rgb(r, g, b)
ctx.stroke() ctx.stroke()
# fill area above # fill area above
for pos in range(len(points)): for pos in range(len(points)):

Loading…
Cancel
Save