main
Felix Pankratz 2 months ago
parent 82c19b690b
commit 210e36fd9a

@ -6,13 +6,9 @@ from datetime import datetime
import calendar import calendar
import random import random
import colorsys import colorsys
import argparse
# dimensions of the output image
# how much should the phases be offset?
WAVE_OFFSET = math.pi / random.choice([1, 2, 4]) # -1.9
# background black? White otherwise:
DARK_BG = True
# precision of the calculation # precision of the calculation
PRECISION = 10000 PRECISION = 10000
@ -35,7 +31,12 @@ def get_amplitude_from_date(date: datetime, waves) -> float:
def create_wpotd( def create_wpotd(
width: int, height: int, date: datetime = datetime.now(), dark: bool = True width: int,
height: int,
frequency: int,
wave_offset: float,
date: datetime = datetime.now(),
dark: bool = True,
) -> cairo.ImageSurface: ) -> cairo.ImageSurface:
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
ctx = cairo.Context(surface) ctx = cairo.Context(surface)
@ -45,7 +46,6 @@ def create_wpotd(
lastpoints = [(x / PRECISION, 0) for x in range(PRECISION + 1)] lastpoints = [(x / PRECISION, 0) for x in range(PRECISION + 1)]
frequency = random.randint(10, 40)
waves = date.month waves = date.month
amplitude = get_amplitude_from_date(date, waves) amplitude = get_amplitude_from_date(date, waves)
@ -68,7 +68,7 @@ def create_wpotd(
x = 0 x = 0
while x < 1: while x < 1:
# step along, create points along the wave # step along, create points along the wave
y = amplitude * math.sin(frequency * x + (wave_index * WAVE_OFFSET)) y = amplitude * math.sin(frequency * x + (wave_index * wave_offset))
points.append((x, (y + (0.5 + wave_index) * wave_height))) points.append((x, (y + (0.5 + wave_index) * wave_height)))
x += step_size x += step_size
# print(f'Draw {len(points)} points for curve {num}') # print(f'Draw {len(points)} points for curve {num}')
@ -87,12 +87,43 @@ def create_wpotd(
ctx.fill() ctx.fill()
lastpoints = points lastpoints = points
return surface return surface
# surface.write_to_png(output) # Output to PNG
def main(): def main():
output = create_wpotd(1920, 1080, dark=False) parser = argparse.ArgumentParser()
output.write_to_png("out/waves.png") parser.add_argument("width", type=int, help="Width of the image")
parser.add_argument("height", type=int, help="Height of the image")
parser
parser.add_argument("--dark", help="Draw on dark background", action="store_true")
parser.add_argument(
"-o",
"--offset",
type=float,
help="How much the waves should be offset to each other",
)
parser.add_argument("-f", "--frequency", type=int, help="Frequency of the waves")
parser.add_argument(
"--stdout", help="Write output image to stdout", action="store_true"
)
args = parser.parse_args()
print(args)
if not args.offset:
args.offset = math.pi / random.choice([1, 2, 4])
if not args.frequency:
args.frequency = random.randint(10, 40)
output = create_wpotd(
args.width,
args.height,
dark=args.dark,
wave_offset=args.offset,
frequency=args.frequency,
)
if args.stdout:
import sys
output.write_to_png(sys.stdout.buffer)
else:
output.write_to_png("out/waves.png")
if __name__ == "__main__": if __name__ == "__main__":

Loading…
Cancel
Save