コード例 #1
0
def draw_polyline_nice_corners(cr,
                               points,
                               arrow_degrees,
                               arrow_len,
                               arrow_start=False,
                               arrow_end=False):
    ex, ey = points[-1]
    prev = points[0]

    if arrow_start:
        cr.move_to(prev[0], prev[1])
        draw_arrow(cr, utils.make_vector(points[1], points[0]), arrow_degrees,
                   arrow_len)

    cr.move_to(prev[0], prev[1])
    for i in xrange(1, len(points) - 1):
        a = utils.make_vector(points[i - 1], points[i])
        b = utils.make_vector(points[i], points[i + 1])
        la = utils.vector_len(a)
        lb = utils.vector_len(b)
        if la < 0.01 or lb < 0.01:
            continue
        v = utils.vector_mul_scalar(utils.normalize_vector(a), min(la, 20.0))
        w = utils.vector_mul_scalar(utils.normalize_vector(b), min(lb, 20.0))
        t = utils.vector_diff(points[i], v)
        cr.line_to(t[0], t[1])
        cr.rel_curve_to(v[0], v[1], v[0], v[1], v[0] + w[0], v[1] + w[1])
    cr.line_to(ex, ey)
    cr.stroke()

    if arrow_end:
        cr.move_to(ex, ey)
        draw_arrow(cr, utils.make_vector(points[-2], points[-1]),
                   arrow_degrees, arrow_len)
コード例 #2
0
ファイル: drawing.py プロジェクト: Palasekm/Kaira
def draw_polyline_nice_corners(cr, points, arrow_degrees, arrow_len, arrow_start = False, arrow_end = False):
    ex, ey = points[-1]
    prev = points[0]

    if arrow_start:
        cr.move_to(prev[0],prev[1])
        draw_arrow(cr, utils.make_vector(points[1], points[0]), arrow_degrees, arrow_len)

    cr.move_to(prev[0],prev[1])
    for i in xrange(1, len(points) - 1):
        a = utils.make_vector(points[i-1], points[i])
        b = utils.make_vector(points[i], points[i + 1])
        la = utils.vector_len(a)
        lb = utils.vector_len(b)
        if la < 0.01 or lb < 0.01:
            continue
        v = utils.vector_mul_scalar(utils.normalize_vector(a), min(la, 20.0))
        w = utils.vector_mul_scalar(utils.normalize_vector(b), min(lb, 20.0))
        t = utils.vector_diff(points[i], v)
        cr.line_to(t[0], t[1])
        cr.rel_curve_to(v[0], v[1], v[0], v[1], v[0] + w[0], v[1] + w[1])
    cr.line_to(ex,ey)
    cr.stroke()

    if arrow_end:
        cr.move_to(ex, ey)
        draw_arrow(cr, utils.make_vector(points[-2], points[-1]), arrow_degrees, arrow_len)
コード例 #3
0
ファイル: main.py プロジェクト: nutnicha-t/tk-space
    def generate(self, space_game, ship):
        # def create_enemy_star(self):
        self.enemies = []

        self.x = randint(100, CANVAS_WIDTH - 100)
        self.y = randint(100, CANVAS_HEIGHT - 100)

        while vector_len(self.x - self.ship.x, self.y - self.ship.y) < 200:
            self.x = randint(100, CANVAS_WIDTH - 100)
            self.y = randint(100, CANVAS_HEIGHT - 100)

        for d in range(18):
            self.dx, self.dy = direction_to_dxdy(d * 20)
            self.enemy = Enemy(self, self.x, self.y,
                               self.dx * ENEMY_BASE_SPEED,
                               self.dy * ENEMY_BASE_SPEED)
            self.enemies.append(self.enemy)

        return self.enemies

        # def create_enemy_from_edges(self):
        self.x, self.y = random_edge_position()
        self.vx, self.vy = normalize_vector(self.ship.x - self.x,
                                            self.ship.y - self.y)

        self.vx *= ENEMY_BASE_SPEED
        self.vy *= ENEMY_BASE_SPEED

        self.enemy = Enemy(self, self.x, self.y, self.vx, self.vy)
        return [self.enemy]
コード例 #4
0
ファイル: main.py プロジェクト: bhokin/Space-fighter
    def generate(self, space_game, ship):
        enemies = []
        x = randint(100, CANVAS_WIDTH - 100)
        y = randint(100, CANVAS_HEIGHT - 100)

        while vector_len(x - ship.x, y - ship.y) < 200:
            x = randint(100, CANVAS_WIDTH - 100)
            y = randint(100, CANVAS_HEIGHT - 100)

        for d in range(18):
            dx, dy = direction_to_dxdy(d * 20)
            enemy = Enemy(space_game, x, y, dx * ENEMY_BASE_SPEED, dy * ENEMY_BASE_SPEED)
            enemies.append(enemy)
        return enemies
コード例 #5
0
ファイル: main.py プロジェクト: bhokin/Space-fighter
    def create_enemy_star(self):
        enemies = []

        x = randint(100, CANVAS_WIDTH - 100)
        y = randint(100, CANVAS_HEIGHT - 100)

        while vector_len(x - self.ship.x, y - self.ship.y) < 200:
            x = randint(100, CANVAS_WIDTH - 100)
            y = randint(100, CANVAS_HEIGHT - 100)

        for d in range(18):
            dx, dy = direction_to_dxdy(d * 20)
            enemy = Enemy(self, x, y, dx * ENEMY_BASE_SPEED, dy * ENEMY_BASE_SPEED)
            enemies.append(enemy)

        return enemies
コード例 #6
0
ファイル: main.py プロジェクト: nutnicha-t/tk-space
    def generate(self, space_game, ship):
        self.enemies = []

        self.x = randint(100, CANVAS_WIDTH - 100)
        self.y = randint(100, CANVAS_HEIGHT - 100)

        while vector_len(self.x - self.ship.x, self.y - self.ship.y) < 200:
            self.x = randint(100, CANVAS_WIDTH - 100)
            self.y = randint(100, CANVAS_HEIGHT - 100)

        for d in range(18):
            self.dx, self.dy = direction_to_dxdy(d * 20)
            self.enemy = Enemy(self, self.x, self.y,
                               self.dx * ENEMY_BASE_SPEED,
                               self.dy * ENEMY_BASE_SPEED)
            self.enemies.append(self.enemy)

        return self.enemies
コード例 #7
0
ファイル: main.py プロジェクト: patkamon/space_fighter
    def generate(self, space_game, ship):
        ## ##
        # TODO: extracted from method create_enemy_star
        self.ship = ship
        enemies = []

        x = randint(100, CANVAS_WIDTH - 100)
        y = randint(100, CANVAS_HEIGHT - 100)

        while vector_len(x - self.ship.x, y - self.ship.y) < 200:
            x = randint(100, CANVAS_WIDTH - 100)
            y = randint(100, CANVAS_HEIGHT - 100)

        for d in range(18):
            dx, dy = direction_to_dxdy(d * 20)
            enemy = Enemy(self.ship, x, y, dx * ENEMY_BASE_SPEED, dy * ENEMY_BASE_SPEED)
            enemies.append(enemy)

        return enemies