You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.7 KiB
Python

3 years ago
#!/usr/bin/env python3
import cairo
import math
import random
from utils import circle_fill
from utils import draw_crater
from utils import random_color
2 months ago
from utils import moon_shade
3 years ago
2 months ago
WIDTH, HEIGHT = 100, 100
3 years ago
def main():
2 months ago
import sys
seed = sys.argv[1]
random.seed(seed)
3 years ago
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context(surface)
ctx.scale(WIDTH, HEIGHT) # Normalizing the canvas
ctx.set_source_rgb(0.9, 0.9, 0.9)
# draw "full" moon
circle_fill(ctx, 0.5, 0.5, 0.5)
# make sure we only draw "inside"
ctx.set_operator(cairo.Operator.ATOP)
# draw craters
ctx.set_source_rgb(0.5, 0.5, 0.5)
for c in range(30):
#c_col = random.uniform(0.4, 0.6)
#ctx.set_source_rgb(c_col, c_col, c_col)
c_x = random.uniform(0.0, 1.0)
c_y = random.uniform(0.0, 1.0)
c_r = random.uniform(0.01, 0.1)
draw_crater(ctx, c_x, c_y, c_r)
# draw "aura"
a_r, a_g, a_b = random_color()
p = cairo.RadialGradient(0.5, 0.5, 0.25, 0.5, 0.5, 0.5)
#p.add_color_stop_rgba(0.0, 0.9, 0.9, 0.9, 0.0)
p.add_color_stop_rgba(0.0, a_r, a_g, a_b, 0.0)
p.add_color_stop_rgba(0.3, a_r, a_g, a_b, 0.0)
p.add_color_stop_rgba(1.0, a_r, a_g, a_b, 0.8)
ctx.set_source(p)
ctx.arc(0.5, 0.5, 0.5, 0, math.pi*2)
#ctx.arc(0.5, 0.5, 0.3, 0, math.pi*2)
ctx.fill()
# draw "shade" of the phase
ctx.set_source_rgba(0.1, 0.1, 0.1, 0.95)
2 months ago
phase_pos = random.uniform(-1.2, 1.2)
#circle_fill(ctx, phase_pos, 0.5, 0.5)
moon_shade(ctx, phase_pos)
surface.write_to_png(f"nft/{seed}_moon.png") # Output to PNG
3 years ago
if __name__ == '__main__':
main()