def get_points(self): rotation = util.try_default(lambda: int(self.rotation.get()), 0) sides = max(util.try_default(lambda: int(self.sides.get()), 0), 3) points = np.array( list( map(lambda v: [math.cos(v), math.sin(v)], [ i * 2 * math.pi / sides + math.radians(rotation) for i in range(sides) ]))) points *= util.try_default(lambda: int(self.radius.get()), 0) points += self.centre return points.astype(int).tolist()
def subdivide(self): val = util.try_default(lambda: int(Smooth.min_angle.get()), 0) if int(val) > 180: min_angle = math.pi else: min_angle = math.radians(int(val)) for obj, newObj in zip(self.objects, self.adjusted): points = obj['points'] splits = [] for i, (p1, p2, p3) in enumerate( zip(np.roll(points, -1, 0), points, np.roll(points, 1, 0))): a = math.atan2(*(p1 - p2)[::-1]) b = math.atan2(*(p3 - p2)[::-1]) angle = a - b angle = abs(angle) angle = [angle, 2 * math.pi - angle][angle > math.pi] #angle += [0, 2*math.pi][angle<0] if angle < min_angle: splits.append(i) splits = np.array(splits, int) new = convolve1d(points, (1, 1), axis=0, mode='wrap') / 2 splitShape = np.zeros((len(points) * 2, 2)) splitShape[1::2, :] = new splitShape[0::2, :] = points convolved = convolve1d(splitShape, self.rule, axis=0, mode='wrap') / sum(self.rule) #print(type(convolved), convolved, type(points), type(splits)) convolved[splits * 2] = np.array(points)[splits] newObj['points'] = convolved.tolist()
def render(self): if get_cursor_focus(): a = math.atan2(*(self.centre - shared.god.get_cursor_position() )) - self.start_angle self.angle.set(str(int(math.degrees(a)))) else: a = math.radians(util.try_default(lambda: int(self.angle.get()), 0)) rot = np.array([[math.cos(a), -math.sin(a)], [math.sin(a), math.cos(a)]], float) for old, new in zip(self.objects, self.adjusted): if new['type'] == 'polygon': new['points'] = np.array( [((point - self.centre) @ rot) + self.centre for point in old['points']], int) elif new['type'] in ('circle', 'text'): new['pos'] = (old['pos'] - self.centre) @ rot + self.centre for old, new in zip(self.constraints, self.adjusted_constraints): new['pos'] = ((old['pos'] - self.centre) @ rot + self.centre).astype(int) super().render()
def apply(self): if util.try_default(lambda: int(self.radius.get()), 0) < 10: set_error('Radius too small') return super().apply() set_error('N-Gon Created') insert()
def render(self): if get_cursor_focus(): self.pos = shared.god.get_cursor_position().tolist() size = util.try_default(lambda: int(self.size.get()), 0) if len(self.content.get()) != 1 or size < 10: self.obj = None else: self.obj = { 'type': 'text', 'char': self.content.get(), 'size': int(self.size.get()), 'pos': self.pos } super().render()
def render(self): if self.pos is not None: if get_cursor_focus(): delta = self.pos - shared.god.get_cursor_position() radius = round(math.sqrt(sum(delta**2))) self.radius.set(str(radius)) else: radius = util.try_default(lambda: int(self.radius.get()), 0) if radius < 2: return self.obj = { 'type': 'circle', 'radius': radius, 'pos': self.pos.tolist() } super().render()
def render(self): if get_cursor_focus(): delta = (shared.god.get_cursor_position() - self.centre).astype(int) [t.set(str(v)) for v, t in zip(delta, self.strPos)] else: delta = np.array([ util.try_default(lambda: int(var.get()), 0) for var in self.strPos ], dtype=int) for old, new in zip(self.objects, self.adjusted): if old['type'] == 'polygon': new['points'] = old['points'] + delta elif old['type'] in ('circle', 'text'): new['pos'] = old['pos'] + delta for old, new in zip(self.constraints, self.adjusted_constraints): new['pos'] = old['pos'] + delta super().render()