def window():
    win = GraphWin("얘기 카운트", 1280, 720)
    win.setBackground(color_rgb(17, 22, 15))

    historyText = Text(Point(480, 360), '')
    historyText.setFill(color_rgb(255, 255, 255))
    historyText.setFace("arial")
    historyText.setSize(16)
    historyText.draw(win)

    rect = Rectangle(Point(960, 0), Point(1280, 720))
    rect.setFill(color_rgb(17, 22, 15))
    rect.draw(win)

    clockText = Text(Point(1117, 16), "")
    clockText.setFill(color_rgb(255, 255, 255))
    clockText.setFace("courier")
    clockText.setSize(16)
    clockText.draw(win)

    yaegiConstText = Text(Point(1117, 300), "%s 횟수" % toFilter)
    yaegiConstText.setFill(color_rgb(255, 255, 255))
    yaegiConstText.setFace("arial")
    yaegiConstText.setSize(36)
    yaegiConstText.draw(win)

    yaegiNumberText = Text(Point(1117, 420), "0")
    yaegiNumberText.setFill(color_rgb(255, 255, 255))
    yaegiNumberText.setFace("arial")
    yaegiNumberText.setSize(36)
    yaegiNumberText.draw(win)

    line = graphics.Line(Point(960, 0), Point(960, 720))
    line.setFill(color_rgb(200, 200, 200))
    line.draw(win)

    while not win.checkMouse():
        clockText.setText(
            "%s KST" %
            datetime.datetime(2020, 1, 1).now().isoformat().split('.')[0])
        yaegiNumberText.setText(str(yaegiCount))
        historyText.setText('\n'.join(history))

        sleep(1)

    win.close()

    running = False

    global f
    f.write('%s count: %d' % (toFilter, yaegiCount))
Beispiel #2
0
    def start_simulation(self, simulation_speed=1, framerate=30):
        # Header initializes window
        simulation_speed = 1 / simulation_speed

        win_name = self.name + " - N-Body Problem"
        win = GraphWin(win_name, self.size, self.size, autoflush=False)
        win.setBackground("black")
        win.setCoords(-self.size / (2 * self.scale),
                      -self.size / (2 * self.scale),
                      self.size / (2 * self.scale),
                      self.size / (2 * self.scale))

        # Body
        start_time = time.time()
        current_time = time.time()
        draw_time = time.time()

        while win.checkMouse() is None:
            # FIXME this should be drawspeed
            if simulation_speed < time.time() - current_time:

                current_time = time.time()
                # draw update to window
                win.delete("all")
                # TODO ezen belul legyen
                self.update(simulation_speed)
                self.print(win)
            # If max time is exceeded break out of loop
            else:
                continue

            # Max time reached stop simulation
            if self.max_time < time.time() - start_time:
                break

            # If time passed is greater than refresh rate, refresh
            # TODO lehet ezt az updaten belul kulon is kene kezelni
            update(framerate)

        # Trailer closes window
        win.close()
        if not self.collisions:
            print("Simulation successful; System Stable")
        else:
            print("Simulation over; System Unstable\nCollisions: ",
                  self.collisions)
Beispiel #3
0
class View:
    """
    Will handle all functions necessary to provide a graphical representation of a World.
    """

    def __init__(self, world: World, title: str):
        """
        Creates a new View with a given World to represent.
        """
        self.world = world
        self.window = GraphWin(title, world.width, world.height, autoflush=False)
        self.rectangles = []
        self.vehicle = None
        self.camera = None

    def update(self, delta_t: float):
        """
        Redraws this View (call upon update in coordinates).
        """
        if self.vehicle:
            self.vehicle.move(self.world.vehicle.velocity[0] * delta_t, self.world.vehicle.velocity[1] * delta_t)
        
        if self.world.camera:
            #self.camera = Rectangle(self.world.camera.get_upper_left_corner(), self.world.camera.get_lower_right_corner())
            if self.camera:
                self.camera.undraw()
            upper_left_corner = self.world.camera.get_upper_left_corner()
            lower_right_corner = self.world.camera.get_lower_right_corner()
            self.camera = Rectangle(Point(upper_left_corner[0], upper_left_corner[1]), Point(lower_right_corner[0], lower_right_corner[1]))
            self.camera.setFill("green")
            self.camera.setOutline("green")
            self.camera.draw(self.window)
        else:
            if self.camera:
                self.camera.undraw()
            self.camera = None
        
        self.window.update()

    def add_feature(self, upper_left_corner: tuple, lower_right_corner: tuple, color: str):
        """
        Adds a feature to be drawn in this view.
        """
        self.rectangles.append(Rectangle(Point(upper_left_corner[0], upper_left_corner[1]), Point(lower_right_corner[0], lower_right_corner[1])))
        self.rectangles[len(self.rectangles) - 1].setFill(color)
        self.rectangles[len(self.rectangles) - 1].setOutline(color)
        self.rectangles[len(self.rectangles) - 1].draw(self.window)

    def set_vehicle(self, upper_left_corner: tuple, lower_right_corner: tuple, color: str):
        """
        Sets the location of the Vehicle.
        """
        self.vehicle = Rectangle(Point(upper_left_corner[0], upper_left_corner[1]), Point(lower_right_corner[0], lower_right_corner[1]))
        self.vehicle.setFill(color)
        self.vehicle.draw(self.window)

    def check_mouse(self):
        """
        Checks if a mouse button has been clicked during the previous frame.
        Returns the specific button if a button was clicked, or None if not button was pressed.
        """
        return self.window.checkMouse()

    def close_window(self):
        """
        Closes the window associated with this View.
        """
        self.window.close()

    def capture_png(self, name: str):
        """
        Records a postscript (similar to PDF) of the current graphical representation to the given file name.
        Converts this postscript to a png.
        """
        file_name = name + ".eps"
        self.window.postscript(file=file_name, colormode='color')
        img = Image.open(file_name)
        img.save(name + ".png", "png")
Beispiel #4
0
scoreText.draw(win)

pikColor = draw_pikman(pikLocation, pikColor)
draw_notice("Click anywhere to quit", "yellow")
draw_pik_score(pikScore, "0")
debug_print()

# ---------------------------------------------------------
# Start game loop
# ---------------------------------------------------------
while alive:
    #    if checkCapture():
    #        alive = False
    #    else:
    #        calcScore()
    coordinate = win.checkMouse()
    if coordinate is not None:
        alive = False

    move = win.checkKey()
    if move != "":
        move_pikman(move)

    if (gameDuration - gameTimer) < 0:
        alive = False
    else:
        # gameTimer = gameTimer - 1
        gameTimer = time.time() - gameStart
        draw_pik_score(pikScore, f"{gameTimer:.1f}")
        # print("time: " + str(f'{gameTimer:.1f}'))
    animate_board()
Beispiel #5
0
        dist = sqrt(yd**2 + xd**2)
        if not i == cir:
            if dist <= 2 * cir.m:
                y1 = u1 - np.dot(u1 - u2, x1 - x2) / np.linalg.norm(
                    x1 - x2, ord=2)**2 * (x1 - x2)
                y2 = u2 - np.dot(u2 - u1, x2 - x1) / np.linalg.norm(
                    x2 - x1, ord=2)**2 * (x2 - x1)
                cir.vy = y1[0]
                cir.vx = y1[1]
                i.vy = y2[0]
                i.vx = y2[1]


while True:
    vx = randint(-3, 3)
    vy = randint(-3, 3)

    for i in cirObjs:
        move(i)

    p = win.checkMouse()
    if p:

        c1 = Circles(p.getX(), p.getY(), vx, vy)
        color = colors[randint(0, len(colors) - 1)]
        c1.setFill(color)
        c1.draw(win)
        cirObjs.append(c1)

    sleep(0.01)