def tosector0(pos): px, py = pos px = abs(px) py = abs(py) if py < 1 / math.sqrt(3) * px: px, py = math.R(math.radians(60), (px, py)) elif py < math.sqrt(3) * px: px, py = R1((px, py)) return px, py
def polygon(self, f=1): theta = 30 if math.dot(self.pos, (C15, -S15)) < 0 else -60 theta = -60 R = math.R(math.radians(theta)) w, h = self.size w *= f h *= f sx, sy = self.pos ds = [R(p) for p in ((0, h), (w, 0), (w, -0.8), (-w, -0.8), (-w, 0))] return [(sx + dx, sy + dy) for dx, dy in ds]
def polygon(self, f=1): sx, sy = self.anchors[0] sw, sh = self.size sw *= f sh *= 0.5 + 0.5 * f R = math.R(-math.atan2(sx, sy)) ps = (0, 0), (1, 1), (0, 0.7), (-1, 1), (0, 0), (-1, -1), (0, -0.7), (1, -1) ds = [R((dx * sw, dy * sh)) for (dx, dy) in ps] return [(sx + dx, sy + dy) for dx, dy in ds]
def shapecontains(shape, pos): sx, sy = shape["pos"] theta = math.atan2(sx, sy) if sx or sy else 0 dx, dy = math.R(theta, pos) dy -= math.length((sx, sy)) if shape["type"] == "circle": return math.length(dx, dy) <= shape["r"] if shape["type"] == "shard": sw, sh = shape["size"] return abs(dx / sw) + abs(dy / sh) < 1 if shape["type"] == "blade": w = shape["width"] dx = abs(dx / w) dy /= 4 * w return (dy < 0 and dx < 1) or (dy >= 0 and dx + dy < 1)
def anchor(Fspot, anchor, color): p = view.BconvertF(Fspot, anchor) pygame.draw.circle(pview.screen, pygame.Color("black"), T(p), T(10)) pygame.draw.circle(pview.screen, pygame.Color(color), T(p), T(7)) # m = tan(60deg) = sqrt(3) # A = 1/(1+m^2) [1-m^2, 2m, 2m, m^2 - 1] = 1/4 [-2, 2sqrt(3), 2sqrt(3), 2] def R1(pos): x, y = pos m = math.sqrt(3) return (-x + m * y) / 2, (m * x + y) / 2 R2 = math.R(math.radians(-60)) def dim(color, amount=1): return ptext._applyshade(color, 0.2 * amount) def sectorpoly(sectorimgs, ps0, color): s = sectorimgs[0].get_height() pygame.draw.polygon(sectorimgs[0], color, I([(x * s, (1 - y) * s) for x, y in ps0])) if len(sectorimgs) > 1: ps1 = [R1(p) for p in ps0] pygame.draw.polygon(sectorimgs[1], color, I([(x * s, (1 - y) * s) for x, y in ps1])) if len(sectorimgs) > 2: