def sierpinski_step(triangle_vertices): n = len(triangle_vertices) # 3 midpoints = [ midpoint(*pair_vertices) for pair_vertices in combinations(triangle_vertices, 2) ] res = [] for i, pair_midpoints in enumerate(combinations(midpoints, 2)): # res += (*pair_midpoints, triangle_vertices[(i+2)%3]) res += (*pair_midpoints, triangle_vertices[i]) return res
def brownian_island(frm, to, variance, scale, n): if n == 0: return [(frm, to)] m = midpoint(frm, to) rand_height = normal(0, sqrt(variance)) rand_width = normal(0, sqrt(variance)) m = m[0] + rand_width, m[1] + rand_height points = [] points += brownian_island(frm, m, variance / scale, scale, n - 1) points += brownian_island(m, to, variance / scale, scale, n - 1) return points
def brownian_bridge(frm, to, variance, scale): points = [] if abs(to[0] - frm[0]) < TOLERANCE: points += [(frm, to)] else: m = midpoint(frm, to) rand_height = normal(0, sqrt(variance)) m = m[0], m[1] + rand_height points += brownian_bridge(frm, m, variance / scale, scale) points += brownian_bridge(m, to, variance / scale, scale) return points
def horizontal_split(bottom_left, top_right): top_left, bottom_right = other_corners(bottom_left, top_right) return [midpoint(bottom_left, top_left), midpoint(bottom_right, top_right)]
def vertical_split(bottom_left, top_right): top_left, bottom_right = other_corners(bottom_left, top_right) return [midpoint(bottom_left, bottom_right), midpoint(top_left, top_right)]
def center(self): return midpoint(self._bottom_left, self._top_right)
def get_H_shape_lines(uc, lc): "return list of points to draw for the H shape given the upper corner and the lower corner" return [[midpoint(uc[0], lc[0]), midpoint(uc[1], lc[1])], [uc[0], lc[0]], [uc[1], lc[1]]]