Example #1
0
        def outro():

            import time
            from turtle import Pen
            global mars_game_completed
            pen1 = Pen()

            pen1.color('black', 'green')

            turtle.clearscreen()

            pen1.up()
            pen1.goto(0, 100)
            pen1.down()
            pen1.write("You win! now go, you inglorious bastard!",
                       False,
                       'center',
                       font=('Arial', 24, 'bold'))
            time.sleep(2)
            turtle.clearscreen()
            # gameDone = True
            turtle.bye()
            pygame.mixer.pause()
            import MainMenuV4
            MainMenuV4.main_menu()
Example #2
0
    def outro():
        global mars_game_completed
        mars_game_completed = True
        import MainMenuV4
        MainMenuV4.main_menu()
        pygame.display.iconify()

        import time
        from turtle import Pen
        pen1 = Pen()

        pen1.color('black', 'green')

        turtle.clearscreen()

        pen1.up()
        pen1.goto(0, 100)
        pen1.down()
        pen1.write("You win!",
                   False,
                   'center',
                   font=('Cooper Black', 18, 'bold'))
        time.sleep(2)
        turtle.clearscreen()
        turtle.done()
Example #3
0
class Particula:
    
    def __init__(self):
        self._desenho = Pen()
        self._desenho.shape('circle')
        self._desenho.color('blue')
        self._velocidade = (0,0)


    def alterar_velocidade(self, valor):
        pass
Example #4
0
from turtle import Pen
from random import randint

laki = Pen()

def square():
    side = 1
    length = randint(20, 100)
    while side <=4:
        laki.forward(length)
        laki.left(90)
        side += 1

while True:
    laki.speed(1000)
    laki.penup()
    laki.goto(randint(-250, 250), randint(-250, 250))
    laki.pendown()
    laki.begin_fill()
    laki.color("#" + str(randint(100000, 999999)))
    square()
    laki.end_fill()
Example #5
0
class Plotter(object):
    """
    A plotter object provides a graphical window for plotting data and 
    mathematical functions.
    """
    def __init__(self, width, height, min_x, max_x, min_y, max_y):
        """ (Plotter, int, int, int, int, int, int) -> turtle
        
        The constructor initializes the Turtle graphics window. 
        It accepts parameters that define the window’s physical size and 
        ranges of x and y axes.

        Initializes the plotter with a window that is <width> wide and 
        <height> high. Its x-axis ranges from <min_x> to <max_x>, and it's 
        y-axis ranges from <min_y> to <max_y>.

        Establishes the global begining and ending x values for the plot and
        the x_increament value.
        Draws the x-axis and y-axes
        """
        # Init
        self.pen = Pen()  # The plotter object's pen
        self.screen = Screen()  # The plotter object's sceen

        self.pen.speed(0)  # Speed up rendering
        self.screen.tracer(0, 0)  # DONT draw pen while drawing

        # Establish global x and y ranges
        self.min_x, self.max_x = min_x, max_x
        self.min_y, self.max_y = min_y, max_y

        self.screen.setup(width=width,
                          height=height)  # Set up window size, in pixels

        # set up screen size, in pixels
        self.screen.screensize(width, height)
        self.screen.setworldcoordinates(min_x, min_y, max_x, max_y)

        # x-axis distance that correspond to one pixel in window distance
        self.x_increament = (max_x - min_x) / width
        self.draw_grid(20)
        self.draw_axes()
        self.screen.title('Plot')
        self.screen.update()

    def __del__(self):
        """ (Plotter) -> stdout

        Called when the client no longer uses the plotter object. 

        The interpreter calls this method, also known as destructor, 
        when the object is no longer bound to a reference with in the 
        executing program. 
        Among other times, this happens when the program’s execution 
        terminates.
        """
        print('Done Printing')

    def draw_axes(self, grid=False):
        """ (Plotter, bool) -> turtle

        Draws the x and y axes within the plotting window.

        An option Boolean parameter <grid> controls the drawing of
        accessory horizontal and vertical lines
        """
        if grid:
            self.draw_grid(20)
        self.pen.hideturtle()  # Make pen invisible
        prev_width = self.pen.width()
        self.pen.width(2)

        # Draw x axis
        self.pen.color('black')
        self.draw_arrow(self.min_x, 0, self.max_x, 0)

        # Draw y axis
        self.draw_arrow(0, self.min_y, 0, self.max_y)
        self.pen.width(prev_width)

    def draw_grid(self, num):
        """ (Plotter, int) -> turtle

        Draws horizontal and vertical accessory reference coordinate 
        lines on the plot. Parameter <num> control the frequency of the 
        reference lines.
        """
        self.pen.up()
        # self.pen.setposition(self.min_x, self.min_y)
        inc = (self.max_x - self.min_y) / num
        self.pen.color('lightblue')
        x = self.min_x

        while x <= self.max_x:
            self.pen.setposition(x, self.min_y)
            self.pen.down()
            self.pen.setposition(x, self.min_y)
            self.pen.up()
            x += inc  # Next x
        inc = (self.max_y - self.min_y) / num
        y = self.min_y

        while y <= self.max_y:
            self.pen.setposition(self.min_x, y)
            self.pen.down()
            self.pen.setposition(self.max_x, y)
            self.pen.up()
            y += inc  # Next y

    def draw_arrow(self, x1, y1, x2, y2):
        """ (Plotter, int, int, int, int) -> turtle

        Draws a line segment with an attached arrow head. 
        Expects four numeric parameters representing the (x 1 , y 1 ) tail end 
        point and (x 2 , y 2 ) head end point of the arrow.
        """
        # Draw arrow shaft
        self.pen.up()
        self.pen.setposition(x1, y1)  # Move the pen starting point
        self.pen.down()  # Draw line bottom to top
        self.pen.setposition(x2, y2)  # Move the pen starting point

        # Draw arrow head
        dy = y2 - y1
        dx = x2 - x1

        angle = atan2(dy, dx) * 180 / pi
        self.pen.setheading(angle)
        self.pen.stamp()

    def plot_function(self, f, color, update=True):
        """ (Plotter, func, str, bool) -> turtle
        Plots the curve of a given function <f> with a specified color,
        established by initialize_plotter.
        Plots (x, f(x)), for all x in range min_x <= x < max_x
        The color parameter dicatates the curve's color

        An optional Boolean parameter determines if the function renders 
        immediately or requires the client to call the update method after a 
        series of plots (defaults to True).    
        """
        # Move pen to starting position
        self.pen.up()
        self.pen.setposition(self.min_x, f(self.min_x))
        self.pen.color(color)
        self.pen.down()

        # Iterate over the range of x values for min_x <= x < max_x
        x = self.min_x
        while x < self.max_x:
            self.pen.setposition(x, f(x))
            x += self.x_increament  # Next x

        if update:
            self.screen.update()

    def plot_data(self, data, color, update=True):
        """ (Plotter, list, str, bool) -> turtle
        
        Plots the curve (x, y) pairs of values in data_list.
        A parameter <color> specifies the curve’s color. 
        An optional Boolean parameter determines if the function renders 
        immediately or requires the client to call the update method after a 
        series of plots (defaults to True).
        """
        self.pen.up()
        self.pen.setposition(data[0][0], data[0][1])
        self.pen.color(color)
        self.pen.down()

        # Plot the points in th data set
        for x, y in data:
            self.pen.setposition(x, y)
        if update:
            self.screen.update()

    def update(self):
        """ (Plotter) -> turtle
        
        Draws any pending actions to the screen 
        """
        self.screen.update()

    def setcolor(self, color):
        """ (Plotter, str) -> turtle
        
        Sets the current drawing color. 
        """
        self.pen.color(color)

    def onclick(self, fun):
        """ (Plotter, func) -> turtle

        Assigns a callback function that the frame should call when the 
        user clicks the mouse button when the pointer is over the plotter 
        window.
        
        The function <fun> must accept two integer parameters that represent
        the (x, y) location of the mouse when the click occurred
        """
        self.screen.onclick(fun)

    def interact(self):
        """ (Plotter) -> turtle

        Sets the plotter to interactive mode, enabling the user to 
        provide mouse and keyboard input.
        """
        self.screen.mainloop()
class Personagem:
    def __init__(self, nome = str, exibir=True):
        self._img = Pen()
        self._img.up()        
        self._img.shape(nome+'.gif')
        print(nome+'.gif')
        self._img.speed('fastest')
        self._caneta = Pen()
        self._caneta.hideturtle()
        self._caneta.pensize(2)
        self._caneta.color('white')
        if not exibir:
            self._img.hideturtle()
        


    def esconder(self):
        self._img.hideturtle()

    def exibir(self):
        self._img.showturtle()
                
    def falar(self, mensagem = str):
        #mensagem = formata(mensagem)
        x,y = self._img.position()
        self._caneta.up()
        self._caneta.goto(x,y)
        self._caneta.down()
        self._caneta.goto(x+100,y+100)
        self._caneta.write(mensagem)
        time.sleep(4)
        self._caneta.clear()


    def andar_direita(self, distancia = int):
        self._img.forward(distancia)

    def andar_esquerda(self, distancia = int):
        self._img.left(180)
        self._img.forward(distancia)
        
    def vapara (self, x = int, y = int):
        self._img.goto(x, y)


    def pular_cima (self):
        x,y = self._img.position()
        self._img.goto(x, y+100)
        time.sleep(0.5)
        self._img.goto(x+50, y-100)


    def pular_tras (self):
        x,y = self._img.position()
        self._img.goto(x-100, y+100)
        time.sleep(0.5)
        self._img.goto(x-100, y-100)


    def pular_frente (self):
        x,y = self._img.position()
        self._img.goto(x+100, y+100)
        time.sleep(0.5)
        self._img.goto(x+100, y-100)

    def posicao(self):
        return self._img.position()
            
        
    def lancar(self, vx = int, vy = int):
        x,y = self.posicao()
        for i in range(20):          
            self.vapara(x+i*vx, y+i*vy)
            vy -= 1
Example #7
0
class Plotter:
    """ A plotter object provides a graphical window for 
        plotting data and mathematical functions. """

    def __init__(self, width, height, min_x, max_x, min_y, max_y):
        """ Initializes the plotter with a window that is 
            width wide and height high.  Its x-axis ranges from
            min_x to max_x, and its y-axis ranges from
            min_y to max_y.  Establishes the global beginning and ending
            x values for the plot and the x_increment value.
            Draws the x- and y-axes. """

        self.pen = Pen()   #  The plotter object's pen
        self.screen = Screen()   #  The plotter object's screen

        self.pen.speed(0)            # Speed up rendering
        self.screen.tracer(0, 0)        # Do not draw pen while drawing
        # Establish global x and y ranges
        self.min_x, self.max_x = min_x, max_x
        self.min_y, self.max_y = min_y, max_y
        # Set up window size, in pixels
        self.screen.setup(width=width, height=height)
        # Set up screen size, in pixels
        self.screen.screensize(width, height)
        self.screen.setworldcoordinates(min_x, min_y, max_x, max_y)

        # x-axis distance that corresponds to one pixel in window distance
        self.x_increment = (max_x - min_x)/width
        self.draw_grid(20)
        self.draw_axes()
        self.screen.title("Plot")
        self.screen.update()

    def __del__(self):
        """ Called when the client no longer uses the plotter 
            object. """
        print("Done plotting")

    def draw_axes(self, grid=False):
        """ Draws the x and y axes within the plotting window. 
            The grid parameter controls the drawing of accessory
            horizontal and vertical lines. """
        if grid:
            self.draw_grid(20)
        self.pen.hideturtle()            # Make pen invisible
        prev_width = self.pen.width()
        self.pen.width(2)
        #  Draw x axis
        self.pen.color('black')
        self.draw_arrow(self.min_x, 0, self.max_x, 0) 
        #  Draw y axis
        self.draw_arrow(0, self.min_y, 0, self.max_y) 
        self.pen.width(prev_width)

    def draw_grid(self, n):
        """ Draws horizontal and vertical accessory reference 
            coordinate lines on the plot.  Parameter n controls 
            the frequency of the reference lines. """
        self.pen.up()
        #self.pen.setposition(self.min_x, self.min_y)
        inc = (self.max_x - self.min_x)/n
        self.pen.color("lightblue")
        x = self.min_x
        while x <= self.max_x:
            self.pen.setposition(x, self.min_y)
            self.pen.down()
            self.pen.setposition(x, self.max_y)
            self.pen.up()
            x += inc  # Next x
        inc = (self.max_y - self.min_y)/n
        y = self.min_y
        while y <= self.max_y:
            self.pen.setposition(self.min_x, y)
            self.pen.down()
            self.pen.setposition(self.max_x, y)
            self.pen.up()
            y += inc  # Next y

    def draw_arrow(self, x1, y1, x2, y2):
        """ Draws an arrow starting at (x1, y1) and ending at
            (x2, y2). """
        # Draw arrow shaft
        self.pen.up()
        self.pen.setposition(x1, y1) # Move the pen starting point
        self.pen.down()           # Draw line bottom to top
        self.pen.setposition(x2, y2) # Move the pen starting point
        # Draw arrow head
        dy = y2 - y1
        dx = x2 - x1
        angle = atan2(dy, dx) *180/pi
        self.pen.setheading(angle)
        self.pen.stamp()

    def plot_function(self, f, color, update=True):
        """ Plots function f on the Cartesian coordinate plane
            established by initialize_plotter. Plots (x, f(x)), 
            for all x in the range min_x <= x < max_x. 
            The color parameter dictates the curve's color. """
    
        #  Move pen to starting position
        self.pen.up()
        self.pen.setposition(self.min_x, f(self.min_x))
        self.pen.color(color)
        self.pen.down()
        # Iterate over the range of x values for min_x <= x < max_x
        x = self.min_x
        while x < self.max_x:
            self.pen.setposition(x, f(x))
            x += self.x_increment   # Next x

        if update:
            self.screen.update()

    def plot_data(self, data, color, update=True):
        """ Plots the (x, y) pairs of values in the data list.
            The curve's color is specified by the color parameter. """
        #  Move pen to starting position
        self.pen.up()
        self.pen.setposition(data[0][0], data[0][1])
        self.pen.color(color)
        self.pen.down()
        # Plot the points in the data set
        for x, y in data:
            self.pen.setposition(x, y)
        if update:
            self.screen.update()

    def update(self):
        """ Draws any pending plotting actions to the screen. """
        self.screen.update()

    def setcolor(self, color):
        """ Sets the current drawing color. """
        self.pen.color(color)

    def onclick(self, fun):
        """ This method assigns a function to call when the user
            clicks the mouse over the plotting window.  The
            function must accept two integer parameters that
            represent the (x, y) location of the mouse when the
            click occurred. """
        self.screen.onclick(fun)
    
    def interact(self):
        """ Places the plotting object in interactive mode so the
            user can provide input via the mouse or keyboard. """
        self.screen.mainloop()