Example #1
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)
Example #2
0
                code1 = computeCode(x1, y1)

            else:
                x2 = x
                y2 = y
                code2 = computeCode(x2, y2)
    if accept:
        Bresenhams(x1, y1, x2, y2)
        print("(x1: %d , y1 : %d),(x2: %d , y2 : %d)" % (x1, y1, x2, y2))

    else:
        print("Line rejected")


if __name__ == "__main__":

    window = Rectangle(Point(x_max, y_max), Point(x_min, y_min))
    window.draw(win)
    #Bresenhams(100,300,400,700)
    #Bresenhams(425,425,500,500)
    Bresenhams(50, 375, 700, 600)
    win.getMouse()
    win.delete("all")
    window = Rectangle(Point(x_max, y_max), Point(x_min, y_min))
    window.draw(win)
    #cohenSutherlandClip(100,300,400,700)
    #cohenSutherlandClip(425,425,500,500)
    cohenSutherlandClip(50, 375, 700, 600)
    win.getMouse()
    win.close()