def _get_tree_line(self, wall, verts, indices): v1, v2 = wall # We want to draw back to front, so larger y value first if v1.y < v2.y: v1, v2 = v2, v1 Dx, Dy = v2.x - v1.x, v2.y - v1.y sparsity = 20.0 density = sqrt(distance_squared(v1, v2)) / sparsity if not density: return dy, dx = Dy / density, Dx / density x, y = v1 x_going_right = (dx > 0) while y > v2.y and ((x < v2.x) == x_going_right): jitter = gauss(0, 0.25) indices.extend(self._triangle_indices(len(verts))) verts.extend( self._mesh_box( self._choose_tex(), x + jitter * dy, y + jitter * dx, scale=0.3 ) ) x, y = x + dx, y + dy
def __init__(self, margin=60, dims=WINDOW_SIZE): self.dims = Size(*dims) self.min_distance = sum(dims) / 18 self.margin = margin points = [ Coords(floor(x) + self.margin, floor(y) + self.margin) for x, y in sample_poisson_uniform(self.dims.w - self.margin * 2, self.dims.h - self.margin * 2, self.min_distance, # Sample points for Poisson, arbitrary 30) ] self.graph = nx.Graph() self.graph.add_nodes_from(points) for triangle in computeDelaunayTriangulation(points): self.graph.add_edges_from(chain(*[ [(points[firstIndex], points[secondIndex]), (points[secondIndex], points[firstIndex])] for firstIndex, secondIndex in combinations(triangle, 2) ])) wall_crossings, self.wall_dict = self.computeWalls() self.walls = [cross.wall for cross in wall_crossings] self.removeMultiWallEdges() self.addCrossings(wall_crossings) # can't use edges_iter here since we're modifying it dist_squared = self.min_distance ** 2 for v1, v2, attrs in self.graph.edges(data=True): if distance_squared(v1, v2) > 2 * dist_squared: self.graph.remove_edge(v1, v2) if not nx.is_connected(self.graph): self.graph.add_edge(v1, v2, attrs)