main
Felix Pankratz 3 years ago
parent 611fb2f9ae
commit f97d517961

@ -0,0 +1,57 @@
#!/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
WIDTH, HEIGHT = 1000, 1000
def main():
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)
phase_pos = random.uniform(-0.5, 1.5)
circle_fill(ctx, phase_pos, 0.5, 0.5)
surface.write_to_png("out/moon.png") # Output to PNG
if __name__ == '__main__':
main()

@ -10,6 +10,14 @@ def circle_fill(ctx,x,y,r):
ctx.arc(x,y,r,0,math.pi*2.) ctx.arc(x,y,r,0,math.pi*2.)
ctx.fill() ctx.fill()
def draw_crater(ctx,x,y,r):
for n in range(3):
off_x = random.uniform(-0.01, 0.01)
off_y = random.uniform(-0.01, 0.01)
ctx.arc(x + off_x, y + off_y, r, 0, math.pi*2.)
ctx.fill()
def random_color(): def random_color():
red = random.uniform(0, 1) red = random.uniform(0, 1)

Loading…
Cancel
Save