Esempio n. 1
0
def end_fill():
    """
    Fill the shape enclosed by the turtle's drawing path after the last call to begin_fill.
    """
    _check_turtle()
    if eg.is_run():
        _turtle.end_fill()
Esempio n. 2
0
def begin_fill():
    """
    Begin to record the turtle's shape drawing path for filling.
    """
    if eg.is_run():
        _check_turtle()
        _turtle.begin_fill()
Esempio n. 3
0
 def _refresh_loop(self):
     while eg.is_run():
         if not self._win.isVisible():
             self.set_immediate(True)
         if self._win.delay_fps(60):
             if not self._running:
                 break
             self._render()
Esempio n. 4
0
def create_world(width: int = 800, height: int = 600) -> None:
    """
    Create an world for turtle drawing.

    :param width: width of the graphics window
    :param height: height of the graphics window
    """
    global _turtle, _world
    if _world is not None:
        raise ValueError("The world has been created! ")
    if not eg.is_run():
        eg.init_graph(width, height)
    _world = TurtleWorld()
    _turtle = Turtle(_world)
Esempio n. 5
0
def mainloop():
    # visualization
    x = 500
    y = 400
    global minDistance
    minDistance = distanceToDest()
    vectorCollectionBad = []
    vectorCollectionGood = []
    coordsGoal = []
    iterMax = maxiter
    easygraphics.set_render_mode(easygraphics.RenderMode.RENDER_MANUAL)
    while easygraphics.is_run():
        # code from the simmulation function
        while iterMax != 0:
            rotatePlanets()
            if iterMax <= maxiter - startParameters[2]:
                currDistance = distanceToDest()
                if currDistance < minDistance:
                    minDistance = currDistance
                # calculating the gravitational pull
                pull = gravPull(satellite[0], satellite[1])
                # calculating the new position of the satellite
                newSatPosition = positionChange(pull, startParameters[0],
                                                startParameters[1])
                satellite[0] = newSatPosition[0]
                satellite[1] = newSatPosition[1]
                # print(newSatPosition)
                # calculating the new velocity vector of the satellite
                newSatVelocity = velocityChange(pull, startParameters[0],
                                                startParameters[1])
                # print(newSatVelocity)
                newSatVelocity = cartToPolar(newSatVelocity[0],
                                             newSatVelocity[1])
                startParameters[0] = newSatVelocity[0]
                startParameters[1] = newSatVelocity[1]
            else:
                satellite[0] = planets[startPlanetID][0]
                satellite[1] = planets[startPlanetID][1]
            if easygraphics.delay_jfps(40):
                # settin the fps limit
                easygraphics.clear_device()
                for pl in planets:
                    # transforming and drawing planets
                    if pl == planets[destPlanetID]:
                        coordsGoal = polarToCart(pl[0], pl[1])
                        easygraphics.set_fill_color(
                            easygraphics.Color.LIGHT_GREEN)
                        easygraphics.draw_circle(coordsGoal[0] + 500,
                                                 coordsGoal[1] + 400,
                                                 allowedDistance)
                    easygraphics.circle(x, y, pl[0])
                    coordsPlanet = polarToCart(pl[0], pl[1])
                    easygraphics.set_fill_color(easygraphics.Color.BLUE)
                    easygraphics.draw_circle(coordsPlanet[0] + 500,
                                             coordsPlanet[1] + 400, 5)
                # transforming and drawing satellite
                coordsSatellite = polarToCart(satellite[0], satellite[1])
                goal = polarToCart(planets[destPlanetID][0],
                                   planets[destPlanetID][1])
                if math.sqrt(
                    (coordsSatellite[0] - goal[0])**2 +
                    (coordsSatellite[1] - goal[1])**2) < allowedDistance:
                    vectorCollectionGood.append(coordsSatellite)
                else:
                    vectorCollectionBad.append(coordsSatellite)
                easygraphics.set_fill_color(easygraphics.Color.RED)
                easygraphics.draw_circle(coordsSatellite[0] + 500,
                                         coordsSatellite[1] + 400, 3)
                for vec in vectorCollectionGood:
                    easygraphics.set_fill_color(easygraphics.Color.CYAN)
                    easygraphics.draw_circle(vec[0] + 500, vec[1] + 400, 2)
                for vec in vectorCollectionBad:
                    easygraphics.set_fill_color(easygraphics.Color.RED)
                    easygraphics.draw_circle(vec[0] + 500, vec[1] + 400, 2)
                easygraphics.draw_line(coordsSatellite[0] + 500,
                                       coordsSatellite[1] + 400,
                                       coordsGoal[0] + 500,
                                       coordsGoal[1] + 400)
            iterMax -= 1
    easygraphics.close_graph()
Esempio n. 6
0
def _check_turtle():
    if _turtle is None:
        create_world()
    elif _in_shell:
        if not eg.is_run():
            raise RuntimeError("Must run close_world() to clean up the world!")