Ejemplo n.º 1
1
def main():
    ## create compound yellow/blue turtleshape for planets
    global s
    s = Screen()
    s.setup(1120,840)
    s.reset()
    s.tracer(0, 0)
    t = Turtle()
    t.ht()
    t.pu()
    t.fd(6)
    t.lt(90)

    t.begin_poly()
    t.circle(6, 180)
    t.end_poly()
    m1 = t.get_poly()

    t.begin_poly()
    t.circle(6,180)
    t.end_poly()
    m2 = t.get_poly()

    planetshape = Shape("compound")
    planetshape.addcomponent(m1,"orange")
    planetshape.addcomponent(m2,"blue")
    s.register_shape("planet", planetshape)
    #s.tracer(1,0)
    s.update()
    ## setup gravitational system
    gs = GravSys()
    sun = Star(1000000, Vec(-250,0), Vec(0,-0.35), gs, "circle")
    sun.color("yellow")
    sun.pensize(1.8)
    sun.pu()
    earth = Star(5000, Vec(450,0), Vec(0,70), gs, "planet")
    earth.pencolor("green")
    earth.shapesize(0.8)

    rm=12.0583
    vm=(8.0*5000/rm)**.5
    moon = Star(1, Vec(450+rm,0), Vec(0,70+vm), gs, "planet")
    moon.pencolor("blue")
    moon.shapesize(0.5)
    gs.init()
    gs.start()
    return "Done!"
Ejemplo n.º 2
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()
Ejemplo n.º 3
0
def drawCircle(n):
    pen = Turtle()
    pen.speed(0)
    pen.color('blue')
    for x in range(n):
        pen.circle(50)
        pen.left(360 / n)
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))
Ejemplo n.º 5
0
def draw_spirograph(drawer: Turtle):
    drawer.speed(0)
    drawer.width(2)
    for _ in range(0, 360, 5):
        drawer.setheading(_)
        drawer.color(random_hex_color_code())
        drawer.circle(100)
Ejemplo n.º 6
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()
Ejemplo n.º 7
0
class KeysMouseEvents:
    def __init__(self):
        super().__init__()
        self.T = Turtle()
        self.screen = self.T.getscreen()
        self.screen.onkey(self.clear, "c")
        self.screen.onkey(self.quit, "q")
        self.screen.onclick(self.draw_fig)
        self.screen.listen()

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

    @staticmethod
    def quit():
        sys.exit(0)

    def draw_fig(self, x, y):
        print(x, y)
        self.T.goto(x, y)
        self.T.circle(20)

    def main(self):
        mainloop()
Ejemplo n.º 8
0
class Ponteiro:
    def __init__(self, nome: str):
        self._nome = nome
        self._desenho = Turtle()
        self._desenho.speed('fastest')
        self._desenho.color("white")
        self._desenho.setheading(90)
        self._definir_forma()
        self._eixo_de_giro = 0

    def _definir_forma(self):
        if self._nome == "segundos":
            tela.register_shape(self._nome,
                                ((-2, 0), (-2, 235), (2, 235), (2, 0)))
            self._desenho.color('red')
            self._desenho.shape(self._nome)

        elif self._nome == "minutos":
            tela.register_shape(self._nome,
                                ((-2, 0), (-2, 235), (2, 235), (2, 0)))
            self._desenho.shape(self._nome)

        elif self._nome == "horas":
            tela.register_shape(self._nome,
                                ((-2, 0), (-2, 150), (2, 150), (2, 0)))
            self._desenho.shape(self._nome)

    def girar(self, angulo: float):
        self._desenho.circle(self._eixo_de_giro, angulo * (-1))

        tela.update()
Ejemplo n.º 9
0
def main():
    s = Turtle()
    s.reset()
    s.getscreen().tracer(0, 0)
    s.ht()
    s.pu()
    s.fd(6)
    s.lt(90)
    s.begin_poly()
    s.circle(6, 180)
    s.end_poly()
    m1 = s.get_poly()
    s.begin_poly()
    s.circle(6, 180)
    s.end_poly()
    m2 = s.get_poly()
    planetshape = Shape('compound')
    planetshape.addcomponent(m1, 'orange')
    planetshape.addcomponent(m2, 'blue')
    s.getscreen().register_shape('planet', planetshape)
    s.getscreen().tracer(1, 0)
    gs = GravSys()
    sun = Star(1000000, Vec(0, 0), Vec(0, -2.5), gs, 'circle')
    sun.color('yellow')
    sun.shapesize(1.8)
    sun.pu()
    earth = Star(12500, Vec(210, 0), Vec(0, 195), gs, 'planet')
    earth.pencolor('green')
    earth.shapesize(0.8)
    moon = Star(1, Vec(220, 0), Vec(0, 295), gs, 'planet')
    moon.pencolor('blue')
    moon.shapesize(0.5)
    gs.init()
    gs.start()
    return 'Done!'
Ejemplo n.º 10
0
def main():
    global screen, red, green, blue
    screen = Screen()
    screen.delay(0)
    screen.setworldcoordinates(-1, -0.3, 3, 1.3)

    #red = ColorTurtle(0, .5)
    #green = ColorTurtle(1, .5)
    #blue = ColorTurtle(2, .5)
    setbgcolor()

    writer = Turtle()
    writer.ht()
    writer.pu()
    writer.goto(1, 0.3)

    #writer.write("DRAG!",align="center",font=("Arial",30,("bold","italic")))

    #writer.write("我们毕业了!", align="center", font=("微软雅黑", 40, "bold"))
    writer.write("我们毕业了!", align="center", font=("宋体", 40, "bold"))

    writer.goto(1, 0.5)
    writer.write("我们毕业了!", align="center", font=("微软雅黑", 40, "bold"))

    writer.goto(1, 0.7)
    writer.write("我们毕业了!", align="center", font=("楷体", 40, "bold"))

    writer.pendown()
    writer.goto(0, 0)
    writer.color("red")
    writer.circle(2, 360)
    return "EVENTLOOP"
Ejemplo n.º 11
0
def draw_arm(vrinda: Turtle, x: int, y: int) -> None:
    vrinda.speed(100)
    vrinda.penup()
    vrinda.goto(x + 220, y + 21)
    vrinda.setheading(30)
    vrinda.pendown()
    vrinda.circle(30, 20)
    vrinda.forward(60)
    return
Ejemplo 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
Ejemplo n.º 13
0
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()  # Erase the screen
        self.turtle.goto(self.x, self.y)
        self.turtle.down()
        # self.turtle.begin_fill()
        self.turtle.circle(25)
        # self.turtle.end_fill()
        bubbleName = "Frank"
        self.turtle.write("Hello!", font=("Arial", 72, "normal"))
        # self.turtle.write(bubbleName, font=("Arial", 36, "normal"), align="center")
        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
Ejemplo n.º 14
0
 def ShapeO():
     from turtle import Turtle, Screen, done
     from time import sleep
     Screen().clear()
     t = Turtle()
     t.hideturtle()
     t.circle(100)
     sleep(1)
     test()
     done()
Ejemplo n.º 15
0
 def ShapeC():
     from turtle import Turtle, Screen, done
     from time import sleep
     Screen().clear()
     t = Turtle()
     t.hideturtle()
     t.left(180)
     t.circle(100, extent=180)
     sleep(1)
     test()
     done()
Ejemplo n.º 16
0
def Spriograph():
    r = 5
    t=Turtle()
    s= Screen()
    t.speed(11)
    for _ in range(int(360/r)):
        t.circle(100)
        t._rotate(r)
        t.pencolor(random.random(),random.random(),random.random())
        t.circle(100)
        r +=1
    s.exitonclick()
Ejemplo n.º 17
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
Ejemplo n.º 18
0
 def ShapeS():
     from turtle import Turtle, Screen, done
     from time import sleep
     Screen().clear()
     t = Turtle()
     t.hideturtle()
     t.right(180)
     t.circle(50, extent=180)
     t.right(180)
     t.circle(50, extent=-270)
     sleep(1)
     test()
     done()
Ejemplo n.º 19
0
 def ShapeP():
     from turtle import Turtle, Screen, done
     from time import sleep
     Screen().clear()
     t = Turtle()
     t.hideturtle()
     t.left(90)
     t.forward(200)
     t.right(-90)
     t.circle(50, extent=-180)
     sleep(1)
     test()
     done()
Ejemplo n.º 20
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()
Ejemplo n.º 21
0
def draw_neck(vrinda: Turtle, x: int, y: int) -> None:
    vrinda.speed(100)
    vrinda.penup()  # neck1
    vrinda.goto(x + 91, y + 142)
    vrinda.pendown()
    vrinda.setheading(60)
    vrinda.circle(30, 45)
    vrinda.penup()  # neck2
    vrinda.goto(x + 131, y + 142)
    vrinda.pendown()
    vrinda.setheading(300)
    vrinda.circle(30, -45)

    return
Ejemplo n.º 22
0
def draw_pelvis(vrinda: Turtle, x: int, y: int) -> None:
    vrinda.speed(100)
    vrinda.penup()  # long line
    vrinda.goto(x + 95, y + -30)
    vrinda.pendown()
    vrinda.setheading(120)
    vrinda.circle(200, -20)
    vrinda.hideturtle()
    vrinda.penup()  # short line
    vrinda.goto(x + 110, y + -60)
    vrinda.pendown()
    vrinda.setheading(243)
    vrinda.circle(200, -10)
    return
Ejemplo n.º 23
0
def main():

    turtle = Turtle()
    screen = Screen()

    turtle.speed(20)
    angle = 0
    while angle != 360:
        turtle.pencolor((random.random(), random.random(), random.random()))
        turtle.setheading(angle)
        turtle.circle(80)
        angle += 5

    screen.exitonclick()
Ejemplo n.º 24
0
def petal(m, t: turtle.Turtle):
    for i in range(m):
        a = 200 - 400 * random.random()
        b = 10 - 20 * random.random()
        t.up()
        t.forward(b)
        t.left(90)
        t.forward(a)
        t.down()
        t.color('pink')
        t.circle(1)
        t.up()
        t.backward(a)
        t.right(90)
        t.backward(b)
Ejemplo n.º 25
0
 def _render(self):
     """Отрисовывает круглый контур циферблата и точку в центре"""
     t = Turtle()
     t.speed(0)
     t.width(self.radius // 80)
     t.up()
     t.goto((self._center[0], self._center[1] - self.radius))
     t.seth(0)
     t.down()
     t.circle(self.radius)
     t.up()
     t.goto((self._center[0], self._center[1]))
     t.down()
     t.dot(self.radius / 15)
     t.hideturtle()
Ejemplo n.º 26
0
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
Ejemplo n.º 27
0
 def ShapeQ():
     from turtle import Turtle, Screen, done
     from time import sleep
     Screen().clear()
     t = Turtle()
     t.hideturtle()
     t.circle(100)
     t.up()
     t.right(-45)
     t.forward(50)
     t.down()
     t.left(90)
     t.back(150)
     sleep(1)
     test()
     done()
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
Ejemplo n.º 29
0
def main():
    ## create compound yellow/blue turtleshape for planets
    global s
    s = Screen()
    s.setup(1120, 840)
    s.reset()
    s.tracer(0, 0)
    t = Turtle()
    t.ht()
    t.pu()
    t.fd(6)
    t.lt(90)

    t.begin_poly()
    t.circle(6, 180)
    t.end_poly()
    m1 = t.get_poly()

    t.begin_poly()
    t.circle(6, 180)
    t.end_poly()
    m2 = t.get_poly()

    planetshape = Shape("compound")
    planetshape.addcomponent(m1, "orange")
    planetshape.addcomponent(m2, "blue")
    s.register_shape("planet", planetshape)
    s.update()
    ## setup gravitational system
    gs = GravSys()
    sun = Star(1000000, Vec(-250, 0), Vec(0, -0.35), gs, "circle")
    sun.color("yellow")
    sun.pensize(1.8)
    sun.pu()
    earth = Star(5000, Vec(450, 0), Vec(0, 70), gs, "planet")
    earth.pencolor("green")
    earth.shapesize(0.8)

    rm = 12.0583
    vm = (8.0 * 5000 / rm)**.5
    moon = Star(1, Vec(450 + rm, 0), Vec(0, 70 + vm), gs, "planet")
    moon.pencolor("blue")
    moon.shapesize(0.5)
    gs.init()
    gs.start()
    s.tracer(True)
    return "Done!"
Ejemplo 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
Ejemplo n.º 31
0
def create_raise_sector_shape(shape_name, radius, extent, width=10):
    tmp = Turtle()
    tmp.hideturtle()
    tmp.setheading(90)
    tmp.begin_poly()
    tmp.circle(radius, extent=extent)
    tmp.end_poly()
    p1 = tmp.get_poly()
    tmp.reset()
    tmp.setheading(90)
    tmp.setx(-width)
    tmp.begin_poly()
    tmp.circle(radius - width, extent=extent)
    tmp.end_poly()
    p2 = tmp.get_poly()
    tmp.reset()
    p3 = p1 + p2[::-1]
    screen.register_shape(shape_name, p3)
Ejemplo n.º 32
0
def draw_square():
    window = Turtle().screen
    window.bgcolor('red')
    turtle = Turtle()
    turtle.shape('turtle')
    turtle.speed(50)
    turtle.color('blue')

    for x in range(0, 180):
        for j in range(1, 5):
            turtle.forward(100)
            turtle.right(90)
        turtle.right(2)

    turtle_circle = Turtle()
    turtle_circle.shape('arrow')
    turtle_circle.circle(100)

    window.exitonclick()
Ejemplo n.º 33
0
def createPlanetShape():
    s.tracer(0,0)
    t = Turtle()
    t.ht()
    t.pu()
    t.fd(6)
    t.lt(90)
    t.begin_poly()
    t.circle(6, 180)
    t.end_poly()
    m1 = t.get_poly()
    t.begin_poly()
    t.circle(6,180)
    t.end_poly()
    m2 = t.get_poly()

    planetshape = Shape("compound")
    planetshape.addcomponent(m1,"orange")
    planetshape.addcomponent(m2,"blue")
    s.register_shape("planet", planetshape)
    s.tracer(True,0)
def main():
	# creating a window
	window = Screen()
	# window.bgcolor("orange")

	remo = Turtle()
	remo.shape("turtle")
	remo.color("green")
	remo.speed(50)

	for i in range(36):
		remo.circle(100)
		remo.left(10)

	remo.color("red")

	for i in range(36):
		remo.circle(80)
		remo.left(10)

	remo.color("yellow")

	for i in range(36):
		remo.circle(60)
		remo.left(10)


	window.exitonclick()
Ejemplo n.º 35
0
def draw_olympics_logo(turtle: Turtle, radius: int) -> None:
    x_coord = -radius * 3
    x_subtract = radius + 20
    colors = ['blue', 'yellow', 'red', 'green', 'black']

    for i in range(0, len(colors), 2):
        turtle.penup()
        turtle.setpos(x_coord, 0)
        turtle.pendown()
        turtle.color(colors[i])
        turtle.circle(radius)

        x_coord += x_subtract

        if i + 1 != len(colors):
            turtle.penup()
            turtle.setpos(x_coord, -radius)
            turtle.pendown()
            turtle.color(colors[i + 1])
            turtle.circle(radius)

            x_coord += x_subtract
Ejemplo n.º 36
0
def main():
    s = Turtle()
    s.reset()
    s.getscreen().tracer(0,0)
    s.ht()
    s.pu()
    s.fd(6)
    s.lt(90)
    s.begin_poly()
    s.circle(6, 180)
    s.end_poly()
    m1 = s.get_poly()
    s.begin_poly()
    s.circle(6,180)
    s.end_poly()
    m2 = s.get_poly()

    planetshape = Shape("compound")
    planetshape.addcomponent(m1,"orange")
    planetshape.addcomponent(m2,"blue")
    s.getscreen().register_shape("planet", planetshape)
    s.getscreen().tracer(1,0)

    ## setup gravitational system
    gs = GravSys()
    sun = Star(1000000, Vec(0,0), Vec(0,-2.5), gs, "circle")
    sun.color("yellow")
    sun.shapesize(1.8)
    sun.pu()
    earth = Star(12500, Vec(210,0), Vec(0,195), gs, "planet")
    earth.pencolor("green")
    earth.shapesize(0.8)
    moon = Star(1, Vec(220,0), Vec(0,295), gs, "planet")
    moon.pencolor("blue")
    moon.shapesize(0.5)
    gs.init()
    gs.start()
    return "Done!"
Ejemplo n.º 37
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()
Ejemplo n.º 38
0
# Set the window background color to black
window.bgcolor("black")

# Make the cursor ink white, the width of the pen 3, the shape a turtle, and 
# move at moderate speed
cursor.color("white")
cursor.width(3)
cursor.shape("turtle") # or "circle", "classic", etc.
cursor.speed(5) # 1 - 10


# Draw a square of side length 100 starting from the home position
cursor.home()
for i in range(4):
	print cursor.position()
	cursor.forward(100)
	cursor.right(90)
print cursor.position()

# Move the turtle to (0, 100) without drawing anything,
# then draw a pentagon
cursor.penup()
cursor.sety(100)
print cursor.position()
cursor.pendown()
cursor.color("green")
cursor.circle(50, steps=5) # remove ", steps=5" to make a circle

# Keep the window open until you click to close it
window.exitonclick()
Ejemplo n.º 39
0
from turtle import Turtle
t = Turtle()
t.speed(0)
for x in range(50):
    t.circle(3*x)
t.right(90)
for x in range(50):
    t.circle(3*x)
t.right(90)
for x in range(50):
    t.circle(3*x)
t.right(90)
for x in range(50):
    t.circle(3*x)
input('Press any key to continue...')
Ejemplo n.º 40
0
class ParsonTurtle(Turtle):
  def __init__(self):
    self._turtle = Turtle()
    self._turtle.shape('turtle')
    self._commands = []

  def forward(self, dist, log=True):
    self._turtle.forward(dist)
    if log:
      self._commands.append("fwd" + str(dist))
  def fd(self, dist, log=True):
    return self.forward(dist, log=log)


  def backward(self, dist, log=True):
    self._turtle.backward(dist)
    if log:
      self._commands.append("bwd" + str(dist))
  def back(self, dist, log=True):
    return self.backward(dist, log=log)
  def bk(self, dist, log=True):
    return self.backward(dist, log=log)

  def left(self, angle, log=True):
    self._turtle.left(angle)
    if log:
      self._commands.append("lt" + str(angle))
  def lt(self, angle, log=True):
    return self.left(angle, log=log)

  def right(self, angle, log=True):
    self._turtle.right(angle)
    if log:
      self._commands.append("rt" + str(angle))
  def rt(self, angle, log=True):
    return self.right(angle, log=log)

  def goto(self, nx, ny, log=True):
    self._turtle.goto(nx, ny)
    if log:
      self._commands.append("gt" + str(nx) + "-" + str(ny))

  def setposition(self, nx, ny, log=True):
    self._turtle.setposition(nx, ny)
    if log:
      self._commands.append("setpos" + str(nx) + "-" + str(ny))
  def setpos(self, nx, ny, log=True):
    return self.setposition(nx, ny, log=log)

  def setx(self, nx, log=True):
    self._turtle.setx(nx)
    if log:
      self._commands.append("setx" + str(nx))

  def sety(self, ny, log=True):
    self._turtle.sety(ny)
    if log:
      self._commands.append("sety" + str(ny))

  def dot(self, size, color, log=True):
    self._turtle.dot(size, color)
    if log:
      self._commands.append("dot" + str(size) + "-" + str(color))

  def circle(self, radius, extent, log=True):
    self._turtle.circle(radius, extent)
    if log:
      self._commands.append("circle" + str(radius) + "-" + str(extent))

  def up(self, log=True):
    self._turtle.up()
    if log:
      self._commands.append("up")
  def penup(self, log=True):
    return self.up(log=log)
  def pu(self, log=True):
    return self.up(log=log)

  def down(self, log=True):
    self._turtle.down()
    if log:
      self._commands.append("down")
  def pendown(self, log=True):
    return self.down(log=log)
  def pd(self, log=True):
    return self.down(log=log)

  def speed(self, spd):
    self._turtle.speed(spd)

  def _logColorChange(self, command, color, green, blue):
    if blue is not None:
      self._commands.append("%s(%d, %d, %d)"%(command, color, green, blue))
    else:
      self._commands.append("%s(%s)"%(command, color))

  def pencolor(self, color, green=None, blue=None, log=True):
    if blue is not None:
      self._turtle.pencolor(color, green, blue)
    else:
      self._turtle.pencolor(color)
    if log:
      self._logColorChange("pcolor", color, green, blue)

  def color(self, color, green=None, blue=None, log=True):
    if blue is not None:
      self._turtle.color(color, green, blue)
    else:
      self._turtle.color(color)
    if log:
      self._logColorChange("color", color, green, blue)

  def fillcolor(self, color, green=None, blue=None, log=True):
    if blue is not None:
      self._turtle.fillcolor(color, green, blue)
    else:
      self._turtle.fillcolor(color)
    if log:
      self._logColorChange("fcolor", color, green, blue)

  def width(self, size, log=True):
    self._turtle.pensize(size)
    if log:
      self._commands.append("width%d"%size)
  def pensize(self, size, log=True):
    return self.width(size, log=log)

  def commands(self):
    return ':'.join(self._commands)
from turtle import Turtle
t = Turtle()
t.speed(0)
a = 180
b = 180
for i in range(100):
    t.circle(i,a)
    t.right(b)
    t.circle(i,a)
    t.right(b)
    t.circle(i,a)
    t.right(b)
    t.circle(i,a)
input('Press any key to continue...')
Ejemplo n.º 42
0
class KeysMouseEvents:
	def __init__(self):
		super().__init__()
		global arg
		turtle.setup(width=600,height=400,startx=300,starty=200)
		self.T=Turtle()
		self.screen=self.T.getscreen()
		self.T.pensize(4)
		self.T.color("blue")
		if arg == '1':
			self.screen.onclick(self.drawcir)
		if arg == '2':
			self.screen.onclick(self.drawrec)
		if arg == '3':
			self.screen.onclick(self.drawtri)


		self.screen.listen()
		self.count=0
		self.first=(0,0)
		self.T.hideturtle()
		self.T.up()
		
	def drawcir(self,x,y):
		self.count = (self.count + 1) 
		if self.count == 1:
			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
			radious = math.sqrt (d);
			self.T.goto(self.firstx, self.firsty-radious)
			self.T.down()
			self.T.circle(radious)
			self.T.up()
			self.count=0

	def drawrec(self,x,y):
		self.count = (self.count + 1) 
		if self.count == 1:
			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
			self.T.goto(x,y)
			self.T.down()
			self.T.dot()
			self.T.up()
			self.count=0
			if ((self.secondx > self.firstx) and (self.secondy < self.firsty)):
				upperleft = (self.firstx, self.firsty)
			if ((self.secondx < self.firstx) and (self.secondy > self.firsty)):
				upperleft = (self.secondx, self.secondy)
			if ((self.secondx < self.firstx) and (self.secondy < self.firsty)):
				upperleft = (self.secondx, self.firsty)
			if ((self.secondx > self.firstx) and (self.secondy > self.firsty)):
				upperleft = (self.firstx, self.secondy)
			"""
			elif (self.secondy < self.firsty):
				upperleft = (self.firstx, self.secondy)
			elif (self.secondx < self.firstx):
				upperleft = (self.secondx, self.firsty)
			else: 
				upperleft = (self.firstx, self.firsty)
			"""
			width=abs (self.secondx - self.firstx)
			height=abs (self.secondy - self.firsty)
                        
			self.T.goto(upperleft)
			self.T.down()
			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()

	def drawtri(self,x,y):
		if self.count == 0:
			self.first=(x,y)
		if self.count < 3:
			self.T.goto(x,y)
			self.T.down()
			self.T.dot()
			self.count = (self.count + 1) 
		if self.count == 3:
			self.T.goto(self.first)
			self.T.up()
			self.count=0

	def main(self):
		mainloop()