Esempio n. 1
1
class KeysMouseEvents:
	def __init__(self):
		super().__init__()
		self.reinit()

	def reinit(self):
		self.T=Turtle()
		self.screen=self.T.getscreen()
		self.screen.onclick(self.drawcir)
		self.screen.onkey(self.clear,"c")
		self.T.pensize(5)
		self.screen.listen()
		self.count=0
		self.firstx=0
		self.firsty=0
		self.secondx=0
		self.secondy=0
		self.T.hideturtle()
		self.T.up()

	def clear(self):
		self.T.screen.clear()
		self.reinit()

	def drawcir(self,x,y):
		self.count = (self.count + 1) 
		if self.count == 1:
			self.T.color("black")
			self.firstx=x
			self.firsty=y
			self.T.goto(x,y)
			self.T.down()
			self.T.dot()
			self.T.up()
			return
		if self.count == 2:
			self.secondx=x
			self.secondy=y
			X = self.secondx - self.firstx
			Y = self.secondy - self.firsty
			d = X * X + Y * Y
			
			self.T.color("black")
			
			radius = math.sqrt (d);
			len = math.sqrt (2*radius*radius)
			a = len/2
			b = math.sqrt((radius*radius)-(a*a))
			self.T.goto(self.firstx-radius, self.firsty+radius)
			self.T.down()
			width = 2*radius
			height = 2*radius
			self.T.speed(0)
			self.T.forward(width)
			self.T.right(90)
			self.T.forward(height)
			self.T.right(90)
			self.T.forward(width)
			self.T.right(90)
			self.T.forward(height)
			self.T.right(90)
			self.T.up()

			x = random.randint(1, 7)
			c = x
			if c == 1:
				self.T.color("red")
			if c == 2:
				self.T.color("green")
			if c == 3:
				self.T.color("blue")
			if c == 4:
				self.T.color("yellow")
			if c == 5:
				self.T.color("white")
			if c == 6:
				self.T.color("pink")
			if c == 7:
				self.T.color("brown")
			if c == 8:
				self.T.color("purple")
			if c == 9:
				self.T.color("gray")
			if c == 10:
				self.T.color("orange")
			self.T.begin_fill()
			radius1=radius-4
			self.T.goto(self.firstx-radius1, self.firsty+radius1)
			self.T.down()
			width = 2*radius1
			height = 2*radius1
			self.T.speed(0)
			self.T.forward(width)
			self.T.right(90)
			self.T.forward(height)
			self.T.right(90)
			self.T.forward(width)
			self.T.right(90)
			self.T.forward(height)
			self.T.right(90)
			self.T.up()
			self.T.end_fill()
			self.T.up()
			self.T.color("black")
			self.T.goto(self.firstx, self.firsty-radius)
			self.T.down()
			self.T.circle(radius)
			self.T.up()

			c = x+1
			if c == 1:
				self.T.color("red")
			if c == 2:
				self.T.color("green")
			if c == 3:
				self.T.color("blue")
			if c == 4:
				self.T.color("yellow")
			if c == 5:
				self.T.color("white")
			if c == 6:
				self.T.color("pink")
			if c == 7:
				self.T.color("brown")
			if c == 8:
				self.T.color("purple")
			if c == 9:
				self.T.color("gray")
			if c == 10:
				self.T.color("orange")

			self.T.begin_fill()
			radius=radius-4
			self.T.goto(self.firstx, self.firsty-radius)
			self.T.speed(0)
			self.T.down()
			self.T.circle(radius)
			self.T.end_fill()
			self.T.up()
			self.T.color("black")
			self.T.goto(self.firstx-b, self.firsty+b)
			self.T.down()
			width = 2*b
			height = 2*b
			self.T.forward(width)
			self.T.right(90)
			self.T.forward(height)
			self.T.right(90)
			self.T.forward(width)
			self.T.right(90)
			self.T.forward(height)
			self.T.right(90)
			self.T.up()
			c = x+2
			if c == 1:
				self.T.color("red")
			if c == 2:
				self.T.color("green")
			if c == 3:
				self.T.color("blue")
			if c == 4:
				self.T.color("yellow")
			if c == 5:
				self.T.color("white")
			if c == 6:
				self.T.color("pink")
			if c == 7:
				self.T.color("brown")
			if c == 8:
				self.T.color("purple")
			if c == 9:
				self.T.color("gray")
			if c == 10:
				self.T.color("orange")
			self.T.begin_fill()
			b1=b-4
			self.T.goto(self.firstx-b1, self.firsty+b1)
			self.T.down()
			width = 2*b1
			height = 2*b1
			self.T.speed(0)
			self.T.forward(width)
			self.T.right(90)
			self.T.forward(height)
			self.T.right(90)
			self.T.forward(width)
			self.T.right(90)
			self.T.forward(height)
			self.T.right(90)
			self.T.up()
			self.T.end_fill()
			self.T.up()
			self.T.color("black")
			self.T.goto(self.firstx,self.firsty)
			self.T.down()
			self.T.dot()
			self.T.up()

			self.count=0
	def main(self):
		mainloop()
Esempio n. 2
0
def app() -> None:

    int_list = process_input()
    print("Drawing chart, take a look at the window.")

    cursor = Turtle()
    cursor.penup()
    cursor.goto(START_X, START_Y)
    cursor.pendown()
    cursor.right(90)
    cursor.showturtle()

    for index in range(len(int_list)):
        data = int_list[index]
        color = BG_COLORS[index % len(BG_COLORS)]

        cursor.fillcolor(color)
        cursor.begin_fill()

        cursor.left(180)
        cursor.forward(data)
        cursor.write(f"{data}")
        cursor.right(90)
        cursor.forward(BAR_WIDTH)
        cursor.right(90)
        cursor.forward(data)

        cursor.end_fill()

    screen.mainloop()
def draw_square(obj: Turtle, size=10) -> None:
    obj.color("red", "yellow")
    obj.begin_fill()
    for _ in range(4):
        obj.forward(size)
        obj.left(90)
    obj.end_fill()
Esempio n. 4
0
def cubeB(
    startx, starty, colno
):  #different one for going down as otherwise the top will cover the above cube
    c = Turtle()
    c.penup()
    c.hideturtle()
    c.goto(startx, starty)
    c.speed(0)
    c.left(30)

    c.color(colours[colno])
    c.begin_fill()
    c.forward(50)
    c.left(60)
    c.forward(50)
    c.left(120)
    c.forward(50)
    c.left(60)
    c.forward(50)
    c.end_fill()

    c.color(colours3[colno])
    c.begin_fill()
    c.right(120)
    c.forward(50)
    c.right(60)
    c.forward(50)
    c.right(120)
    c.forward(50)
    c.right(60)
    c.forward(50)
    c.end_fill()
Esempio n. 5
0
def draw_background(vrinda: Turtle, x: int, y: int, move: int,
                    counter: int) -> None:
    """Fills in the background, customized by color."""
    # if r < 1 or r > 254:
    # r = 204
    # if g < 1 or g > 254:
    #   g = 102
    # if b < 1 or b > 254:
    #b = 153
    r: int = random.randint(1, 255)
    g: int = random.randint(1, 255)
    b: int = random.randint(1, 255)
    if counter > 0:
        vrinda.speed(100)
        vrinda.penup()
        vrinda.goto(x, y)
        vrinda.setheading(0.0)
        vrinda.pendown()
        vrinda.pencolor(r, g, b)
        vrinda.fillcolor(r, g, b)
        vrinda.begin_fill()
        vrinda.forward(move)
        vrinda.left(90)
        vrinda.forward(2000)
        vrinda.left(90)
        vrinda.forward(move)
        vrinda.left(90)
        vrinda.forward(2000)
        vrinda.end_fill()
        vrinda.hideturtle()
        draw_background(vrinda, x + move, y, move, counter - 1)
    else:
        return
def play():
    bullets_turtle= Turtle()
    window= Tk()
    window.withdraw()
    confirmation= True
    while confirmation:
        bullets_turtle.clear()
        bullets_turtle.speed(0)
        bullets_turtle.hideturtle()
        shots_to_fire = simpledialog.askinteger(title="", prompt="How many shots you want to fire:")
        points = 0
        for i in range(shots_to_fire):
            x, y = randint(-285,285), randint(-285,285)
            
            goTo(bullets_turtle, x,y-5)
            bullets_turtle.pensize(3)
            bullets_turtle.pencolor("black")

            bullets_turtle.begin_fill()
            bullets_turtle.fillcolor("white")
            bullets_turtle.circle(10)
            bullets_turtle.end_fill()

            dist_cent= sqrt(x**2+y**2)
            if (dist_cent<=75): points+=50
            elif (dist_cent<=135): points+=25
            elif (dist_cent<=195): points+=15
            elif (dist_cent<=255): points+=5
            
        confirmation = messagebox.askyesno(title='Results', message='Congratulations! You scored {} points.\nDo you want to shoot again?'.format(points))
Esempio n. 7
0
def rect(p, c="gray"):
    tur = Turtle()

    # setters
    tur.ht()
    tur.up()
    tur.speed(0)

    x = p[0] * s
    y = p[1] * -s

    # continue
    tur.fillcolor(c)

    # position
    tur.goto(x - s / 2, y - s / 2)

    # fill rec
    tur.begin_fill()

    tur.setx(x + s / 2)
    tur.sety(y + s / 2)
    tur.setx(x - s / 2)
    tur.sety(y - s / 2)
    tur.end_fill()
    screen.update()
    return x, y
Esempio n. 8
0
class Circle(object):
    def __init__(self,
                 radius,
                 x=0,
                 y=0,
                 color='white'):  # set default to white
        self.radius = radius
        self.location = (x, y)
        self.turtle = Turtle()
        self.color = color

    def area(self):  # method for area
        return pi * (self.radius**2)

    def perimeter(self):  # method for perimeter
        return 2 * pi * self.radius

    def x_coord(self):  # method for x coord
        return self.location[0]

    def y_coord(self):  # method for y coord
        return self.location[1]

    def center(self):  # method for x and y coords
        return (self.x_coord, self.y_coord)

    def render(self):  # method for turtle plotting
        self.turtle.clear()
        self.turtle.penup()
        self.turtle.setposition(self.location)
        self.turtle.color(self.color)
        self.turtle.pendown()
        self.turtle.begin_fill()
        self.turtle.circle(self.radius)
        self.turtle.end_fill()
Esempio n. 9
0
def rect(p):
    tur = Turtle()

    # setters
    tur.ht()
    tur.up()
    tur.speed(0)
    for i in p:
        if i[2] in (" ", "0"): continue
        x = i[0]
        y = i[1]

        # continue
        tur.fillcolor(getColor(i[2]))

        # position
        tur.goto(x - s / 2, y - s / 2)

        # fill rec
        tur.begin_fill()

        tur.setx(x + s / 2)
        tur.sety(y + s / 2)
        tur.setx(x - s / 2)
        tur.sety(y - s / 2)
        tur.end_fill()
    screen.update()
Esempio n. 10
0
def draw_table(dimension: int, side: int, turtle: Turtle, x_coord: int, y_coord: int) -> None:
    fill = False

    for i in range(dimension ** 2):
        if i % dimension == 0:
            y_coord -= side
            turtle.penup()
            turtle.setpos(x_coord, y_coord)
            turtle.pendown()
            fill = fill != (dimension % 2 == 0)

        if fill:
            turtle.begin_fill()

        for _ in range(4):
            turtle.forward(side)
            turtle.right(90)

        if turtle.filling():
            turtle.end_fill()

        turtle.forward(side)

        fill = not fill

    done()
def draw_circle(obj: Turtle, size=1) -> None:
    obj.color("DeepSkyBlue", "DeepPink")
    radius = round(sqrt((360 * size) / pi), 2)
    print(f"Radius of a circle is: {radius}")
    obj.begin_fill()
    for _ in range(360):
        obj.forward(size)
        obj.left(1)
    obj.end_fill()
Esempio n. 12
0
 def filled_circle(bob: turtle.Turtle, color, size, angle):
     """Create a filled up circle"""
     bob.fillcolor(color)  # set fill color
     bob.begin_fill()  # start filling
     if angle == 360:  # if the angle is a full circle
         bob.circle(size)  # make circle with set size
     else:
         bob.circle(size, angle)  # create circle with set size and angle
     bob.end_fill()  # finish filling
Esempio n. 13
0
def draw(dict, myPen, mean, stddev):

    xList = list(dict.keys())
    maxX = max(xList)
    print(maxX)
    yList = list(dict.values())
    maxY = max(yList)
    xList.sort()
    myPen = Turtle()
    win = myPen.getscreen()
    win.setworldcoordinates(-1, -1, maxX + 1, maxY + 1)  # 设定坐标系大小
    myPen.hideturtle()  # 隐藏光标形状
    #画X轴
    myPen.up()
    myPen.goto(0, 0)
    myPen.down()
    myPen.goto(maxX, 0)
    myPen.up()
    myPen.goto(0, 0)
    myPen.down()
    myPen.goto(0, maxY)
    #画Y轴和最大,最小两个数值
    myPen.up()
    myPen.goto(-0.1, 0)
    myPen.write("0")
    myPen.goto(-0.1, maxY)
    myPen.write(str(maxY))
    xList = list(dict.keys())
    xList.sort()
    for i in range(1, xList[-1] + 1):
        myPen.goto(i + 0.15, -0.2)
        myPen.write(str(i))  # 写数字
        myPen.goto(i, 0)
        myPen.down()
        if i in dict:
            myPen.begin_fill()
            myPen.goto(i, dict[i])  # 画线
            myPen.goto(i + 0.3, dict[i])
            myPen.goto(i + 0.3, 0)
            myPen.end_fill()
        myPen.up()
    myPen.color('red')
    myPen.goto(mean, 0)
    myPen.down()
    myPen.goto(mean, maxY)
    myPen.up()
    myPen.color('blue')
    myPen.goto(mean - stddev, 0)
    myPen.down()
    myPen.goto(mean - stddev, maxY)
    myPen.up()
    myPen.goto(mean + stddev, 0)
    myPen.down()
    myPen.goto(mean + stddev, maxY)
    myPen.up()
    win.mainloop()
def draw_rectangle(obj: Turtle, side_a=20, side_b=10) -> None:
    obj.color("red", "blue")
    obj.begin_fill()
    for i in range(4):
        if i == 0 or i % 2 == 0:
            obj.forward(side_a)
        else:
            obj.forward(side_b)
        obj.left(90)
    obj.end_fill()
def draw_sierpinski_triangle(points: list, color: str, turtle: Turtle):
    turtle.fillcolor(color)
    turtle.up()
    turtle.goto(points[0])
    turtle.down()
    turtle.begin_fill()
    turtle.goto(points[1])
    turtle.goto(points[2])
    turtle.goto(points[0])
    turtle.end_fill()
Esempio n. 16
0
class Maze():
    def __init__(self, mazeFileName):

        rowsInMaze = 0
        columnsInMaze = 0
        self.mazeList = []

        mazeFile = open(mazeFileName, 'r')
        for line in mazeFile:

            rowList = []
            col = 0
            for ch in line[:-1]:

                rowList.append(ch)

                if ch == 'Q':

                    self.startRow = rowsInMaze
                    self.startCol = col
            rowsInMaze = rowsInMaze + 1
            self.mazeList.append(rowList)

            colimnsMaze = len(rowList)

        self.rowsInMaze = rowsInMaze
        self.columnsInMaze = colimnsMaze

        self.xTranslate = columnsInMaze / 2
        self.yTranslate = rowsInMaze / 2
        self.t = Turtle(shape='turtle')
        turtle.setup(width=600, height=600)
        turtle.setworldcoordinates(-(columnsInMaze - 1) / 2 - .5,
                                   -(rowsInMaze - 1) / 2 - .5,
                                   (columnsInMaze - 1) / 2 + .5,
                                   (rowsInMaze - 1) / 2 + .5)

    # 绘制屏幕
    def draw_maze(self, x, y, color):
        tracer(0)

        self.t.up()
        self.t.goto(x - 0.5, y - .5)
        self.t.color('black', color)
        self.t.heading(90)
        self.t.down
        self.t.begin_fill()
        for i in range(4):

            self.t.forward(1)
            self.t.right(90)
        self.t.end_fill()

        turtle.update()
        turtle.tracer()
def drawFiveStars():
    p = Turtle()
    p.speed(3)  #设置动画速度
    p.pensize(5)  #设置线条粗细
    p.color("black", "yellow")  # 边缘画笔颜色为黑色,用黄色填充图形
    # p.fillcolor("red")
    p.begin_fill()
    for i in range(5):  #用for循环语句完成5条线的绘制
        p.forward(200)
        p.right(144)  #五角星的每两条线段之间的折返角度为144°。。。五角星尖角每个为36°。
    p.end_fill()
Esempio n. 18
0
File: n2.py Progetto: PaulAustin/sb7
class Bubble:
    # Special name for the very first method called __init__
    def __init__(self, x, y, color1, color2):

        # Set location and direction
        self.x = x
        self.y = y
        self.dx = 0
        self.dy = 0

        # Make our own 'private' turtle for drawing
        self.turtle = Turtle()
        self.turtle.color(color1, color2)
        self.turtle.hideturtle()
        self.turtle.up()
        self.turtle.goto(self.x, self.y)
        self.turtle.width(3)

    # A method to simulate the passage of time
    def sim(self):
        # self.turtle.clear()
        self.turtle.goto(self.x, self.y)
        self.turtle.down()
        self.turtle.begin_fill()
        self.turtle.circle(25)
        self.turtle.end_fill()
        self.turtle.up()
        self.x += self.dx
        self.y += self.dy
        self.checkWalls()

    # Give the bubble a random direction
    def randomBump(self):
        dx = (random.randint(0, 7) - 3) * 8
        dy = (random.randint(0, 7) - 3) * 8
        self.bump(dx, dy)

    def bump(self, dx, dy):
        self.dx = dx
        self.dy = dy

    # Keep the bubble on the pond.
    # How could you make it a circular?
    def checkWalls(self):

        # h = math.sqrt((self.x * self.x) + (self.y * self.y))
        # if (h > 300):
        #    self.dx *= -1

        if ((self.x > 300) or (self.x < -300)):
            self.dx *= -1
        if ((self.y > 300) or (self.y < -300)):
            self.dy *= -1
Esempio n. 19
0
def draw_moon(moon: Turtle, x: float, y: float) -> None:
    """This function draws the moon in the night sky."""
    radius: int = 75
    colormode(255)
    moon.penup()
    moon.goto(x, y)
    moon.pendown()
    moon.color(220, 220, 220)
    moon.speed(FASTEST_SPEED)
    moon.begin_fill()
    moon.circle(radius)
    moon.end_fill()
    return
Esempio n. 20
0
    def fillTile(self, color):
        fillerTurtle = Turtle()
        fillerTurtle.penup()
        fillerTurtle.goto(self.cor[0] + 1, self.cor[1] - 1)

        fillerTurtle.color(color)
        fillerTurtle.begin_fill()
        for i in range(3):
            fillerTurtle.forward(self.tileSize)
            fillerTurtle.right(90)
        fillerTurtle.forward(self.tileSize)
        fillerTurtle.end_fill()
        fillerTurtle.hideturtle()
Esempio n. 21
0
def draw_moon():
    t = Turtle()
    # 画月亮
    t.up()
    t.goto(-300, 250)
    t.down()
    t.fillcolor('#ffd700')
    t.begin_fill()
    t.pencolor('#ffd700')
    t.pensize(3)
    t.circle(30)
    t.end_fill()
    t.up()
    t.hideturtle()
Esempio n. 22
0
def draw_polygon(t: turtle.Turtle, length: int, sides: int) -> None:
    for count in range(sides):
        t.forward(length)
        t.left(360 / sides)
    t.penup()
    t.goto(5, 15)
    t.pendown()
    t.fillcolor("red")
    t.begin_fill()
    for count in range(sides):
        t.forward(length - 10)
        t.left(360 / sides)
    t.end_fill()
    turtle.done()
Esempio n. 23
0
def make_sea_floor(color):
    sea_floor = Turtle()
    sea_floor.hideturtle()
    sea_floor.penup()
    sea_floor.setpos(-400, -180)
    sea_floor.color(color)
    sea_floor.begin_fill()
    sea_floor.forward(800)
    sea_floor.right(90)
    sea_floor.forward(300)
    sea_floor.right(90)
    sea_floor.forward(800)
    sea_floor.right(90)
    sea_floor.forward(300)
    sea_floor.end_fill()
Esempio n. 24
0
 def draw(self, col_L, col_F):
     length = self.R * 2 * math.sin(math.pi / self.n)
     Terry = Turtle()
     Terry.color(col_L, col_F)
     Terry.pu()
     Terry.setpos(.5 * length + self.x,
                  -(self.R**2 - (.5 * length)**2)**.5 + self.y)
     Terry.begin_fill()
     Terry.pd()
     for _ in range(0, self.n):
         Terry.left((2 / self.n) * 180)
         Terry.forward(length)
     Terry.end_fill()
     Terry.setpos(self.x, self.y)
     Terry.pu()
def major_rectangle(ito: Turtle, x: float, y: float, w: int, h: int, r: int, g: int, b: int) -> None:
    """Draws a rectangle with dimensions (w*h) starting from the bottom-left corner (x, y) with a color (r, g, b)."""
    i: int = 0
    ito.color(r, g, b)
    ito.penup()
    ito.goto(x, y)
    ito.pendown()
    ito.begin_fill()
    while i < 2:
        ito.forward(w)
        ito.left(90)
        ito.forward(h)
        ito.left(90)
        i += 1
    ito.end_fill()
Esempio n. 26
0
class VolumeBar():
    def __init__(self, pos, maximum, screen):
        self.bar = Turtle()
        self.fill = Turtle()
        self.bar_hypo = 100
        self.pencolor = "black"
        self.pensize = 1
        self.pos = pos
        self.maximum = maximum
        self.s = screen

    def draw_volume_bar(self):
        self.bar.hideturtle()
        self.s.tracer(False)
        self.bar.pencolor(self.pencolor)
        self.bar.pensize(self.pensize)
        self.bar.penup()
        self.bar.goto(self.pos)
        self.bar.pendown()
        self.bar.left(10)
        self.bar.fd(self.bar_hypo)
        self.bar.right(100)
        self.bar.fd(self.maximum)
        self.bar.right(90)
        self.bar.goto(self.pos)
        self.s.tracer(True)

    def fill_volume_bar(self, percent=None):
        self.fill.hideturtle()
        self.fill.clear()
        self.s.tracer(False)
        forward = self.bar_hypo * percent
        down = self.maximum * percent
        self.fill.pencolor(self.pencolor)
        self.fill.fillcolor(self.pencolor)
        self.fill.penup()
        self.fill.goto(self.pos)
        self.fill.pendown()
        self.fill.begin_fill()
        self.fill.left(10)
        self.fill.fd(forward)
        self.fill.right(100)
        self.fill.fd(down)
        self.fill.right(90)
        self.fill.goto(self.pos)
        self.fill.right(180)
        self.fill.end_fill()
        self.s.tracer(True)
def cir(ito: Turtle, n: int, x: float, y: float, w: int, h: int, s: int, r: int, g: int, b: int) -> None:
    """Draws n circles.
    
    Does so at random points within a specified rectangle of dimensions (w*h) starting at (x, y) 
    in shades varying by a specified + / - range (RGBRANGECIR) from the rgb values of a color (r, g, b).
    """
    i: int = 0
    while i < n:
        ito.penup()
        ito.goto(randint(int(x), int(x + w)), randint(int(y), int(y + h)))
        ito.pendown()
        ito.begin_fill()
        ito.color(actual_rgb(r, RGBRANGECIR), actual_rgb(g, RGBRANGECIR), actual_rgb(b, RGBRANGECIR))
        ito.circle(s)
        ito.end_fill()
        i = i + 1
Esempio n. 28
0
def draw_sky(sky: Turtle, x: float, y: float) -> None:
    """This function makes the screen black to represent the night sky."""
    colormode(255)
    sky.penup()
    sky.goto(x, y)
    sky.pendown()
    sky.color(0, 0, 0)
    sky.speed(FASTEST_SPEED)
    sky.begin_fill()
    i: int = 0
    while (i < 4):
        sky.forward(800)
        sky.left(90)
        i = i + 1
    sky.end_fill()
    return
Esempio n. 29
0
def pieChart(flist):
    COL = ['red', 'yellow', 'blue', 'green', 'purple']
    Alist = ['A', 'E', 'I', 'O', 'U']
    total = 0
    r = 200
    R = r * 0.5
    FONTSIZE = 20
    FONT = ("Ariel", FONTSIZE, "bold")

    for i in range(0, 5):
        total += flist[i]

    pie = Turtle()
    pie.penup()
    pie.sety(-r)
    pie.pendown()

    j = 0
    k = 0
    while j <= 4:
        while k <= 4:
            pie.fillcolor(COL[j])
            pie.begin_fill()
            frac = flist[k]
            pie.circle(r, frac * 360 / total)
            pos = pie.position()
            pie.goto(0, 0)
            pie.end_fill()
            pie.setposition(pos)
            j += 1
            k += 1
    pie.penup()
    pie.sety(-R)

    l = 0
    m = 0
    while m <= 4:
        while l <= 4:
            la = Alist[m]
            frac = flist[l]
            pie.circle(R, frac * 360 / total / 2)
            pie.write(la, align='center', font=FONT)
            pie.circle(R, frac * 360 / total / 2)
            l += 1
            m += 1

    pie.hideturtle()
Esempio n. 30
0
def draw_sand(sand: Turtle, x: float, y: float) -> None:
    """This function draws the sand on the beach."""
    radius: int = 80
    shift_x_coordinate_right: int = 80
    colormode(255)
    i: int = 0
    while i < 10:
        sand.penup()
        sand.goto(x, y)
        sand.pendown()
        sand.color(222, 184, 135)
        sand.begin_fill()
        sand.speed(FASTEST_SPEED)
        sand.circle(radius)
        sand.end_fill()
        x = x + (shift_x_coordinate_right)
        i = i + 1
    return
Esempio n. 31
0
def circle(radius, d, x, y, h, w, color="black"):
    try:
        # ------ optimizing turtle -------------#
        turtle.tracer(0, 0)
        turtle.speed("fastest")
        tr = Turtle(visible=True)
        #---------------------------------------
        # this assures that the size of the image is set by user ...
        screen = turtle.Screen()
        screen.setup(h, w)
        tr.width(d)
        tr.penup()
        tr.goto(x + radius, y)
        tr.pendown()

        # color of drawing line
        tr.color("blue", color)
        tr.begin_fill()
        #-------------------------------------------------
        # Circle drawing starts here
        for i in range(1, 361):
            tr.goto(radius * cos(radians(i)) + x, radius * sin(radians(i)) + y)
        # Circle drawing ends here
        #-------------------------------------------------
        tr.end_fill()
        ts = turtle.getscreen()
        # export as eps objects
        ts.getcanvas().postscript(file="circle.eps")
        turtle.update()
        #turtle.done()
        try:
            turtle.bye()
        except turtle.Terminator:
            pass

        # convert eps into circle
        img = Image.open('circle.eps')
        img.save('circle.png', 'png')
        print("Plot generated in: ", os.getcwd())
        # remove the eps file
        os.remove("circle.eps")

    except OSError:
        pass
Esempio n. 32
0
def background_block(pos_x, pos_y):
    """Creates the background scene of green-toned bricks. Color is
       slightly altered for each brick"""
    beta = Turtle()
    beta.color((0, 51, 51))
    beta.pensize(1)
    beta.speed(0)
    beta.penup()
    beta.setpos(pos_x, pos_y)
    beta.pendown()
    beta.hideturtle()

    beta.fillcolor((0, random.randint(55, 130), random.randint(15, 50)))
    beta.begin_fill()
    for all in range(2):
        beta.forward(30)
        beta.right(90)
        beta.forward(15)
        beta.right(90)
    beta.end_fill()
Esempio n. 33
0
def draw_chess_board(t: turtle.Turtle):
    side = 40
    for k in range(4):
        for j in range(2):
            for i in range(8):
                if i % 2 == 0:
                    t.begin_fill()
                t.forward(side)
                t.left(90)
                t.forward(side)
                t.left(90)
                t.forward(side)
                t.left(90)
                t.forward(side)
                t.left(90)
                t.end_fill()
                t.forward(side)
            side = -side
        if k != 3:
            t.right(90)
            t.forward(2 * side)
            t.left(90)
    turtle.exitonclick()
Esempio n. 34
0
from turtle import Turtle as Zelva

BARVY = {1: "red", 2: "blue", 3: "white"}
POZICE = {1: (0, 0), 2: (120, 0), 3: (120, 60), 4: (0, 60)}  # Levý spodní  # Pravý spodní  # Pravý horní  # Levý hodní


if __name__ == "__main__":
    # Nakreslíme červenou vlajku
    vlajky = {}
    vlajka = (1, 2, 3, 4, 1)
    vlajky[vlajka] = "Bílá země"
    z = Zelva()
    z.speed(1)
    barva = vlajka[-1]
    z.fillcolor(BARVY[barva])  # Poslední prvek je číslo barvy
    z.color = "black"

    z.hideturtle()
    z.begin_fill()
    for bod in vlajka[:-1]:
        z.setpos(*POZICE[bod])
    z.setpos(0, 0)
    z.end_fill()
Esempio n. 35
0
    bot.color("green");
    bot.speed("slowest");
    #bot.setpos(x, y)
    #bot.st()
    bot.circle(50);
    bot.clear()
    
window = Screen();
window.bgcolor("yellow");

#draw_triangle(3, 100, 100)
#draw_square(4, 200, 200)
#draw_circle(300, 300)

# 1. don't show trutle shape.
# 2. we need to draw multiple squres (360/10 = 36 squares)
# 3. each squre we should start with different angle (10 degrees).
# 4. for each square, createa turtle and call square function.

bot = Turtle()
#bot.ht()
bot.color("blue", "green");
bot.speed("fast");
bot.begin_fill()
for i in range(0, 36):
    print (" square " + str(i * 10))
    draw_triangle(bot, 10)
bot.end_fill()

window.exitonclick()
Esempio n. 36
0
class KeysMouseEvents:
	def __init__(self):
		super().__init__()
		self.reinit()

	def reinit(self):
		self.T=Turtle()
		self.screen=self.T.getscreen()
		self.screen.onclick(self.drawcir)
		self.screen.onkey(self.clear,"c")
		self.T.pensize(5)
		self.screen.listen()
		self.count=0
		self.firstx=0
		self.firsty=0
		self.secondx=0
		self.secondy=0
		self.T.hideturtle()
		self.T.up()

	def clear(self):
		self.T.screen.clear()
		self.reinit()

		
	def drawcir(self,x,y):
		self.count = (self.count + 1) 
		if self.count == 1:
			self.T.color("black")
			self.firstx=x
			self.firsty=y
			self.T.goto(x,y)
			self.T.down()
			self.T.dot()
			self.T.up()
			return
		if self.count == 2:
			self.secondx=x
			self.secondy=y
			X = self.secondx - self.firstx
			Y = self.secondy - self.firsty
			d = X * X + Y * Y

			self.T.color("black")
			radious = math.sqrt (d);
			self.T.goto(self.firstx, self.firsty-radious)
			self.T.down()
			self.T.circle(radious)
			self.T.up()


			c = random.randint(1, 4)
			if c == 1:
				self.T.color("red")
			if c == 2:
				self.T.color("green")
			if c == 3:
				self.T.color("blue")
			if c == 4:
				self.T.color("yellow")

			self.T.begin_fill()
			radious=radious-4
			self.T.goto(self.firstx, self.firsty-radious)
			self.T.down()
			self.T.circle(radious)
			self.T.end_fill()
			self.T.up()

			self.T.color("black")
			self.T.goto(self.firstx,self.firsty)
			self.T.down()
			self.T.dot()
			self.T.up()

			self.count=0
	def main(self):
		mainloop()
Esempio n. 37
0
from turtle import Turtle
p = Turtle()
p.speed(3)
p.pensize(5)
p.color("black", 'yellow')
p.begin_fill()
for i in range(5):
    p.forward(200)
    p.right(144)
p.end_fill()