def main(): from modules.render import Render from modules.tree import Tree from time import time while True: render = Render(SIZE, FRONT, BACK, TRUNK, TRUNK_STROKE, GRAINS) render.ctx.set_source_rgba(*FRONT) render.ctx.set_line_width(ONE) # TODO :does not work with transparent bg. use operators #render.clear_canvas() tree = Tree(MID, 0.9, INIT_BRANCH, -pi * 0.5, ONE, ONE, BRANCH_SPLIT_ANGLE, BRANCH_PROB_SCALE, BRANCH_DIMINISH, BRANCH_SPLIT_DIMINISH, BRANCH_ANGLE_MAX, BRANCH_ANGLE_EXP) i = 1 while tree.Q: i += 1 tree.step() map(render.branch2, tree.Q) if not i % 200: print i, len(tree.Q) render.sur.write_to_png( '/media/var/andreas_tree/test_bp42_{:10.0f}.png'.format(time()))
def __init__(self, n, back, front, params): Render.__init__(self, n, front, back) # scale down canvas so random drift doesn't get clipped self.scale(0.6) numSplines = params['numSplines'] sectionCount = params['sectionCount'] noiseScale = params['noiseScale'] noiseDetail = params['noiseDetail'] density = params['density'] radius = params['radius'] decayRadius = params['decayRadius'] radiusDecay = params['radiusDecay'] # computed self.alpha = n * 0.000005 * (1.0 + random() * 0.1) # self.alpha = n * 0.00003 * (1.0+random()*0.1) # if self.alpha < 0.05: # self.alpha = 0.08 # if self.alpha < 0.03: self.alpha = 0.055 print('===========') print("spline count: " + str(numSplines)) print("section count: " + str(sectionCount)) print("noise: " + str(noiseScale)) print("detail: " + str(noiseDetail)) print("alpha: " + str(self.alpha)) print("radiusDecay: " + str(radiusDecay)) # load up sampler self.sampler = self.get_colors_from_file('img/check.png') # create splines self.splines = [] for i in range(numSplines): self.splines.append( SandSpline(sectionCount, radius, noiseScale, noiseDetail, density)) if decayRadius: radius -= radiusDecay
choices.shape # offset each x, y choice row by center x, y choices = centers + choices # reshape array from numpy import array, concatenate xys = [] for cell in list(choices.reshape((rows * rows,2,n))): for itm in cell.reshape(n,2): xys.append(itm.tolist()) print(len(xys)) %load_ext helpers.ipython_cairo from modules.render import Render from modules.color import hex_to_rgba CANVAS_SQUARE_SIZE = 800 PIXEL = 1.0 / CANVAS_SQUARE_SIZE BACKGROUND = hex_to_rgba("#EEAA22") FOREGROUND = hex_to_rgba("#00000022") render = Render(CANVAS_SQUARE_SIZE, BACKGROUND, FOREGROUND) render.remap(domain=(0, size), range=(0, size)) for xy in xys: render.dot(xy) render.ctx
x_off = linspace(0, sin(theta) * scale, circle_count) y_off = linspace(0, cos(theta) * scale, circle_count) stack = [] for r, dx, dy in zip(rads, x_off, y_off): stack.append(Circle(pos[0] + dx, pos[1] + dy, r)) return stack circle_stacks = list(map(circle_stack, centers)) circle_stacks %load_ext helpers.ipython_cairo from modules.render import Render from modules.color import hex_to_rgba CANVAS_SQUARE_SIZE = 2400 PIXEL = 1.0 / CANVAS_SQUARE_SIZE # BACKGROUND = hex_to_rgba("#f9f8f4") BACKGROUND = hex_to_rgba("#EEAA22") # FOREGROUND = hex_to_rgba("#ec3636") FOREGROUND = hex_to_rgba("#000000") render = Render(CANVAS_SQUARE_SIZE, BACKGROUND, FOREGROUND) render.remap(domain=(0, 1), range=(0, 1)) render.set_line_width(1.0 * PIXEL) for stack in circle_stacks: for circle in stack: render.circle(circle.x, circle.y, circle.r) render.ctx
def __init__(self, n, back, front): Render.__init__(self, n, front, back)
noise = generate_perlin_noise_2d((noise_density, noise_density), (8, 8)) theta = noise * 2 * np.pi xs = np.sin(theta) ys = np.cos(theta) flow_field = np.column_stack((xs.flatten(), ys.flatten())).reshape(noise_density, noise_density, 2) flow_field.shape %load_ext helpers.ipython_cairo from modules.render import Render from modules.color import hex_to_rgba from numpy import array, pi, cos, sin, column_stack CANVAS_MULT = 8 CANVAS_SQUARE_SIZE = noise_density * CANVAS_MULT BACKGROUND = hex_to_rgba("#332633") FOREGROUND = hex_to_rgba("#ee99aa") DEBUG = hex_to_rgba("#ff00ee") render = Render(CANVAS_SQUARE_SIZE, BACKGROUND, DEBUG) # render.remap(domain=(-0.05, 1.05), range=(-0.05, 1.05)) render.remap(domain=(0, noise_density * CANVAS_MULT), range=(0, noise_density * CANVAS_MULT)) render.set_line_width(1.0) for y in range(noise_density): for x in range(noise_density): a = array((x, y)) * CANVAS_MULT # space out for display b = a + flow_field[x][y] * CANVAS_MULT * 1.2 render.line(a, b) render.ctx
rectangle(x,y,pix,pix) fill() #%% from modules.render import Render BACK = [1, 1, 1, 1] FRONT = [1, 0, 0, 1] size = 600 sand = Sand(size) sand.init() render = Render(size, BACK, FRONT) render.set_line_width(sand.one) bob = sand.draw(render) bob[0] # for pt in Circle(r=RAD).to_points(10): # x, y = pt # render.circle(x, y, .05, fill=True) # render.set_front([0, 1, 0, 1]) # for pt in xys: # x, y = pt # render.circle(x, y, .01, fill=True) # render.ctx
# each walker has X agents all starting on a horizontal line - vertically centered AGENT_COUNT = 256 * 2 # how should random walks scale in the X and Y direction SCALE = array((0.2, 1), dtype="float") * 0.025 * ONE_PIXEL from modules.render import Render from modules.walkers import Walkers walkers = [] for i in range(WALKER_COUNT): scale = random(2) * SCALE res = int(random(1)[0] * 3) + 1 w = Walkers(AGENT_COUNT, scale, pnoise_res=res).perlin() walkers.append(w) render = Render(CANVAS_SQUARE_SIZE, BACKGROUND, COLORS[0]) render.remap(domain=(0 - EDGE_PADDING_PERC, 1 + EDGE_PADDING_PERC), range=(0.5, -0.5)) render.set_line_width(0.2 * ONE_PIXEL) ITER = 256 render.set_operator(Operator.OVER) # render.set_operator(Operator.ADD) # render.set_operator(Operator.SCREEN) # render.set_operator(Operator.COLOR_DODGE) for _ in range(ITER): for k, w in enumerate(walkers): col = COLORS[k % len(COLORS)] col[3] = ALPHA render.set_front(col) dots = next(w)
def main(): # Width/height of final image (in pixels) SURF_SIZE = 2400 # Size of cell in nearest-neighbors grid (in pixels) CELL_SIZE = 2 # Minimum node radius allowed (in pixels) MIN_RAD = 12 # Radius of initial node(s) NODE_RAD = SURF_SIZE * 0.025 # Radius of boundary circle BOUND_RAD = SURF_SIZE * 0.4 # During initialization of the root, only nodes inside # the radius of BOUND_RAD * BOUND_BUFF will be created. # This ensures that the first few nodes aren't too close # to the boundary. BOUND_BUFF = 0.5 # Number of initial nodes; if greater than one, the root # system will be composed of multiple roots. NODE_NUM = 1 """ NO SPLIT OR BRANCH (ie. SINGLE CHILD) (1) | (2) | SPLIT (1) | (2) / \ BRANCH (1) | (2) /| or (1) | (2) |\ or (1) | (2) /|\ """ # split_rate: Probability that a node splits next iteration # branch_rate: Probability that a node branches next iteration # single_child_rad_rat: Ratio of single child's radius to parent's radius # split_child_rad_rat: Ratio of split child's radius to parent's radius # branch_child_rad_rat: Ratio of branch child's radius to parent's radius # single_child_angle_sigma: Single child's random (standard) deviation from parent's direction of travel # split_child_angle_dev: Split child's constant angular deviation from parent's direction of travel # branch_child_angle_dev: Branch child's constant angular deviation from parent's direction of travel # child_split_k: Ratio of child's splitting probability and parent's splitting probability # child_branch_k: Ratio of child's branching probability and parent's branching probability DEFAULT_NODE_KWARGS = { "split_rate": 0.20, "branch_rate": 0.10, "single_child_rad_rat": 0.95, "split_child_rad_rat": 0.925, "branch_child_rad_rat": 0.85, "single_child_angle_sigma": math.pi / 18, "split_child_angle_dev": math.pi / 6, "branch_child_angle_dev": math.pi / 3, "child_split_k": 1.0075, "child_branch_k": 1.0075 } DEFAULT_ROOT_KWARGS = { "surf_size": SURF_SIZE, "cell_size": CELL_SIZE, "min_rad": MIN_RAD, "node_rad": NODE_RAD, "bound_rad": BOUND_RAD, "bound_buff": BOUND_BUFF, "node_num": NODE_NUM, "node_kwargs": DEFAULT_NODE_KWARGS } render = Render(SURF_SIZE, SURF_SIZE, 1.0, 0.15) root = initialize_root_system(**DEFAULT_ROOT_KWARGS) try: tic = time.time() root.generate() toc = time.time() print "Simulation took %.3f sec" % (toc - tic) tic = time.time() render.draw_root(root) toc = time.time() print "Drawing took %.3f sec" % (toc - tic) render.save_png("img/hyphae-{}.png".format(int(time.time())), verbose=True) except KeyboardInterrupt as e: print "Keyboard Interruption:" render.save_png("img/hyphae-{}.png".format(int(time.time())), verbose=True)
Ressources.yearOffset = 2020 if (Ressources.configFileExists and Ressources.screenConf != []): screenWidth = int(Ressources.screenConf[0].getAttribute("width")) screenHeight = int(Ressources.screenConf[0].getAttribute("height")) Ressources.getScores() else: screenWidth = 500 screenHeight = 500 Ressources.maxScore = {"value": "0", "date": "00000000"} Ressources.minScore = {"value": "0", "date": "00000000"} Ressources.scores = [] screen = pygame.display.set_mode([screenWidth, screenHeight]) Ressources.running = True clock = pygame.time.Clock() rend = Render(screenWidth, screenHeight, screen) if (Ressources.canContinue): Render.getSave() pygame.display.update() #----gameVariables Ressources.selected = -1 mousePos = pygame.mouse.get_pos() Ressources.selectedGameObject = 0 Ressources.mouseOffset = (0, 0) Ressources.screen = screen while Ressources.running: mousePos = pygame.mouse.get_pos()
idx = (p.points * 255).astype(int) samps = array(list(map(lambda i: flow_field[i[0]][i[1]], idx))) samps *= 0.0333 p.points += samps polys.append(p) %load_ext helpers.ipython_cairo from modules.render import Render from modules.color import hex_to_rgba CANVAS_SQUARE_SIZE = 2400 PIXEL = 1.0 / CANVAS_SQUARE_SIZE BACKGROUND = hex_to_rgba("#332633") FOREGROUND = hex_to_rgba("#ee99aa99") DEBUG = hex_to_rgba("#ff00ee") render = Render(CANVAS_SQUARE_SIZE, BACKGROUND, FOREGROUND) render.remap(domain=(-0.05, 1.05), range=(-0.05, 1.05)) render.set_line_width(4.0 * PIXEL) for poly in polys: render.set_front(FOREGROUND) render.path(poly.vertices(), closed=True) # render.set_front(BACKGROUND) # for v in poly.vertices(): # render.circle(v, 0.001) render.ctx
count = 16 grid = Grid(1, 1, count, count, padding=-0.001) lines = [] for rect in grid.cells(): poly = rect.resample(num=40) c = rect.center() + ((random(2) - 0.5) * 0.03) for vert in poly.vertices(): lines.append(Line(c, vert)) # len(lines) %load_ext helpers.ipython_cairo from modules.render import Render from modules.color import hex_to_rgba CANVAS_SQUARE_SIZE = 2400 PIXEL = 1.0 / CANVAS_SQUARE_SIZE BACKGROUND = hex_to_rgba("#EEAA22") FOREGROUND = hex_to_rgba("#000000") render = Render(CANVAS_SQUARE_SIZE, BACKGROUND, FOREGROUND) render.remap(domain=(0, 1), range=(0, 1)) render.set_line_width(1.6 * PIXEL) for line in lines: a, b = line.vertices() render.line(a, b) # render.circle(pt, 0.01) render.ctx