things n stuffs

main
Felix Pankratz 3 months ago
parent 2a3e2c03a0
commit d15eddd2bc

3
.gitignore vendored

@ -0,0 +1,3 @@
out/
__pycache__/
nft/

Binary file not shown.

@ -120,7 +120,7 @@ class Node():
def grow_sub(ctx, branch, branches, new_subs):
# create a sub branch based on length
sub_branches = len(branch.nodes) // 7 * 3
sub_branches = len(branch.nodes) // 8 * 2
if sub_branches == 0: return
#sub_branches = 4
#print(f'creating {sub_branches} subs')
@ -140,6 +140,7 @@ def grow_sub(ctx, branch, branches, new_subs):
break
if found_ang:
break
grow_branch_until_ended(new_branch, branches)
new_branch.set_ignores(branch.nodes)
branches.append(new_branch)
@ -154,8 +155,8 @@ def grow_subs(ctx, subs, branches):
new_subs = []
for branch in subs:
grow_sub(ctx, branch, branches, new_subs)
for branch in new_subs:
grow_branch_until_ended(branch, branches)
#for branch in new_subs:
# grow_branch_until_ended(branch, branches)
return new_subs
def main():
@ -172,6 +173,7 @@ def main():
# place seeds
branches = []
r, g, b = colorsys.hsv_to_rgb(start_hue, 1.0, 1.0)
#r, g, b = random_color()
ctx.set_source_rgb(r, g, b)
@ -203,6 +205,10 @@ def main():
print(f'iteration {x} done')
#surface.write_to_png("out/hyphae.png") # Output to PNG
r, g, b = colorsys.hsv_to_rgb(start_hue - 0.05, 1.0, 0.2)
ctx.set_source_rgb(r, g, b)
ctx.set_operator(cairo.Operator.DEST_OVER)
circle_fill(ctx, 0.5, 0.5, 0.4)
finally:
surface.write_to_png(f"out/hyphae_{run}_{rarity}.png") # Output to PNG
print(f'run {run} complete')

@ -6,10 +6,15 @@ import random
from utils import circle_fill
from utils import draw_crater
from utils import random_color
from utils import moon_shade
WIDTH, HEIGHT = 1000, 1000
WIDTH, HEIGHT = 100, 100
def main():
import sys
seed = sys.argv[1]
random.seed(seed)
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context(surface)
@ -48,10 +53,10 @@ def main():
# 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
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
if __name__ == '__main__':
main()

@ -5,7 +5,6 @@ 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()
@ -17,6 +16,34 @@ def draw_crater(ctx,x,y,r):
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():

Loading…
Cancel
Save