Esempio n. 1
0
    def draw(self):
        if self.frame_rate == 0:
            p5.background(0, 0, 0)  # set initial background to black

        # action
        if self.paused:
            return

        self.frame_rate += 1

        self.update()

        # MARK: actual drawing
        p5.background(0, 0, 0, 90)

        p5.fill(255)
        p5.stroke(255)

        p5.rect((self.user.x, self.user.y), self.block_width,
                self.block_height)
        p5.rect((self.machine.x, self.machine.y), self.block_width,
                self.block_height)
        p5.ellipse((self.ball.x, self.ball.y), 2 * self.ball_radius,
                   2 * self.ball_radius)

        if self.draw_prediction and self.last_prediction is not None:
            p5.no_fill()
            p5.stroke(220, 0, 0)
            p5.ellipse((self.width - self.block_width - self.ball_radius,
                        self.last_prediction), 2 * self.ball_radius,
                       2 * self.ball_radius)
Esempio n. 2
0
    def follow(self, path):
        # calculate future location
        predicted_location = copy.copy(self.velocity)
        predicted_location.normalize()
        predicted_location *= 10
        predicted_location += self.location
        shortest_distance = width  # initialise to a large number
        # check whether future location is on path

        for i in range(len(path.points) - 1):
            point_a = path.points[i]
            point_b = path.points[i + 1]
            norm = sp.scalar_projection(predicted_location, point_a, point_b)
            if(norm.x < point_a.x or norm.x > point_b.x):
                continue
            distance = Vector.distance(norm, predicted_location)
            if distance < shortest_distance:
                shortest_distance = distance
                direction = point_b - point_a
                direction.normalize()
                direction *= 20
                target = norm + direction


            if shortest_distance > path.radius:
                self.steer(target)
                if self.debug:
                    line(self._tup(self.location), (self._tup(predicted_location)))
                    fill(255, 0, 0)
                    ellipse((norm.x, norm.y), 10, 10)
                    fill(0, 255, 0)
                    ellipse((target.x, target.y), 10, 10)
Esempio n. 3
0
def draw():
    background(250)
    global point_a
    global point_b
    stroke(0)
    mouse = Vector(mouse_x, mouse_y)

    line(point_a, mouse)
    line(point_a, point_b)

    norm = scalar_projection(mouse, point_a, point_b)
    fill(255, 0, 0)
    ellipse((norm.x, norm.y), 10, 10)
Esempio n. 4
0
 def show_points(self):
     noStroke()
     if len(self.centroid_assignments) == 0:
         for p in self.data:
             fill(255)
             stroke(0)
             strokeWeight(1)
             ellipse(p[0], p[1], 5, 5)
     else:
         for i, points in self.centroid_assignments.items():
             fill(self.colors[i], 255, 225)
             for p in points:
                 ellipse(p[0], p[1], 5, 5)
Esempio n. 5
0
def draw_box(qt):
    no_fill()
    stroke(255, 0, 0)
    rect((qt.boundary[0], qt.boundary[1]), qt.boundary[2], qt.boundary[3])

    fill(0, 255, 0)
    stroke(0, 255, 0)
    if len(qt.points) > 0:
        for pt in qt.points:
            ellipse([pt.x, pt.y], 1, 1)

    if qt.children[0] is not None:
        for child in qt.children:
            draw_box(child)
Esempio n. 6
0
    def follow(self, path):
        # calculate future location
        predicted_location = copy.copy(self.velocity)
        predicted_location.normalize()
        predicted_location *= 50
        predicted_location += self.location
        # check whether future location is on path
        norm = sp.scalar_projection(predicted_location, path.point_a,
                                    path.point_b)
        distance = Vector.distance(norm, predicted_location)
        direction = path.point_b - path.point_a
        direction.normalize()
        direction *= 20
        target = norm + direction

        if distance > path.radius:
            self.steer(target)
            if self.debug:
                line(self._tup(self.location), (self._tup(predicted_location)))
                fill(255, 0, 0)
                ellipse((norm.x, norm.y), 10, 10)
                fill(0, 255, 0)
                ellipse((target.x, target.y), 10, 10)
Esempio n. 7
0
def draw():
    global t, circleList
    p.background(200)
    p.translate(width / 4, height / 2)
    p.no_fill()
    p.stroke(0)
    p.ellipse((0, 0), 2 * r1, 2 * r1)
    p.fill(255, 0, 0)
    y = r1 * p.sin(t)
    x = r1 * p.cos(t)
    circleList = [y] + circleList[:249]
    p.ellipse((x, y), r2, r2)
    p.stroke(0, 255, 0)
    p.line((x, y), (200, y))
    p.fill(0, 255, 0)
    p.ellipse((200, y), 10, 10)
    for i, c in enumerate(circleList):
        p.ellipse((200 + i, c), 15, 15)
    t += 0.1
Esempio n. 8
0
def draw():
    global r1, r2, x1, y1, t, prop, points
    p.translate(width / 2, height / 2)
    p.background(255)
    p.no_fill()
    p.stroke(0)
    p.ellipse((x1, y1), 2 * r1, 2 * r1)
    x2 = (r1 - r2) * p.cos(t)
    y2 = (r1 - r2) * p.sin(t)
    p.ellipse((x2, y2), 2 * r2, 2 * r2)
    x3 = x2 + prop * (r2 - r3) * p.cos(-((r1 - r2) / r2) * t)
    y3 = y2 + prop * (r2 - r3) * p.sin(-((r1 - r2) / r2) * t)
    p.fill(255, 0, 0)
    p.ellipse((x3, y3), 2 * r3, 2 * r3)
    points = [[x3, y3]] + points[:2000]
    for i, d in enumerate(points):
        if i < len(points) - 1:
            p.stroke(255, 0, 0)
            p.line((d[0], d[1]), (points[i + 1][0], points[i + 1][1]))
    t += 0.1
Esempio n. 9
0
def draw():
    p.line((1, 0), (40, 50))
    p.ellipse((400, 400), 100, 20)