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.

54 lines
1.4 KiB
Python

#!/usr/bin/env python3
import random
import math
def circle(ctx,x,y,r):
ctx.arc(x,y,r,0,math.pi*2.)
ctx.stroke()
def circle_fill(ctx,x,y,r):
ctx.arc(x,y,r,0,math.pi*2.)
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 moon_shade(ctx, phase, nothern=True):
#phase=-0.4
#x_max = 0.7
x_max = 1.
# the shadow always has to "hug" one side - pick which
ctx.move_to(0.5, 0.0)
if phase > 0:
ctx.curve_to(-0.2, 0, -0.2, 1, 0.5, 1)
elif phase < 0:
ctx.curve_to(1.2, 0, 1.2, 1, 0.5, 1)
else:
return
#ctx.close_path()
#ctx.fill()
#ctx.move_to(0.5, 0.0)
#ctx.curve_to(x_max*phase, 0.5-(0.5*phase), x_max*phase, 0.5+(0.5*phase), 0.5, 1)
#ctx.curve_to(0.5 + (x_max*phase), 0.5+(0.5*phase), 0.5+ (x_max*phase), 0.5-(0.5*phase), 0.5, 0)
# helper x is the same for both points
h_x = abs(x_max * phase)
h_y = abs(h_x - 0.5)
#y_c = (phase * 0.5)
#ctx.curve_to(x_max*phase, 0.5+abs(0.5*phase-0.5), (x_max*phase), 0.5-abs(0.5*phase-0.5), 0.5, 0)
ctx.curve_to(h_x, 0.5 + h_y, h_x, 0.5-h_y, 0.5, 0)
#ctx.close_path()
ctx.fill()
def random_color():
red = random.uniform(0, 1)
green = random.uniform(0, 1)
blue = random.uniform(0, 1)
return red, green, blue