Esempio n. 1
0
 def move(self, x, y):
     self.col = x
     self.row = y
     self.circle.undraw()
     self.face.undraw()
     self.circle = Circle(Point(x * 50 + 25, y * 50 + 50 + 25), 20)
     self.face = self._getFace()
def draw_grid(size):
    squares = size - 1
    win = GraphWin("Graphical traced walk", 50 * size, 50 * size)
    win.setCoords(0, size, size, 0)

    border_rectangle = Rectangle(Point(0.5, 0.5), Point(size - 0.5, size - 0.5)).draw(win)
    border_rectangle.setFill("gray")
    border_rectangle.setWidth(2)

    centre_square = Rectangle(
        Point(size / 2 - 0.5, size / 2 - 0.5),
        Point(size / 2 + 0.5, size / 2 + 0.5),
    ).draw(win)
    centre_square.setFill("cyan")
    centre_square.setOutline("")

    person = Circle(Point(size / 2, size / 2), 0.25).draw(win)
    person.setFill("red")

    square_texts = [[""] * squares for _ in range(squares)]

    for i in range(squares):
        for j in range(squares):
            # grid lines
            Line(Point(1.5 + j, 0.5), Point(1.5 + j, size - 0.5)).draw(win)
            Line(Point(0.5, 1.5 + j), Point(size - 0.5, 1.5 + j)).draw(win)

            # text within each square
            square_text = Text(Point(1 + j, 1 + i), "").draw(win)
            square_texts[i][j] = square_text

    return win, person, square_texts
Esempio n. 3
0
    def update_territories(self):
        """Update the black and white territories on the board.

            Attributes updated by this function:
                self.batch_territory
        """
        # Display the territory an the regular batch
        # Display the stones on the regular batch
        self.batch_territory = self.batch
        
        rad = 5
        
        # Iterate trough all territory indicators and place the corresponding
        # black or white circle on the grid or above stones
        for i in range(0, self.data['size']):
            for j in range(0, self.data['size']):
                if self.data['territory'][j][i] != None:
                    x_coord, y_coord = self.grid.get_coords(i, j)
                    if self.data['territory'][j][i] == BLACK:
                        Circle(x_coord,
                               y_coord,
                               color=BLACK_TERRITORY,
                               r=rad,
                               batch=self.batch_territory,
                               group=self.grp_territory)
                    elif self.data['territory'][j][i] == WHITE:
                        Circle(x_coord,
                               y_coord,
                               color=WHITE_TERRITORY,
                               r=rad,
                               batch=self.batch_territory,
                               group=self.grp_territory)
Esempio n. 4
0
class Face:
    def __init__(self, window, center, size):
        eyeSize = 0.15 * size
        eyeOff = size / 3.0
        mouthSize = 0.8 * size
        mouthOff = size / 2.0
        self.head = Circle(center, size)
        self.head.draw(window)
        self.leftEye = Circle(center, eyeSize)
        self.leftEye.move(-eyeOff, -eyeOff)
        self.rightEye = Circle(center, eyeSize)
        self.rightEye.move(eyeOff, -eyeOff)
        self.leftEye.draw(window)
        self.rightEye.draw(window)
        p1 = center.clone()
        p1.move(-mouthSize / 2, mouthOff)
        p2 = center.clone()
        p2.move(mouthSize / 2, mouthOff)
        self.mouth = Line(p1, p2)
        self.mouth.draw(window)

    def Move(self, dx, dy):
        for p in self.points:
            p.Move(dx, dy)

    def Flinch(self, center, size, window):
        eyesize = 0.15 * size
        eyeOff = size / 3.0
        self.leftEye = Line(Point(center.x + eyesize / 2, center.y),
                            Point(center.x - eyesize / 2, center.y))
        self.leftEye.move(-eyeOff, -eyeOff)
        self.rightEye = Circle(center, eyesize)
        self.rightEye.move(eyeOff, -eyeOff)
        self.leftEye.draw(window)
        self.rightEye.draw(window)
Esempio n. 5
0
class Intersection:
    """graphical representation of a vertex"""
    def __init__(self, vertex):
        self.id = vertex.id
        self.x = vertex.x
        self.y = vertex.y
        self.radius = 3
        self.shape = Circle(Point(self.x, self.y), self.radius)

    def __repr__(self):
        return "Intersection {0}: ({1}, {2})".format(self.id, self.x, self.y)

    def draw(self, canvas):
        self.shape.draw(canvas)

    def clicked(self, p):
        xmin = self.x - self.radius
        xmax = self.x + self.radius
        ymin = self.y - self.radius
        ymax = self.y + self.radius
        return (xmin <= p.getX() <= xmax and ymin <= p.getY() <= ymax)

    def get_info(self):
        info = {
            "type": "Intersection",
            "id": self.id,
            "x": "{0:.1f}".format(self.x),
            "y": "{0:.1f}".format(self.y),
        }
        return info
Esempio n. 6
0
 def __moveBall(self, pos):
     """Move a graphic to a particular position on the window,
     rather than move by an amount"""
     old = self.graphic
     graphic = Circle(pos, self.rad)
     graphic.draw(self.window)
     self.graphic = graphic
     old.undraw()
Esempio n. 7
0
 def __init__(self, x, y, vx, vy):
     self.size = 500
     self.px = x
     self.py = y
     self.m = 20
     self.vx = vx
     self.vy = vy
     Circle.__init__(self, Point(self.px, self.py), self.m)
Esempio n. 8
0
def draw_path(final_path):
    for i in final_path:
        dot = Circle(
            Point((i.j * square_size) + square_size / 2,
                  (i.i * square_size) + square_size / 2), 10)
        dot.setFill(color_rgb(206, 141, 14))
        dot.setOutline(color="white")
        dot.setWidth(3)
        dot.draw(win)
Esempio n. 9
0
 def __init__(self, x, y):
     self.col = x
     self.row = y
     self.circle = Circle(Point(x * 50 + 25, y * 50 + 50 + 25), 20)
     self.facing = self.NORTE
     self.face = self._getFace()
     self.attached = False
     self.s = [False, False, False, False, False, False, False, False]
     self.x = [False, False, False, False]
Esempio n. 10
0
 def Flinch(self, center, size, window):
     eyesize = 0.15 * size
     eyeOff = size / 3.0
     self.leftEye = Line(Point(center.x + eyesize / 2, center.y),
                         Point(center.x - eyesize / 2, center.y))
     self.leftEye.move(-eyeOff, -eyeOff)
     self.rightEye = Circle(center, eyesize)
     self.rightEye.move(eyeOff, -eyeOff)
     self.leftEye.draw(window)
     self.rightEye.draw(window)
Esempio n. 11
0
    def __init__(self, win, angle, velocity, height):
        """win is the GraphWin to display the shot. angle, velocity,
            and height are initial projectile parameters.
        """

        self.proj = Projectile(angle, velocity, height)
        self.marker = Circle(Point(0, height), 3)
        self.marker.setFill("red")
        self.marker.setOutline("red")
        self.marker.draw(win)
def draw_circle(win, colour, centre, radius, current_tile, fill=False):
    """Helper function for drawing circles."""
    current_circle = Circle(Point(*centre), radius)
    if fill:
        current_circle.setFill(colour)
    else:
        current_circle.setOutline(colour)
    current_circle.setOutline(colour)
    current_circle.draw(win)
    current_tile.append(current_circle)
Esempio n. 13
0
def draw_coin(window, x, y, score):
    coinCoord = Point(OFFSET + y * SCALE, OFFSET + x * VSCALE)
    if score == 2:
        coin = Circle(coinCoord, GOLD_SIZE)
        coin.setFill(GOLD_COIN)
    else:
        coin = Circle(coinCoord, SILVER_SIZE)
        coin.setFill(SILVER_COIN)
    coin.draw(window)
    return coin
Esempio n. 14
0
 def set_graphicals(self):
     # draw player
     self.body = Circle(Point(scale(self.pos_x), scale(self.pos_y)), 7)
     self.body.setFill('red')
     # Note: downwards in Y is the positive direction for this graphics lib
     #self.arrow = Line(Point(scale(self.pos_x), scale(self.pos_y)),
     #    Point(scale(self.pos_x + self.vel_x), scale(self.pos_y + self.vel_y)))
     #self.arrow.setFill('black')
     #self.arrow.setArrow('last')
     self.body.draw(self.win)
Esempio n. 15
0
def draw_arrow(win, arrow_x, arrow_y):
    """Draw an arrow onto the given graphics window."""
    arrow_shaft = Circle(Point(arrow_x, arrow_y), 0.008).draw(win)
    arrow_shaft.setFill("brown")

    for x in (1, -1):
        fletching = Line(Point(arrow_x + 0.02, arrow_y + 0.02 * x),
                         Point(arrow_x - 0.02, arrow_y - 0.02 * x)).draw(win)
        fletching.setWidth(2)
        fletching.setFill("gray")
Esempio n. 16
0
def draw_circle(board_column, board_row, color, dot_size):
    if color != "white":
        head = Circle(
            Point((board_column * (size * 2) + (offsetC + dot_size)),
                  (board_row * (size * 2) + (offsetR + dot_size))), dot_size)
        head.setFill(color)
    else:
        head = Circle(
            Point((board_column * (size * 2) + (offsetC + dot_size)),
                  (board_row * (size * 2) + (offsetR + dot_size))),
            dot_size / 3)
        head.setFill(color)
    head.draw(win)
Esempio n. 17
0
    def __init__(self, pos, dest, win, vel, type):
        self.pos = pos
        self.dest = Point(dest.getX() - pos.getX(), dest.getY() - pos.getY())
        self.vel = vel
        self.type = type
        self.aliveFlag = True
        self.outOfBounds = False

        r = 25 * type
        self.object = Circle(self.pos, r)
        self.object.setFill(color_rgb(randrange(100, 255), 240, 90))

        self.draw(win)
Esempio n. 18
0
    def __init__(self, pos, win, r, dest, vel=1.0, c=color_rgb(255, 255, 255)):
        self.pos = pos  #position
        self.dest = Point(dest.getX() - pos.getX(),
                          dest.getY() - pos.getY())  #destination
        self.radius = r  #radius
        self.vel = vel  #velocity

        self.object = Circle(self.pos, r)  #Circle
        self.object.setFill(c)  #set colour
        self.object.setOutline('black')
        self.draw(win)  #draw

        self.aliveFlag = True
Esempio n. 19
0
 def createWindow(self, N):
     """
     Create the graphics window.
     Arguments:
         self - the SkewerUI instance
         N - the capacity of the skewer
     """
     self.win = GraphWin("Shish Kebab", 800, 200)
     self.win.setCoords( \
         WIN_LOW_LEFT_X, \
         WIN_LOW_LEFT_Y - 0.1, \
         WIN_LOW_LEFT_X+(N+1)*FOOD_WIDTH, \
         WIN_UP_RIGHT_Y + 0.1 \
     )
     
     # draw skewer
     line = Line( \
         Point(WIN_LOW_LEFT_X, WIN_LOW_LEFT_Y+WIN_HEIGHT/2.0), \
         Point(N, WIN_LOW_LEFT_Y+WIN_HEIGHT/2.0) \
     )
     line.setWidth(LINE_THICKNESS)
     line.draw(self.win)
     handle = Circle( \
         Point(N-.1, WIN_LOW_LEFT_Y+WIN_HEIGHT/2.0), \
         SKEWER_HANDLE_RADIUS \
     )
     handle.setFill(BKGD_COLOR)
     handle.setWidth(LINE_THICKNESS)
     handle.draw(self.win)
     self.items = []
Esempio n. 20
0
    def __init__(self, pos, r, vel=1.0, c=color_rgb(255, 255, 255)):
        self.pos = pos  #position
        self.radius = r  #radius
        self.vel = vel  #velocity
        self.colour = c

        self.object = Circle(self.pos, r)
        self.object.setFill(c)
        self.object.setOutline('black')
        self.bullets = []  #bullet list

        self.score = 0

        print(self.object.getRadius())
Esempio n. 21
0
    def set_graphicals(self):
        draw_x = scale(self.pos_x)
        draw_y = scale(self.pos_y)

        if self.circle is not None and self.get_trace is False:
            dubinc = Circle(self.circle.c.get_scaled_point(),
                            scale_vectors(self.circle.r))
            dubinc.setOutline('Green')
            dubinc.draw(self.win)

        if self.body is not None and self.get_trace is False:
            self.body.undraw()
        self.body = Circle(Point(draw_x, draw_y), self.body_radius)
        self.body.setFill('yellow')
        self.body.draw(self.win)
        if self.vel_arrow:
            self.vel_arrow.undraw()
        self.vel_arrow = Line(
            Point(draw_x, draw_y),
            Point(scale(self.pos_x + self.current_vel[0]),
                  scale(self.pos_y + self.current_vel[1])))
        self.vel_arrow.setFill('black')
        self.vel_arrow.setArrow("last")
        self.vel_arrow.draw(self.win)
        if self.acc_arrow:
            self.acc_arrow.undraw()
        self.acc_arrow = Line(
            Point(draw_x, draw_y),
            Point(scale(self.pos_x + self.current_acc[0] * 5),
                  scale(self.pos_y + self.current_acc[1] * 5)))
        self.acc_arrow.setFill('blue')
        self.acc_arrow.setArrow('last')
        self.acc_arrow.draw(self.win)
Esempio n. 22
0
 def __makePip(self, x, y):
     "Internal helper method to draw a pip at (x,y)"
     pip = Circle(Point(x, y), self.psize)
     pip.setFill(self.background)
     pip.setOutline(self.background)
     pip.draw(self.win)
     return pip
Esempio n. 23
0
    def draw_mark(self, move: tuple) -> None:
        """ Draw a mark as specified by a move 
        :param move: a legal move: (selected_tile.x_pos, selected_tile.y_pos, player.mark)
        :return: none
        """

        if self.window is None:
            raise ValueError('Board has no open window!')

        tile_x, tile_y, mark = move

        grid_x, grid_y = self.coord_tile_to_grid(tile_x, tile_y)

        rad = self.tile_size * 0.3

        if mark == 'O':
            cir = Circle(Point(grid_x, grid_y), rad)
            cir.setOutline('blue')
            cir.setWidth(3)
            cir.draw(self.window)
        else:
            downstroke = Line(Point(grid_x - rad, grid_y - rad),
                              Point(grid_x + rad, grid_y + rad))
            upstroke = Line(Point(grid_x - rad, grid_y + rad),
                            Point(grid_x + rad, grid_y - rad))
            downstroke.setOutline('red')
            downstroke.setWidth(3)
            upstroke.setOutline('red')
            upstroke.setWidth(3)
            upstroke.draw(self.window)
            downstroke.draw(self.window)
Esempio n. 24
0
 def __init__(self, team, points, win):
     self.win = win
     self.radius = 0.1
     self.position = points[0]
     self.looking = points[1]
     self.fire_line = self.get_fire()
     self.color = "red" if team == 0 else "blue"
     self.view_left = self.get_left()
     self.view_left.setFill(self.color)
     self.view_right = self.get_right()
     self.view_right.setFill(self.color)
     self.firing = True
     self.view = False
     self.body = Circle(self.position, self.radius)
     self.body.setFill(self.color)
Esempio n. 25
0
def five_click_stick_figure():
    """
    9. [harder] Write a five_click_stick_figure() function that allows the user
    to draw a (symmetric) stick figure in a graphics window using five clicks of
    the mouse to determine the positions of its features. Each feature should be
    drawn as the user clicks the points.

    Hint: the radius of the head is the distance between points 1 and 2 — see
    the previous practical.

    Note: only the y-coordinate of point (3) should be used — its x coordinate
    should be copied from point (1).
    """
    win = GraphWin("Five Click Stick Figure", 800, 600)
    message = Text(Point(400, 15), "Click to create your stick figure")
    message.draw(win)

    head_centre = win.getMouse()
    head_centreX, head_centreY = head_centre.getX(), head_centre.getY()
    head_perim = win.getMouse()
    head_perimX, head_perimY = head_perim.getX(), head_perim.getY()
    head_radius = math.sqrt((head_perimX - head_centreX)**2 +
                            (head_perimY - head_centreY)**2)
    head = Circle(head_centre, head_radius)
    head.draw(win)

    torso = win.getMouse()
    torso_line = Line(Point(head_centreX, head_centreY + head_radius),
                      Point(head_centreX, torso.getY()))
    torso_line.draw(win)

    arm_reach = win.getMouse()
    arm_length = head_centreX - arm_reach.getX()
    arms_line = Line(Point(arm_reach.getX(), arm_reach.getY()),
                     Point(head_centreX + arm_length, arm_reach.getY()))
    arms_line.draw(win)

    leg_reach = win.getMouse()
    left_leg_line = Line(Point(head_centreX, torso.getY()),
                         Point(leg_reach.getX(), leg_reach.getY()))
    left_leg_line.draw(win)

    leg_distance = head_centreX - leg_reach.getX()
    right_leg_line = Line(Point(head_centreX, torso.getY()),
                          Point(head_centreX + leg_distance, leg_reach.getY()))
    right_leg_line.draw(win)

    await_user_input(win)
Esempio n. 26
0
def spawn_disk() -> Circle:
    x = random.randint(
        int(-disk_size / 2),  # nosec
        int(win_size + disk_size / 2))
    y = random.randint(-win_size, -disk_size)  # nosec
    c = Circle(Point(x, y), disk_size)
    return c
Esempio n. 27
0
def make_button(msg, color):
    poster = Poster()
    circle = Circle(100, color, filled=True)
    poster.pin(circle, 0, 0)
    textbox = TextBox(msg, "Helvetica", "40")
    poster.pin(textbox, 0, 0)
    return poster
Esempio n. 28
0
def draw_classroom():
    win = GraphWin("Stick figure", 300, 200)

    head = Circle(Point(100, 60), 20)
    body = Line(Point(100, 80), Point(100, 120))
    arms = Line(Point(70, 90), Point(130, 90))
    leg_l = Line(Point(100, 120), Point(80, 170))
    leg_r = Line(Point(100, 120), Point(120, 170))

    for body_part in [head, body, arms, leg_l, leg_r]:
        body_part.draw(win)

    # Draw the Whiteboard
    whiteboard = Rectangle(Point(140, 50), Point(290, 150))
    whiteboard.setFill('white')
    whiteboard.draw(win)

    # Draw the blue marker pen base
    marker_pen = Rectangle(Point(120, 80), Point(128, 100))
    marker_pen.setFill('blue')
    marker_pen.draw(win)

    # Draw the blue marker pen tip
    marker_pen_tip = Rectangle(Point(122, 72), Point(126, 80))
    marker_pen_tip.setFill('blue')
    marker_pen_tip.draw(win)

    write_letters(win)
    marker_pen_tip.setFill('white')
Esempio n. 29
0
def draw_tour(path_d, all_nodes):
	from graphics import Point, Circle, Line, GraphWin
	maxX = max([x for x, y in all_nodes])
	minX = min([x for x, y in all_nodes])
	maxY = max([y for x, y in all_nodes])
	minY = min([y for x, y in all_nodes])

	N = 750
	norm_x = N/(maxX - minX)
	norm_y = N/(maxY - minY)

	win = GraphWin("TSP", N, N)
	for n in all_nodes:
		c = Point(*norm(n, norm_x, norm_y, minX, minY))
		c = Circle(c, 3)
		c.draw(win)

	for (k, subdict) in path_d.iteritems():
		#t = Text(Point(*subdict['center']*N), k)
		#t.draw(win)
		if not subdict['hasBeenSplit']:
			p = Point(*norm(subdict['center'], norm_x, norm_y, minX, minY))

			c1i, c2i = subdict['connections']
			c1 = Point(*norm(path_d[str(c1i)]['center'], norm_x, norm_y, minX, minY))
			c2 = Point(*norm(path_d[str(c2i)]['center'], norm_x, norm_y, minX, minY))
			l1 = Line(p, c1)
			l2 = Line(p, c2)
			l1.draw(win)
			l2.draw(win)

	win.getMouse()
	win.close()
Esempio n. 30
0
def draw_tour(tour):
    from graphics import Point, Circle, Line, GraphWin
    maxX = max([x for x, y in tour])
    minX = min([x for x, y in tour])
    maxY = max([y for x, y in tour])
    minY = min([y for x, y in tour])

    N = 750
    norm_x = N / (maxX - minX)
    norm_y = N / (maxY - minY)

    win = GraphWin("TSP", N, N)
    for n in tour:
        c = Point(*norm(n, norm_x, norm_y, minX, minY))
        c = Circle(c, 2)
        c.draw(win)

    for i, _ in enumerate(tour[:-1]):
        p1 = norm(tour[i], norm_x, norm_y, minX, minY)
        p2 = norm(tour[i + 1], norm_x, norm_y, minX, minY)
        l = Line(Point(*p1), Point(*p2))
        l.draw(win)

    win.getMouse()
    win.close()
Esempio n. 31
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--size", type=int, default=3, help="Size of k")
    args = parser.parse_args()

    win = GraphWin("My Circle", WIN_SIZE, WIN_SIZE)

    k = args.size
    m = k * (k - 1) + 1
    r = min(pi * R / m * 0.50, 20)

    ds = DiffState(k)
    ds.search()

    points = []
    for i in range(m):
        ang = 2 * pi * i / m
        center = (CENTER[0] + R * sin(ang), CENTER[1] - R * cos(ang))
        points.append(Point(center[0], center[1]))

    if m < 20:
        for i in range(m):
            for j in range(i, m):
                if not (i in ds.current and j in ds.current):
                    l = Line(points[i], points[j])
                    l.draw(win)
                    l.setOutline(all_color)

    for i in range(m):
        for j in range(i, m):
            if i in ds.current and j in ds.current:
                l = Line(points[i], points[j])
                l.setWidth(3)
                l.draw(win)
                l.setOutline(set_color)

    for i in range(m):
        c = Circle(points[i], r)
        c.setFill("red")
        c.draw(win)

    win.getMouse()
    win.close()
Esempio n. 32
0
def draw_patch(patch, win):
    if win is not None:
        c = Circle(Point(patch.x_pos, patch.y_pos), patch.radius)
        c.setOutline("red")
        c.draw(win)
Esempio n. 33
0
 def __init__(self,window,P1,level):
     from graphics import GraphWin,Circle
     import random
     from time import time
     self.p1=P1
     self.window=window
     self.cir=Circle(self.p1,0.4)
     self.level=level
     self.cir.setWidth(0)
    
     i=random.randrange(6,9+self.level)
     self.color=i
     if self.color==6:                 #颜色对应数字
         self.cir.setFill("red")
     if self.color==7:
         self.cir.setFill("green")
     if self.color==8:
         self.cir.setFill("black")
     if self.color==9:
         self.cir.setFill("blue")
     if self.color==10:
         self.cir.setFill("orange")
     for s in range(100):
         cirs=Circle(self.p1,0.0+s*0.004)
         if self.color==6:
             cirs.setFill("red")
         if self.color==7:
             cirs.setFill("green")
         if self.color==8:
             cirs.setFill("black")
         if self.color==9:
             cirs.setFill("blue")
         if self.color==10:
             cirs.setFill("orange")
         cirs.draw(self.window)
         empty=0                     #空循环控制时间(time间隔太大)
         while empty<=30000:
             empty=empty+1
         cirs.undraw()    
     self.cir.draw(self.window)
     self.activate=True
Esempio n. 34
0
class circle:
    
    def __init__(self,window,P1,level):
        from graphics import GraphWin,Circle
        import random
        from time import time
        self.p1=P1
        self.window=window
        self.cir=Circle(self.p1,0.4)
        self.level=level
        self.cir.setWidth(0)
       
        i=random.randrange(6,9+self.level)
        self.color=i
        if self.color==6:                 #颜色对应数字
            self.cir.setFill("red")
        if self.color==7:
            self.cir.setFill("green")
        if self.color==8:
            self.cir.setFill("black")
        if self.color==9:
            self.cir.setFill("blue")
        if self.color==10:
            self.cir.setFill("orange")
        for s in range(100):
            cirs=Circle(self.p1,0.0+s*0.004)
            if self.color==6:
                cirs.setFill("red")
            if self.color==7:
                cirs.setFill("green")
            if self.color==8:
                cirs.setFill("black")
            if self.color==9:
                cirs.setFill("blue")
            if self.color==10:
                cirs.setFill("orange")
            cirs.draw(self.window)
            empty=0                     #空循环控制时间(time间隔太大)
            while empty<=30000:
                empty=empty+1
            cirs.undraw()    
        self.cir.draw(self.window)
        self.activate=True
            
    
    def click(self,pr):
        from graphics import Circle
        import time
        pd=False       
        if self.activate==True and (pr.getX()-self.p1.getX())**2+(pr.getY()-self.p1.getY())**2<=0.24:
            
            for i in range(3):                    #点击动画
                self.cir.move(0,-0.12/3.0)
                time.sleep(0.01)
            for i in range(3):
                self.cir.move(0,0.12/3.0)
                time.sleep(0.01)
            for i in range(3):
                self.cir.move(0,-0.12/3.0)
                time.sleep(0.01)
            for i in range(3):
                self.cir.move(0,0.12/3.0)
                time.sleep(0.01)
            pd=True
        return pd
  
            
           
    def undraw(self):
        self.cir.undraw()
    def close(self):
        self.cir.undraw()
        self.activate=False
    def move(self,pr):
        self.cir.move(pr.getX()-self.p1.getX(),pr.getY()-self.p1.getY())
        self.p1.move(pr.getX()-self.p1.getX(),pr.getY()-self.p1.getY())
Esempio n. 35
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
Esempio 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()
Esempio n. 37
0
class Particle:
    def __init__(self, window, p=Point(0, 0)):
        self.particle = None
        self.drawn = False
        self.color = "RED"
        self.position = p
        self.x = p.getX()
        self.y = p.getY()
        self.size = 3
        self.dX = 0
        self.dY = 0
        self.win = window
        self.particleTurnCount = 0

    def setCoord(self, x, y):
        self.x = x
        self.y = y

    def setColor(self, color):
        self.color = color
        if self.particle:
            self.particle.setFill(color)

    def setSize(self, size):
        self.size = size
        if self.drawn:
            self.undraw()
            self.draw()

    def draw(self):
        self.particle = Circle(Point(self.x, self.y), self.size)
        self.particle.setFill(self.color)
        self.particle.draw(self.win)
        self.drawn = True

    def undraw(self):
        self.particle.undraw()
        self.drawn = False

    def setParticleMovement(self, dx, dy):
        self.dX = dx
        self.dY = dy

    def move(self):
        self.particle.move(self.dX, self.dY)
        self.position = Point(self.position.getX() + self.dX, self.position.getY() + self.dY)
        self.particle.undraw()
        self.particle.draw(self.win)
Esempio n. 38
0
 def draw(self):
     self.particle = Circle(Point(self.x, self.y), self.size)
     self.particle.setFill(self.color)
     self.particle.draw(self.win)
     self.drawn = True