def __new__(*args, **kwargs): rc = kwargs["rc"] # circumcircle radius del(kwargs["rc"]) a = rc / (np.sqrt(3) / 3) h = rc / (np.sqrt(3) / 2) center = kwargs["center"] del(kwargs["center"]) rotate = kwargs["rotate"] if "rotate" in kwargs else False if "rotate" in kwargs: del(kwargs["rotate"]) rotate = -1 if rotate else 1 triangle = Polygon([(0., -rc * rotate), (-a / 2, (h / 2) * rotate), (a / 2, (h / 2) * rotate)], **kwargs) triangle.translate(center[0], center[1]) return triangle
def make_polygon( self, width: float, height: float, pct_jitter_vertices: float, rand_range=True, color=None, ): """Make an individual polygon with points offset from panel.insert""" points = self.calculate_polygon_points(width, height) if pct_jitter_vertices: points = self.jitter_polygon_points(points, width, height, pct_jitter_vertices, rand_range=rand_range) offset_points = [(x + self.insert[0], y + self.insert[1]) for x, y in points] shape = Polygon( points=offset_points, stroke=color or "black", fill_opacity=0.0, stroke_width=1, ) return shape
def _put_triangle(self, cell, x, y, fill, stone_size): cell.add( Polygon([(x, (y - stone_size / 4)), ((x - stone_size / 4), (y + stone_size / 4)), ((x + stone_size / 4), (y + stone_size / 4))], fill=fill, stroke=fill))
def __new__(*args, **kwargs): r = kwargs["r"] del(kwargs["r"]) center = kwargs["center"] del(kwargs["center"]) m = r / 3 cross = Polygon([(-m, -r), (m, -r), (m, -m), (r, -m), (r, m), (m, m), (m, r), (-m, r), (-m, m), (-r, m), (-r, -m), (-m, -m)], **kwargs) cross.translate(center[0], center[1]) cross.rotate(45, (0., 0.)) return cross
for i in range(len(x_p2)): x_p2[i] += x_p0_max y_p2 = [] for i in range(1, len(y_p0)): if center_y_rand: d = y_p0[i] - y_p0[i - 1] y_p2.append( random.randint(y_p0[i - 1] + int(0.45 * d), y_p0[i - 1] + int(0.55 * d))) else: y_p2.append(random.randint(y_p0[i - 1], y_p0[i] - 1)) p2 = list(zip(x_p2, y_p2)) for i in range(len(p2)): dwg.add( Polygon([p0[i], p2[i], p0[i + 1]], fill=get_color([p0[i], p2[i], p0[i + 1]]))) for i in range(len(p2) - 1): dwg.add( Polygon([p2[i], p0[i + 1], p2[i + 1]], fill=get_color([p2[i], p0[i + 1], p2[i + 1]]))) x_p2_max = max(x_p2) if width - x_p2_max > step_max: x_p1 = [] for i in range(triangle_leftest + 1): x_p1.append(random.randint(step_min, step_max)) for i in range(len(x_p1)): x_p1[i] += x_p2_max