Exemplo n.º 1
0
def main():
    win = GraphWin("House", 600, 600)
    win.setCoords(0,0,600,600)
    Text(Point(300,10),"5 Click House").draw(win)
    # Draw the main house
    p1 = win.getMouse()
    p2 = win.getMouse()
    Rectangle(p1, p2).draw(win)

    # Draw the door
    con = (abs(p1.x) - (p2.x)) / 5
    p3 = win.getMouse()
    d1 = Point(p3.x + con / 2, p3.y)
    d2 = Point(p3.x - con / 2, p1.y)
    Rectangle(d1, d2).draw(win)

    # Draw the window
    p4 = win.getMouse()
    w1 = Point(p4.x - con / 4, p4.y + con / 4)
    w2 = Point(p4.x + con / 4, p4.y - con / 4)
    Rectangle(w1, w2).draw(win)

    p5 = win.getMouse()
    Polygon(p2, Point(p1.x, p2.y), p5).draw(win)

    Text(Point(300,590),"I hoped you liked my house!!").draw(win)
    time.sleep(10) # sleep the thread for 10 seconds
Exemplo n.º 2
0
 def __init__(self, label, color, coordinates, callback):
     x = coordinates['x']
     y = coordinates['y']
     self.area = Rectangle(Point(x[0], y[0]), Point(x[1], y[1]))
     self.text = Text(Point((x[0] + x[1]) / 2, (y[0] + y[1]) / 2), label)
     self.fill(color)
     self.callback = callback
Exemplo n.º 3
0
def draw_hold_button():
    # hold button points
    hold_a = Point(WIN.getWidth() * 2 / 11 - 100, WIN.getHeight() * 3 / 12)
    hold_b = Point(hold_a.getX() + 200, hold_a.getY() + 100)

    hold_button = Rectangle(hold_a, hold_b)

    hold_button.setFill("green")
    hold_button.setOutline("black")
    hold_button.setWidth(5)

    # Obtains the center point of the hold button
    center_hold_button = Point(0.5 * (hold_a.getX() + hold_b.getX()),
                               0.5 * (hold_a.getY() + hold_b.getY()))

    # Text class
    hold_text = Text(center_hold_button, "Hold")

    # Style the text
    hold_text.setFace("helvetica")
    hold_text.setSize(26)
    hold_text.setStyle("bold")
    hold_text.setTextColor("black")

    hold_button.draw(WIN)
    hold_text.draw(WIN)

    return hold_a, hold_b
Exemplo n.º 4
0
class Car():
    WHEEL_TO_TIRE_RATIO = 0.6

    def __init__(self, back_wheel_center, back_tire_radius, front_wheel_center,
                 front_tire_radius, body_height):
        upper_left_point = Point(back_wheel_center.x,
                                 back_wheel_center.y - body_height)
        bottom_right_point = front_wheel_center
        self.body = Rectangle(upper_left_point, bottom_right_point)

        self.back_wheel = Wheel(back_wheel_center,
                                back_tire_radius * Car.WHEEL_TO_TIRE_RATIO,
                                back_tire_radius)
        self.front_wheel = Wheel(front_wheel_center,
                                 front_tire_radius * Car.WHEEL_TO_TIRE_RATIO,
                                 front_tire_radius)

    def set_color(self, tire_color, wheel_color, body_color):
        self.body.setFill(body_color)

        self.back_wheel.set_color(wheel_color, tire_color)
        self.front_wheel.set_color(wheel_color, tire_color)

    def draw(self, win):
        self.body.draw(win)
        self.back_wheel.draw(win)
        self.front_wheel.draw(win)

    def animate(self, win, dx, dy, n):
        pass
Exemplo n.º 5
0
 def getGFX(self):
     gfx = Rectangle(
         Point(self._size * self._pos[0], self._size * self._pos[1]),
         Point(self._size * self._pos[0] + self._size,
               self._size * self._pos[1] + self._size))
     gfx.setFill(self._color)
     self._gfx = gfx
Exemplo n.º 6
0
class Button:
    def __init__(self, win, center, width, height, label):
        w, h = width / 2.0, height / 2.0
        x, y = center.getX(), center.getY()
        self.xmax, self.xmin = x + w, x - w
        self.ymax, self.ymin = y + h, y - h
        p1 = Point(self.xmin, self.ymin)
        p2 = Point(self.xmax, self.ymax)
        self.rect = Rectangle(p1, p2)
        self.rect.setFill("lightgray")
        self.rect.draw(win)
        self.label = Text(center, label)
        self.label.draw(win)
        self.deactivate()

    def clicked(self, p):
        return (self.active and self.xmin <= p.getX() <= self.xmax
                and self.ymin <= p.getY() <= self.ymax)

    def getLabel(self):
        return self.label.getText()

    def activate(self):
        self.label.setFill("black")
        self.rect.setWidth(2)
        self.active = True

    def deactivate(self):
        self.label.setFill("darkgray")
        self.rect.setWidth(1)
        self.active = False

    def undraw(self):
        self.rect.undraw()
        self.label.undraw()
Exemplo n.º 7
0
 def __init__(self, racket, graphWin):
     Rectangle.__init__(self, Point(385, 285), Point(415, 315))
     if graphWin.render:
         self.setFill(racket.color)
         self.draw(graphWin)
     self.speedX = 0
     self.speedY = 5
Exemplo n.º 8
0
 def __init__(self, x, y, w, h, text, toggle):
     self.rect = Rectangle(Point(x, y), Point(x + w, y + h))
     self.text = Text(self.rect.getCenter(), text)
     self.toggle = toggle
     self.pressed = False
     self.func = None
     self.locked = False
Exemplo n.º 9
0
class Tile:
    def __init__(self, xPos, yPos, type):
        self.xPos = xPos
        self.yPos = yPos
        self.type = type
        self.img = Rectangle(Point((20 * xPos), (20 * yPos)),
                             Point((20 * xPos + 20), (20 * yPos + 20)))
        self.img.setFill(colors[self.type])
        self.img.draw(win)

    def cycleType(self):
        if (self.type >= 6):
            self.type -= 7
        self.type += 1
        self.img.setFill(colors[self.type])

    def replaceRegWithDiff(self):
        if (self.type == 1):
            self.type = 2
            self.img.setFill(colors[self.type])

    def replaceRegWithWater(self):
        if (self.type == 1):
            self.type = 5
            self.img.setFill(colors[self.type])
Exemplo n.º 10
0
 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)
Exemplo n.º 11
0
    def __init__(self,
                 pos,
                 width,
                 height,
                 type=None,
                 bc=color_rgb(255, 255, 255),
                 text="",
                 size=18,
                 txtc=color_rgb(0, 0, 0),
                 style="normal",
                 font="arial"):

        oWidth = width / 2  #offset width
        oHeight = height / 2  #offset height

        pos1 = Point(pos.getX() - oWidth, pos.getY() - oHeight)
        pos2 = Point(pos.getX() + oWidth, pos.getY() + oHeight)

        self.object = Rectangle(pos1, pos2)
        self.object.setFill(bc)
        self.object.setOutline(color_rgb(255, 255, 255))
        self.pos = pos
        self.pos1 = pos1  #Left-Up Corner
        self.pos2 = pos2  #Right-Down Corner
        self.type = type
        self.width = width
        self.height = height

        self.text = Text(self.object.getCenter(), text, size, txtc, style,
                         font)
Exemplo n.º 12
0
 def __init__(self, xloc, num=random.randint(1, 6), willDiscard=False):
     self.num = num
     self.willDiscard = willDiscard
     self.xloc = xloc
     self.img = Rectangle(Point(20 + 50 * self.xloc, 100),
                          Point(20 + 50 * (self.xloc + 1), 50))
     self.text = Text(Point(45 + 50 * self.xloc, 75), self.num).draw(win)
Exemplo n.º 13
0
    def __init__(self, win, center, width, height, label='Button'):
        """
        Creates a rectangular button.

        Example usage:
        ==============
        centerPoint = Point(x, y)
        button = Button(win, centerPoint, width, height, 'Click Me!')
        """

        # Get most extreme vertices of button
        half_width = width / 2.0
        half_height = height / 2.0
        x, y = center.getX(), center.getY()
        self.x_min, self.y_min = x - half_width, y - half_height
        self.x_max, self.y_max = x + half_width, y + half_height

        # Create button outline
        point1 = Point(self.x_min, self.y_min)
        point2 = Point(self.x_max, self.y_max)
        self.rect = Rectangle(point1, point2)
        self.rect.setFill('lightgrey')
        self.rect.draw(win)

        # Create button text
        self.label = Text(center, label)
        self.label.draw(win)
        self.deactivate()
Exemplo n.º 14
0
    def __init__(self, x, y, size):
        self.col = x        #Igual no hace falta
        self.row = y        #Igual no hace falta
        self.size = size    #Igual no hace falta

        self.wall = False
        self.square = Rectangle(Point(x*size,y*size+50), Point(x*size+size, y*size+size+50))
Exemplo n.º 15
0
 def __init__(self, config):
     self.board = BulletinBoard(config.get_board_width(),
                                config.get_board_height())
     self.wall = BrickWall(self.board.get_width(),
                           self.board.get_height() * 0.3,
                           config.get_color_matrix(),
                           config.get_color_map(), config.outline_bricks())
     paddle_width = self.board.get_width() // 8
     paddle_height = self.board.get_height() // 40
     self.paddle = Rectangle(paddle_width,
                             paddle_height,
                             "black",
                             filled=True)
     self.board.pin(self.wall, 0, 0.1 * self.board.get_height())
     self.board.pin(self.paddle,
                    self.board.get_width() / 2,
                    0.9 * self.board.get_height())
     self.reset_ball()
     self.message_box = TextBox("", "Helvetica Neue", 20, "#0000FF")
     self.dy = config.get_initial_y_velocity()
     self.dx = random.uniform(config.get_min_x_velocity(),
                              config.get_max_x_velocity())
     self.dx = random.choice([-1, 1]) * self.dx
     self.lives_left = config.get_num_balls()
     self.time_step = config.get_time_step()
     self.game_in_progress = False
     self.game_over = False
Exemplo n.º 16
0
 def __init__(self, bl, tr, color):
     self.bl = bl
     self.tr = tr
     self.rectangle = Rectangle(Point(self.bl[0], self.bl[1]),
                                Point(self.tr[0], self.tr[1]))
     self.piece_image = None
     self.piece_obj = None
     self.state = {"active": False, "original_fill": color}
Exemplo n.º 17
0
 def __init__(self, xPos, yPos, type):
     self.xPos = xPos
     self.yPos = yPos
     self.type = type
     self.img = Rectangle(Point((20 * xPos), (20 * yPos)),
                          Point((20 * xPos + 20), (20 * yPos + 20)))
     self.img.setFill(colors[self.type])
     self.img.draw(win)
Exemplo n.º 18
0
 def respawn(self):
     self.position = Point(random.randint(0, self.game.size.x),
                           random.randint(0, self.game.size.y))
     self.__rectangle.undraw()
     self.__rectangle = Rectangle(
         self.position + self.game.position,
         self.position + self.game.position + SCALE_V)
     self.__rectangle.draw(self.win)
Exemplo n.º 19
0
    def __init__(self, point, color):
        top_left_corner = Point(point.x * Block.PIXEL_TO_SQUARE_CONVERTING,
                                point.y * Block.PIXEL_TO_SQUARE_CONVERTING)
        bottom_right_corner = Point(top_left_corner.x + Block.WIDTH_OF_SQUARE,
                                    top_left_corner.y + Block.WIDTH_OF_SQUARE)

        Rectangle.__init__(self, top_left_corner, bottom_right_corner)

        self.setFill(color)
Exemplo n.º 20
0
    def __init__(self, point, color):
        top_left_corner = Point(point.x * Block.BLOCK_SIZE,
                                point.y * Block.BLOCK_SIZE)
        bottom_right_corner = Point(top_left_corner.x + Block.BLOCK_SIZE,
                                    top_left_corner.y + Block.BLOCK_SIZE)

        Rectangle.__init__(self, top_left_corner, bottom_right_corner)

        self.setFill(color)
Exemplo n.º 21
0
 def __init__(self, pos, color):
     self.x = pos.x
     self.y = pos.y
     p1 = Point(pos.x*Block.BLOCK_SIZE + Block.OUTLINE_WIDTH,
                pos.y*Block.BLOCK_SIZE + Block.OUTLINE_WIDTH)
     p2 = Point(p1.x + Block.BLOCK_SIZE, p1.y + Block.BLOCK_SIZE)
     Rectangle.__init__(self, p1, p2)
     self.setWidth(Block.OUTLINE_WIDTH)
     self.setFill(color)
Exemplo n.º 22
0
 def move(self, dx, dy):
     """
     Parameters: dx - type: int, dy - type: int
     moves the block dx squares in the x direction
     and dy squares in the y direction
     """
     self.x += dx
     self.y += dy
     Rectangle.move(self, dx*Block.BLOCK_SIZE, dy*Block.BLOCK_SIZE)
Exemplo n.º 23
0
    def __init__(self, x, y, window, fill=SNAKE_COLOR):
        self.coordinates = (x, y)

        self.rectangle = Rectangle(
            Point(x * TILE_SIZE, y * TILE_SIZE),
            Point((x + 1) * TILE_SIZE, (y + 1) * TILE_SIZE))

        self.rectangle.setFill(fill)
        self.rectangle.setOutline(BACKGROUND_COLOR)
        self.rectangle.draw(window)
Exemplo n.º 24
0
 def __init__(self, win, game):
     self.win = win
     self.game = game
     self.position = Point(random.randint(0, self.game.size.x),
                           random.randint(0, self.game.size.y))
     self.__rectangle = Rectangle(
         self.position + self.game.position,
         self.position + self.game.position + SCALE_V)
     self.__rectangle.setFill('green')
     self.__rectangle.draw(self.win)
Exemplo n.º 25
0
class Rectangulo_centro(object):#clase para crear rectangulos centrados
    def __init__(self, ventana):
        ancho = ventana.width / 2
        alto = ventana.height / 2
        p1 = Point(ancho - 20, alto - 10)
        p2 = Point(ancho + 20, alto + 10)
        self.r = Rectangle(p1, p2)
        self.r.draw(ventana)
    def color(self, c):
        self.r.setFill(c)
Exemplo n.º 26
0
 def __init__(self, msg, bg_color):
     super().__init__()
     self.rect = Rectangle(120, 50, bg_color)
     self.pin(self.rect, -60, -25)
     self.textbox = None
     self.update_count(msg)
     self.triangle = None
     self.triangle_rotation = 0
     self.triangle_color = "#ABC2FF"
     self.draw_triangle()
Exemplo n.º 27
0
 def __init__(self, window, width, height, rows, columns, wall_height):
     self.window = window
     self.bricks = []
     self.w = width
     self.h = height
     self.player = Rectangle(100, 25, fill=(255, 128, 128, 255))
     self.ball = Rectangle(25, 25, fill=(128, 128, 255, 255))
     self.generate_bricks(width, wall_height, rows, columns)
     self.debug_info = Text("Temp", font_name="Courier", pos=(25, 25))
     self.speed_multiplier = 6.0
     self.reset()
Exemplo n.º 28
0
class Tile:

    # TODO make it just accept x, y coords and callback
    def __init__(self, dimensions, size, i, j):

        x = dimensions['x']
        y = dimensions['y']
        width = dimensions['width']
        height = dimensions['height']

        # In future might make across able to be different to down
        across = down = size
        self.area = Rectangle(Point(x + width * i, y + height * j),
                              Point(x + width * (i + 1), y + height * (j + 1)))
        self.text = Text(
            Point(x + width * (i + 1 / 2), y + height * (j + 1 / 2)), '')
        self.value = 0
        self.assign(i, j, across, down)

    def draw(self, win):
        self.area.draw(win)
        self.text.draw(win)
        return self

    def clear(self):
        self.area.undraw()
        self.text.undraw()
        return self

    def update(self, number):
        self.value = number
        if number > 0:
            self.text.setText(str(number))
        else:
            self.text.setText('')
        return self

    def double(self):
        self.update(2 * self.value)
        return self

    # Given the coordinates in the grid, assign direction for a move to perform
    # This could be simpler, TODO
    def assign(self, i, j, across, down):
        if (i == 0 and j != 0 and j != (down - 1)):
            self.direction = 'left'
        elif (i == (across - 1) and j != 0 and j != (down - 1)):
            self.direction = 'right'
        elif (j == 0 and i != 0 and i != (across - 1)):
            self.direction = 'up'
        elif (j == (down - 1) and i != 0 and i != (across - 1)):
            self.direction = 'down'
        else:
            self.direction = False
Exemplo n.º 29
0
def gen_rectangle(o, x, y, l, color='black', dx=100, dy=100):
    p1 = Point(x * dx, y * dy)
    if o == 0:  # horizontal
        p2 = Point(x * dx + dx * l, (1 + y) * dy)
    else:
        p2 = Point((1 + x) * dx, y * dy + dy * l)

    rectangle = Rectangle(p1, p2)
    rectangle.setFill(color)

    return rectangle
Exemplo n.º 30
0
 def __init__(self, graphWin, id):
     Rectangle.__init__(self, Point(350, 570), Point(450, 590))
     self.id = id
     self.color = color_rgb(random.randint(10,
                                           255), random.randint(10, 255),
                            random.randint(10, 255))
     self.score = 0
     if graphWin.render:
         self.setFill(self.color)
         self.draw(graphWin)
     self.ball = Ball(self, graphWin)
     self.alive = True
Exemplo n.º 31
0
    def __init__(self, back_wheel_center, back_tire_radius, front_wheel_center,
                 front_tire_radius, body_height):
        upper_left_point = Point(back_wheel_center.x,
                                 back_wheel_center.y - body_height)
        bottom_right_point = front_wheel_center
        self.body = Rectangle(upper_left_point, bottom_right_point)

        self.back_wheel = Wheel(back_wheel_center,
                                back_tire_radius * Car.WHEEL_TO_TIRE_RATIO,
                                back_tire_radius)
        self.front_wheel = Wheel(front_wheel_center,
                                 front_tire_radius * Car.WHEEL_TO_TIRE_RATIO,
                                 front_tire_radius)
Exemplo n.º 32
0
 def __init__(self, ventana):
     ancho = ventana.width / 2
     alto = ventana.height / 2
     p1 = Point(ancho - 20, alto - 10)
     p2 = Point(ancho + 20, alto + 10)
     self.r = Rectangle(p1, p2)
     self.r.draw(ventana)
Exemplo n.º 33
0
class Boton(object):
    def __init__(self, v, centro, ancho, alto, etiqueta):
        #calculo de la posicion
        x, y = centro.getX(), centro.getY()
        w, h = ancho /2, alto /2
        self.xmax, self.xmin = x+w, x-w
        self.ymax, self.ymin = y+h, y-h
        p1 = Point(self.xmin, self.ymin)
        p2 = Point(self.xmax, self.ymax)
        #creacion del boton y etiqueta
        self.boton = Rectangle(p1, p2)
        self.boton.draw(v)
        self.boton.setFill('#CCC')
        self.etiqueta = Text(centro, etiqueta)
        self.etiqueta.setTextColor('#666')
        self.etiqueta.draw(v)
        self.desactivar()
    def color(self, c):
        self.boton.setFill(c)
    def pulsado(self, p):
        if p.getX() in range(self.xmin, self.xmax) and p.getY() in range(self.ymin, self.ymax):
            return True
        else:
            return False
    def activar(self):
        self.etiqueta.setTextColor('#000')
        self.estado = True
        
    def desactivar(self):
        self.etiqueta.setTextColor('#666')
        self.estado = False
Exemplo n.º 34
0
 def __init__(self, v, centro, ancho, alto, etiqueta):
     #calculo de la posicion
     x, y = centro.getX(), centro.getY()
     w, h = ancho /2, alto /2
     self.xmax, self.xmin = x+w, x-w
     self.ymax, self.ymin = y+h, y-h
     p1 = Point(self.xmin, self.ymin)
     p2 = Point(self.xmax, self.ymax)
     #creacion del boton y etiqueta
     self.boton = Rectangle(p1, p2)
     self.boton.draw(v)
     self.boton.setFill('#CCC')
     self.etiqueta = Text(centro, etiqueta)
     self.etiqueta.setTextColor('#666')
     self.etiqueta.draw(v)
     self.desactivar()
Exemplo n.º 35
0
def main():
    win = graphics.GraphWin()
    shape = Rectangle(Point(75,75),Point(125,125))
    shape.setOutline('Red')
    shape.setFill('Red')
    shape.draw(win)
 
    for i in range(10):
        p = win.getMouse()
        tx = p.getX()-25
        ty = p.getY()-25
        bx = p.getX()+25
        by = p.getY()+25
 
        Rectangle(Point(tx,ty),Point(bx,by)).draw(win)
 
    Text(Point(100,180),'Click again to quit!').draw(win)
    win.getMouse()
    win.close()
Exemplo n.º 36
0
 def __init__(self, v, centro, ancho, alto):
     x, y = centro.getX(), centro.getY()
     w, h = ancho /2, alto /2
     self.ventana = v
     self.xmax, self.xmin = x+w, x-w
     self.ymax, self.ymin = y+h, y-h
     p1 = Point(self.xmin, self.ymin)
     p2 = Point(self.xmax, self.ymax)
     self.dado = Rectangle(p1, p2)
     self.dado.draw(v)
     self.dado.setFill('#FF0000')
     '''pintamos los circulos del dado con las posiciones reescalables de los puntos
 
         pos1            pos5
         pos2    pos4    pos6
         pos3            pos7
         
     '''
     self.pos1 = Point(self.xmin + w /2, self.ymin + h /2)
     self.pos2 = Point(self.xmin + w / 2, self.ymin + h)
     self.pos3 = Point(self.xmin + w / 2, self.ymin + h * 1.5)
     self.pos4 = Point(self.xmin + w, self.ymin + h)
     self.pos5 = Point(self.xmin + w * 1.5, self.ymin + h /2)
     self.pos6 = Point(self.xmin + w * 1.5, self.ymin + h)
     self.pos7 = Point(self.xmin + w * 1.5, self.ymin + h * 1.5)
     
     self.c1 = Circle(self.pos1, 4)
     self.c1.setOutline('#fff')
     self.c1.setFill('#fff')
     self.c1.draw(self.ventana)
         
     self.c2 = Circle(self.pos2, 4)
     self.c2.setOutline('#fff')
     self.c2.setFill('#fff')
     self.c2.draw(self.ventana)
         
     self.c3 = Circle(self.pos3, 4)
     self.c3.setOutline('#fff')
     self.c3.setFill('#fff')
     self.c3.draw(self.ventana) 
         
     self.c4 = Circle(self.pos4, 4)
     self.c4.setOutline('#fff')
     self.c4.setFill('#fff')
     self.c4.draw(self.ventana)
         
     self.c5 = Circle(self.pos5, 4)
     self.c5.setOutline('#fff')
     self.c5.setFill('#fff')
     self.c5.draw(self.ventana)
         
     self.c6 = Circle(self.pos6, 4)
     self.c6.setOutline('#fff')
     self.c6.setFill('#fff')
     self.c6.draw(self.ventana)
         
     self.c7 = Circle(self.pos7, 4)
     self.c7.setOutline('#fff')
     self.c7.setFill('#fff')
     self.c7.draw(self.ventana)
     
     self.limpiar()
Exemplo n.º 37
0
            points = [[Point(left_marg + c * dim//size, top_marg + r * dim//size) for c in range(size + 1)] for r in range(size + 1)]
            dots = [[Circle(p, 5) for p in l] for l in points]
            for l in dots:
                for c in l:
                    c.setFill('black')
                    c.draw(win)

            printer(win, results_dir, f, i, 0)
            for j, (player, entry) in enumerate(game['history'], start=1):
                # Box finished
                is_vert, r, c = entry
                r = int(r)
                c = int(c)
                if is_vert == '':
                    rec = Rectangle(points[r][c], points[r+1][c+1])
                    rec.setFill(colors[player])
                    rec.draw(win)
                    scores[player] += 1
                    score_text[player].undraw()
                    score_text[player].setText('{}:{}'.format(wins[player], scores[player]))
                    score_text[player].draw(win)
                else:
                    if is_vert:
                        line = Line(points[r][c], points[r+1][c])
                    else:
                        line = Line(points[r][c], points[r][c+1])
                    line.draw(win)
                    line.setFill(colors[player])

                printer(win, results_dir, f, i, j)
Exemplo n.º 38
0
class Dado(object):
    def __init__(self, v, centro, ancho, alto):
        x, y = centro.getX(), centro.getY()
        w, h = ancho /2, alto /2
        self.ventana = v
        self.xmax, self.xmin = x+w, x-w
        self.ymax, self.ymin = y+h, y-h
        p1 = Point(self.xmin, self.ymin)
        p2 = Point(self.xmax, self.ymax)
        self.dado = Rectangle(p1, p2)
        self.dado.draw(v)
        self.dado.setFill('#FF0000')
        '''pintamos los circulos del dado con las posiciones reescalables de los puntos
    
            pos1            pos5
            pos2    pos4    pos6
            pos3            pos7
            
        '''
        self.pos1 = Point(self.xmin + w /2, self.ymin + h /2)
        self.pos2 = Point(self.xmin + w / 2, self.ymin + h)
        self.pos3 = Point(self.xmin + w / 2, self.ymin + h * 1.5)
        self.pos4 = Point(self.xmin + w, self.ymin + h)
        self.pos5 = Point(self.xmin + w * 1.5, self.ymin + h /2)
        self.pos6 = Point(self.xmin + w * 1.5, self.ymin + h)
        self.pos7 = Point(self.xmin + w * 1.5, self.ymin + h * 1.5)
        
        self.c1 = Circle(self.pos1, 4)
        self.c1.setOutline('#fff')
        self.c1.setFill('#fff')
        self.c1.draw(self.ventana)
            
        self.c2 = Circle(self.pos2, 4)
        self.c2.setOutline('#fff')
        self.c2.setFill('#fff')
        self.c2.draw(self.ventana)
            
        self.c3 = Circle(self.pos3, 4)
        self.c3.setOutline('#fff')
        self.c3.setFill('#fff')
        self.c3.draw(self.ventana) 
            
        self.c4 = Circle(self.pos4, 4)
        self.c4.setOutline('#fff')
        self.c4.setFill('#fff')
        self.c4.draw(self.ventana)
            
        self.c5 = Circle(self.pos5, 4)
        self.c5.setOutline('#fff')
        self.c5.setFill('#fff')
        self.c5.draw(self.ventana)
            
        self.c6 = Circle(self.pos6, 4)
        self.c6.setOutline('#fff')
        self.c6.setFill('#fff')
        self.c6.draw(self.ventana)
            
        self.c7 = Circle(self.pos7, 4)
        self.c7.setOutline('#fff')
        self.c7.setFill('#fff')
        self.c7.draw(self.ventana)
        
        self.limpiar()
        
    def colorDado(self, c):#personalizar el dado
        self.dado.setFill(c)
        
    def colorPunto(self, c):#personalizar los puntos del dado
        self.c1.setOutline(c)
        self.c1.setFill(c)
        self.c2.setOutline(c)
        self.c2.setFill(c)
        self.c3.setOutline(c)
        self.c3.setFill(c)
        self.c4.setOutline(c)
        self.c4.setFill(c)
        self.c5.setOutline(c)
        self.c5.setFill(c)
        self.c6.setOutline(c)
        self.c6.setFill(c)
        self.c7.setOutline(c)
        self.c7.setFill(c)
        
    def pulsado(self, p):#funcion para saber si se ha pulsado
        if p.getX() in range(self.xmin, self.xmax) and p.getY() in range(self.ymin, self.ymax):
            return True
        else:
            return False
        
    def ponValor(self, valor=1):#funcion para establecer la cara visible del dado
        self.limpiar()
        if valor == 1:
            self.c4.draw(self.ventana)
        elif valor == 2:
            self.c1.draw(self.ventana)
            self.c7.draw(self.ventana)
        elif valor == 3:
            self.c1.draw(self.ventana)
            self.c4.draw(self.ventana)
            self.c7.draw(self.ventana)
        elif valor == 4:
            self.c1.draw(self.ventana)
            self.c3.draw(self.ventana)
            self.c5.draw(self.ventana)
            self.c7.draw(self.ventana)
        elif valor == 5:
            self.c1.draw(self.ventana)
            self.c3.draw(self.ventana)
            self.c4.draw(self.ventana)
            self.c5.draw(self.ventana)
            self.c7.draw(self.ventana)
        elif valor == 6:
            self.c1.draw(self.ventana)
            self.c2.draw(self.ventana)
            self.c3.draw(self.ventana) 
            self.c5.draw(self.ventana)
            self.c6.draw(self.ventana)
            self.c7.draw(self.ventana)
            
    def limpiar(self):#limpiar el dado antes de pintar
        self.c1.undraw()
        self.c2.undraw()
        self.c3.undraw()
        self.c4.undraw()
        self.c5.undraw()
        self.c6.undraw()
        self.c7.undraw()
        
    def tirarDado(self):#funcion para visualizar aleatoriamente una cara
        posibles = [1, 2, 3, 4, 5, 6]
        num = choice(posibles)
        self.ponValor(num)
        return num
Exemplo n.º 39
0
def main():
 
    win = graphics.GraphWin('Investment Grow Chart',320,240)
    win.setBackground('White')
    win.setCoords(-1.75,-9000,11.5,15400)
     
    Text(Point(4.87,13500),'Future Value Calculator').draw(win)
         
    Text(Point(4.5,-2000),'Input first principal:').draw(win)
    inputP = Entry(Point(9,-2000),6)
    inputP.setText('0')
    inputP.draw(win)
     
    Text(Point(3,-4000),' Input interest rate in decimal:').draw(win)
    inputR = Entry(Point(9,-4000),6)
    inputR.setText('0.0')
    inputR.draw(win)
     
     
    button = Rectangle(Point(2,-6000),Point(8,-8500))
    button.setFill('Green')
    button.draw(win)
    buttontext = Text(Point(5,-7250),'Show Result!:')
    buttontext.draw(win)
    win.getMouse()
     
    p = eval(inputP.getText())
    r = eval(inputR.getText())   
     
     
    Text(Point(-1,0),'0 K').draw(win)
    Text(Point(-1,2500),'2.5K').draw(win)
    Text(Point(-1,5000),'5 K').draw(win)
    Text(Point(-1,7500),'7.5K').draw(win)
    Text(Point(-1,10000),'10 K').draw(win)
     
    bar = Rectangle(Point(0,0),Point(1,p))
    bar.setFill('green')
    bar.setWidth(2)
    bar.draw(win)
     
    for i in range(1,11):
        p = p*(1+r)
        bar= Rectangle(Point(i,0),Point(i+1,p))
        bar.setFill('Green')
        bar.setWidth(2)
        bar.draw(win) 
     
    buttontext.setText('Quit.')
     
    win.getMouse()
    win.close()