|
|
@ -2,38 +2,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
import cairo
|
|
|
|
import cairo
|
|
|
|
import math
|
|
|
|
import math
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
import calendar
|
|
|
|
|
|
|
|
import random
|
|
|
|
from utils import random_color
|
|
|
|
from utils import random_color
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# dimensions of the output image
|
|
|
|
# dimensions of the output image
|
|
|
|
WIDTH, HEIGHT = 1920, 1080
|
|
|
|
WIDTH, HEIGHT = 1920, 1080
|
|
|
|
# numbers of waves
|
|
|
|
|
|
|
|
WAVES = 12
|
|
|
|
|
|
|
|
# how much should the phases be offset?
|
|
|
|
# how much should the phases be offset?
|
|
|
|
WAVE_OFFSET = 0 - (math.pi/4)#-1.9
|
|
|
|
WAVE_OFFSET = math.pi / random.choice([1, 2, 4]) #-1.9
|
|
|
|
# amplitude of the sine wave
|
|
|
|
# amplitude of the sine wave
|
|
|
|
AMPLITUDE = 50
|
|
|
|
#AMPLITUDE = 9
|
|
|
|
# only 1 color with shades?
|
|
|
|
# only 1 color with shades?
|
|
|
|
MONOCHROME = True
|
|
|
|
MONOCHROME = True
|
|
|
|
# works only if monochrome is set - uses todays date as base for the color
|
|
|
|
# works only if monochrome is set - uses todays date as base for the color
|
|
|
|
DATE_BASED_COLOR = True
|
|
|
|
DATE_BASED_COLOR = True
|
|
|
|
|
|
|
|
DATE_BASED_AMPLITUDE = True
|
|
|
|
|
|
|
|
DATE_BASED_COUNT = True
|
|
|
|
# background black? White otherwise:
|
|
|
|
# background black? White otherwise:
|
|
|
|
DARK_BG = True
|
|
|
|
DARK_BG = True
|
|
|
|
# precision of the calculation
|
|
|
|
# precision of the calculation
|
|
|
|
PRECISION = 10000
|
|
|
|
PRECISION = 10000
|
|
|
|
|
|
|
|
|
|
|
|
def todays_color():
|
|
|
|
def days_color(date):
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
import colorsys
|
|
|
|
import colorsys
|
|
|
|
import calendar
|
|
|
|
|
|
|
|
# a day between 1 and 365 (inclusive)
|
|
|
|
# a day between 1 and 365 (inclusive)
|
|
|
|
today = datetime.datetime.now().timetuple().tm_yday
|
|
|
|
today = date.timetuple().tm_yday
|
|
|
|
year = datetime.datetime.now().year
|
|
|
|
year = date.year
|
|
|
|
days_in_year = 365 + calendar.isleap(year)
|
|
|
|
days_in_year = 365 + calendar.isleap(year)
|
|
|
|
# between 0 and 1, how far through the year are we?
|
|
|
|
# between 0 and 1, how far through the year are we?
|
|
|
|
progress = today/days_in_year
|
|
|
|
progress = today/days_in_year
|
|
|
|
return colorsys.hsv_to_rgb(progress, 1, 1)
|
|
|
|
return colorsys.hsv_to_rgb(progress, 1, 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def days_amp(date, waves):
|
|
|
|
|
|
|
|
day = date.day
|
|
|
|
|
|
|
|
days_in_month = calendar.monthrange(date.year, date.month)[1]
|
|
|
|
|
|
|
|
max_amp = 1/waves/2
|
|
|
|
|
|
|
|
return day/days_in_month * max_amp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def days_count(date):
|
|
|
|
|
|
|
|
return date.month
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
|
|
|
|
|
|
|
@ -42,10 +51,20 @@ def main():
|
|
|
|
|
|
|
|
|
|
|
|
ctx.scale(WIDTH, HEIGHT) # Normalizing the canvas
|
|
|
|
ctx.scale(WIDTH, HEIGHT) # Normalizing the canvas
|
|
|
|
|
|
|
|
|
|
|
|
wave_height = 1/WAVES
|
|
|
|
|
|
|
|
step_size = 1/PRECISION
|
|
|
|
step_size = 1/PRECISION
|
|
|
|
|
|
|
|
|
|
|
|
lastpoints = [(x/PRECISION, 0) for x in range(PRECISION+1)]
|
|
|
|
lastpoints = [(x/PRECISION, 0) for x in range(PRECISION+1)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#date = datetime.datetime.strptime('2021-01-01', '%Y-%m-%d')
|
|
|
|
|
|
|
|
date = datetime.datetime.today()
|
|
|
|
|
|
|
|
frequency = random.randint(10, 40)
|
|
|
|
|
|
|
|
if DATE_BASED_COUNT:
|
|
|
|
|
|
|
|
waves = days_count(date)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
waves = 12
|
|
|
|
|
|
|
|
if DATE_BASED_AMPLITUDE:
|
|
|
|
|
|
|
|
amplitude = days_amp(date, waves)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
amplitude = 25
|
|
|
|
if DARK_BG:
|
|
|
|
if DARK_BG:
|
|
|
|
# make bg black
|
|
|
|
# make bg black
|
|
|
|
ctx.rectangle(0, 0, 1, 1)
|
|
|
|
ctx.rectangle(0, 0, 1, 1)
|
|
|
@ -53,17 +72,21 @@ def main():
|
|
|
|
ctx.fill()
|
|
|
|
ctx.fill()
|
|
|
|
|
|
|
|
|
|
|
|
if MONOCHROME:
|
|
|
|
if MONOCHROME:
|
|
|
|
r, g, b = random_color()
|
|
|
|
if DATE_BASED_COLOR:
|
|
|
|
alpha_step = 1/WAVES
|
|
|
|
r, g, b = days_color(date) #datetime.datetime.now())
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
r, g, b = random_color()
|
|
|
|
|
|
|
|
alpha_step = 1/waves
|
|
|
|
|
|
|
|
|
|
|
|
for num in range(WAVES+1):
|
|
|
|
wave_height = 1/waves
|
|
|
|
|
|
|
|
for num in range(waves+1):
|
|
|
|
if not MONOCHROME:
|
|
|
|
if not MONOCHROME:
|
|
|
|
r, g, b = random_color()
|
|
|
|
r, g, b = random_color()
|
|
|
|
points = []
|
|
|
|
points = []
|
|
|
|
x = 0
|
|
|
|
x = 0
|
|
|
|
while x < 1:
|
|
|
|
while x < 1:
|
|
|
|
y = math.sin(x*AMPLITUDE + (num * WAVE_OFFSET) ) * 0.1
|
|
|
|
y = amplitude * math.sin(frequency * x + (num * WAVE_OFFSET) )
|
|
|
|
points.append((x, ( (y/4) + ((0.5+num)*wave_height))))
|
|
|
|
points.append((x, ( (y) + ((0.5+num)*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}')
|
|
|
|
if not MONOCHROME:
|
|
|
|
if not MONOCHROME:
|
|
|
|