Exemple #1
1
def draw_circle(x,y):
	turtle.penup()
	turtle.goto(x,y)
	turtle.pendown()
	turtle.begin_fill()
	turtle.circle(10)
	turtle.end_fill()
Exemple #2
0
def base(color = 'blue',colors = colors, lato = lato, unit = unit, alfa = alfa, depth = depth, height = height):
    turtle.pencolor(colors[color])
    turtle.fillcolor(color)
    turtle.begin_fill()
    turtle.forward(unit*lato)
    turtle.left(alfa)
    turtle.forward(depth*lato)
    turtle.left(alfa)
    turtle.forward(height)
    turtle.left(90+alfa)
    turtle.forward(depth*lato)
    turtle.left(alfa)
    turtle.forward(height)
    turtle.backward(height)
    turtle.right(90)
    turtle.forward(lato*unit)
    turtle.left(90)
    turtle.forward(height)
    turtle.right(180)
    turtle.forward(height)
    turtle.right(alfa)
    turtle.forward(depth*lato)
    turtle.right(alfa)
    turtle.forward(lato*unit)
    turtle.left(alfa)
    turtle.backward(depth*lato)
    turtle.right(alfa)
    turtle.backward(unit*lato)
    turtle.end_fill()
    line_base()
 def cleardisk(self):
     turtle.pu()
     turtle.goto(self.x,self.y)
     turtle.pd()
     turtle.color("white","white")
     turtle.begin_fill()
     turtle.goto(self.x+(self.w/2),self.y)
     turtle.goto(self.x+(self.w/2),self.y-self.h)
     turtle.goto(self.x-(self.w/2),self.y-self.h)
     turtle.goto(self.x-(self.w/2),self.y)
     turtle.goto(self.x,self.y)
     turtle.end_fill()
     turtle.pu()
     turtle.pu()
     turtle.goto(self.x,self.y)
     turtle.pd()
     turtle.color("red","red")
     turtle.begin_fill()
     turtle.goto(self.x+(10/2),self.y)
     turtle.goto(self.x+(10/2),self.y-self.h)
     turtle.goto(self.x-(10/2),self.y-self.h)
     turtle.goto(self.x-(10/2),self.y)
     turtle.goto(self.x,self.y)
     turtle.end_fill()
     turtle.pu()
     return 0
def polygon(side = 50, angle = None, xstart = None, ystart = None, numberSides = 3, color = 'black', fill = False):
    turtle.pensize(3)
    turtle.speed('fastest')
    turtle.hideturtle()
    if angle != None:
        turtle.left(angle)
    
    turtle.penup()
    if fill == True:
        if xstart != None or ystart != None:
            turtle.goto(xstart, ystart)
        else:
            turtle.goto(0, 0)
        turtle.color(color)
        turtle.pendown()
        turtle.begin_fill()
        turtle.circle(side, 360, numberSides)
        turtle.end_fill()
        turtle.penup()
        
    else:
        turtle.goto(xstart, ystart)
        turtle.color(color)
        turtle.pendown()
        turtle.circle(side, 360, numberSides)
        turtle.penup()
    
    return
def hexagone(c, longueur,m, col1, col2, col3,deform):
    """
    Draws a hexagon with or without deformation
    """
    lo = longueur
    x,y,z = c #Hexagon centre
    pa1,pa2,pa3 = (x+lo,y,z), (x+(lo/2),y-m,z), (x-(lo/2),y-m,z)#First losange coordinates (lower right)
    pb1,pb2,pb3 = (x+lo,y,z), (x+(lo/2),y+m,z), (x-(lo/2),y+m,z)#Losange 2 (upper right)
    pc1,pc2,pc3 = (x-(lo/2),y+m,z), (x-lo,y,z), (x-(lo/2),y-m,z)#Losange 3 (left)
    pts = [pa1,pa2,pa3,c,pb1,pb2,pb3,c,pc1,pc2,pc3,c]
    d = []
    for point in pts:
        xd,yd,zd = deform(point)
        d.extend((xd,yd))
    up()
    setpos(d[6],d[7])#Turtle resets to c
    down()
    col = [col1,col2,col3]
    i = 0
    for e in col:
        color(e)
        begin_fill()
        goto(d[i],d[i+1])
        goto(d[i+2],d[i+3])
        goto(d[i+4],d[i+5])
        goto(d[i+6],d[i+7])
        end_fill()
        i += 8
def sky( x, y, scale ):
	'''draws a huge blue square given location and scale'''
	t.tracer(False)
	t.begin_fill()
	t.color('light blue')
	buildingblock(x-1000*scale, y+0*scale, 2000*scale, 1075*scale)
	t.end_fill()
def cross( x, y, scale, fill, color ):
	'''draws a cross given location, scale, and color'''
	goto( x, y )
	
	if fill == "True":
		'''if the scale is 1, and fill == True
			then this function will draw a cross 
			with its left point at (x,y) and
			will have lengths of 50 and widths of 15
			and filled with the color given'''
		t.begin_fill()
		t.color(color)
		for i in range(4):
			t.forward(50*scale)
			t.right(90)
			t.forward(50*scale)
			t.left(90)
			t.forward(15*scale)
			t.left(90)
		t.end_fill()
	else: 
		'''if the scale is 1, and fill == False
			then this function will draw a cross 
			with its left point at (x,y) and
			will have lengths of 50 and widths of 15
			and with no color fill'''
		for i in range(4):
			t.forward(50*scale)
			t.right(90)
			t.forward(50*scale)
			t.left(90)
			t.forward(15*scale)
			t.left(90)
def grass( x, y, scale ):
	'''draws a huge blue square given location and scale'''
	t.tracer(False)
	t.begin_fill()
	t.color('green')
	buildingblock(x-1000*scale, y-1000*scale, 2000*scale, 1075*scale)
	t.end_fill()
def cloud( x, y, scale, color):
	'''draws a cloud given location and scale'''
	goto( x, y )
	t.begin_fill()
	t.color(color)
	t.circle(50*scale)
	t.end_fill()
	t.begin_fill()
	t.color(color)
	t.up()
	t.forward(25*scale)
	t.down()
	t.circle(50*scale)
	t.end_fill()
	t.begin_fill()
	t.color(color)
	t.up()
	t.forward(35*scale)
	t.down()
	t.circle(50*scale)
	t.end_fill()
	t.begin_fill()
	t.color(color)
	t.up()
	t.forward(25*scale)
	t.down()
	t.circle(50*scale)
	t.end_fill()
	t.begin_fill()
	t.color(color)
	t.up()
	t.forward(25*scale)
	t.down()
	t.end_fill()
def block( x, y, width, height, fill, color ):
	goto( x, y )
	
	print 'block(): drawing block of size', width, height
	# tell the turtle to go foward by width
	# tell the turtle to turn left by 90 degrees
	# tell the turtle to go forward by height
	# tell the turtle to turn left by 90 degrees
	# repeat the above 4 commands
	
	# if the parameter fill is true then do this
	if fill == "True":
		''' draw a block at position (x,y) with the
			given width and height, and fill with 
			the color '''
		t.begin_fill()
		t.color(color)
		for i in range(2):
			t.forward(width)
			t.left(90)
			t.forward(height)
			t.left(90)	
		t.end_fill()
	# if the parameter fill is false then do this
	else:
		''' draw a block at position (x,y) with the
			given width and height, and fill with 
			the color '''
		for i in range(2):
			t.forward(width)
			t.left(90)
			t.forward(height)
			t.left(90)	
Exemple #11
0
def drawmountain(x,y,color):
	t.up
	t.goto(x,y)
	t.down
	t.color(color)
	t.begin_fill()
	t.backward(200)
	t.right(120)
	t.backward(200)
	t.right(120)
	t.backward(200)
	t.right(120)
	t.end_fill()
	t.up

	t.goto(x-75,y+125)
	t.down
	t.color("White")
	t.begin_fill()
	t.backward(50)
	t.right(120)
	t.backward(50)
	t.right(120)
	t.backward(50)
	t.right(120)
	t.end_fill()
	t.up
def star( x, y, scale, fill, color ):
	'''draws a star given location, scale, and color'''
	goto( x, y )
	
	if fill == "True":
		'''if the scale is 1, and fill == True
			then this function will draw a star 
			with its left point at (x,y) and
			will have star ray lengths of 50
			and filled with the color given'''
		t.begin_fill()
		t.color(color)
		for i in range(10):
			t.forward(50*scale)
			t.right(108)
			t.forward(50*scale)
			t.left(144)
		t.end_fill()
	else: 
		'''if the scale is 1, and fill == False
			then this function will draw a star 
			with its left point at (x,y) and
			will have star ray lengths of 50
			and with no color fill'''
		t.begin_fill()
		for i in range(10):
			t.forward(50*scale)
			t.right(108)
			t.forward(50*scale)
			t.left(144)
def pythagoras_tree(size, n):
    turtle.begin_fill()
    for _ in range(4):
        turtle.forward(size)
        turtle.left(90)

    turtle.end_fill()
    if n > 0:
        roof = .5 * math.sqrt(2) * size

        turtle.left(90)
        turtle.forward(size)
        turtle.right(45)

        pythagoras_tree(roof, n - 1)

        turtle.forward(roof)
        turtle.right(90)

        pythagoras_tree(roof, n - 1)

        turtle.left(90)
        turtle.backward(roof)
        turtle.left(45)
        turtle.backward(size)
        turtle.right(90)
Exemple #14
0
def circunferencia(simbolos,identificador,linea):
  p1= obtener_punto(2,identificador,simbolos)
  radio = obtener_radio(identificador,simbolos)
  x1 = obtener_x(p1,simbolos)
  y1 = obtener_y(p1,simbolos)
 
  escalar = obtener_escalar(identificador, simbolos,linea)
  relleno = obtener_color(obtener_relleno(identificador,simbolos,linea))
  borde = obtener_color(obtener_borde(identificador,simbolos,linea))  
  turtle.color(borde)
  if escalar == 0:
    escalar=1
  tx = obtener_tx(identificador, simbolos,linea)
  ty = obtener_ty(identificador, simbolos,linea)
  turtle.pensize(8)
  turtle.penup()

  
  #Trasladar circunferencia
  x1 = x1 + tx
  y1 = y1 + ty

  #turtle.setposition(x1, y1-(radio*44))
  #turtle.pendown()
  #turtle.circle(radio*44)

  #Escalar circunferencia
  turtle.penup()
  #turtle.setposition(x1, y1-(radio*44*escalar))
  turtle.setposition(x1*44, (y1*44)-(radio*44*escalar))
  turtle.pendown()
  turtle.fillcolor(relleno)
  turtle.begin_fill()
  turtle.circle(radio*44*escalar)
  turtle.end_fill()
Exemple #15
0
def circle(x,y,size):
	turtle.pu()
	turtle.goto(x,y)
	turtle.pd()
	turtle.begin_fill()
	turtle.circle(size)
	turtle.end_fill()
def dope_flowers(x, y):
    turtle.pendown()
    turtle.begin_fill()
    move(turtle, 100)
    flower(turtle, 10, 20.0, 60.0)
    turtle.end_fill()
    turtle.penup()
Exemple #17
0
def tree( x, y, scale ):
	'''draws a leaf given location and scale'''
	goto( x, y )
	turtle.setheading(0)
	turtle.begin_fill()
	turtle.color('dark green')
	turtle.forward(25*scale)
	turtle.left(150)
	turtle.forward(25*scale)
	turtle.right(150)
	turtle.forward(20*scale)
	turtle.left(150)
	turtle.forward(30*scale)
	turtle.left(60)
	turtle.forward(30*scale)
	turtle.left(150)
	turtle.forward(20*scale)
	turtle.right(150)
	turtle.forward(25*scale)
	turtle.left(150)
	turtle.end_fill()
	turtle.forward(30*scale)
	goto( x, y )
	turtle.begin_fill()
	turtle.color('brown')
	turtle.right(90)
	turtle.forward(15*scale)
	turtle.right(90)
	turtle.forward(5*scale)
	turtle.right(90)
	turtle.forward(15*scale)
	turtle.right(90)
	turtle.end_fill()
	turtle.forward(5*scale)
Exemple #18
0
def draw_rectangle(length_float, width_float, color_str):
    """
    Asks for the length, width, and color of the rectangle and draws it
    using turtle
    
    Recieve:    The length, width and color of the triangle
    Return:     Nothing
    Algorithm:
        Use a for loop and draw a rectangle by going forward the specified
        length and making a 90 degree turn to the right and then going
        forward the width and turning 90 degrees to the right
        Then do the loop again
    """
    
    turtle.fillcolor(color_str)    
    turtle.pendown()
    turtle.begin_fill()
    
    for i in range(2):
        turtle.forward(length_float)
        turtle.right(90)
        turtle.forward(width_float)
        turtle.right(90)
        
    turtle.end_fill()
    turtle.penup()
Exemple #19
0
def cross( x, y, scale, color ):
	'''draws a cross given location, scale, and color'''
	goto( x, y )
	turtle.begin_fill()
	turtle.color(color)
	turtle.forward(50*scale)
	turtle.right(90)
	turtle.forward(50*scale)
	turtle.left(90)
	turtle.forward(15*scale)
	turtle.left(90)
	turtle.forward(50*scale)
	turtle.right(90)
	turtle.forward(50*scale)
	turtle.left(90)
	turtle.forward(15*scale)
	turtle.left(90)
	turtle.forward(50*scale)
	turtle.right(90)
	turtle.forward(50*scale)
	turtle.left(90)
	turtle.forward(15*scale)
	turtle.left(90)
	turtle.forward(50*scale)
	turtle.right(90)
	turtle.forward(50*scale)
	turtle.left(90)
	turtle.forward(15*scale)
	turtle.end_fill()
Exemple #20
0
def leaf( x, y, scale, color ):
	'''draws a leaf given location and scale'''
	goto( x, y )
	turtle.begin_fill()
	turtle.color(color)
	turtle.right(30)
	turtle.forward(8.33*scale)
	turtle.left(120)
	turtle.forward(3.33*scale)
	turtle.right(105)
	turtle.forward(15*scale)
	turtle.left(110)
	turtle.forward(5*scale)
	turtle.right(95)
	turtle.forward(15*scale)
	turtle.left(150)
	turtle.forward(15*scale)
	turtle.right(95)
	turtle.forward(5*scale)
	turtle.left(110)
	turtle.forward(15*scale)
	turtle.right(105)
	turtle.forward(3.33*scale)
	turtle.left(120)
	turtle.forward(8.33*scale)
	turtle.left(60)
	turtle.forward(10*scale)
	turtle.left(30)
	turtle.forward(10*scale)
	turtle.left(180)
	turtle.forward(10*scale)
	turtle.left(75)
	turtle.end_fill()
	turtle.forward(8.33*scale)
def drawPoint(x, y): 
    turtle.penup() # Pull the pen up
    turtle.goto(x, y)
    turtle.pendown() # Pull the pen down
    turtle.begin_fill() # Begin to fill color in a shape
    turtle.circle(3) 
    turtle.end_fill() # Fill the shape
Exemple #22
0
def rand_circle():
    color = choice(colors)
    turtle.color(color, color)
    radius = randint(10, 100)
    turtle.begin_fill()
    turtle.circle(radius)
    turtle.end_fill()
Exemple #23
0
def drawCircleAt(turtleX, turtleY, circleSize):
    turtle.penup()
    turtle.goto(turtleX,turtleY)
    turtle.pendown()
    turtle.begin_fill()
    turtle.circle(circleSize)
    turtle.end_fill()
Exemple #24
0
def draw_vertrect(length,width,color):
    turtle.pendown()
    turtle.color(color)
    turtle.begin_fill()
    #uses color to determine length of cross
    if(color=="blue" or color == "red" or color == "light coral" or color=="yellow"):
        length*=.4375
    elif(color == "snow"or color=="navy" ):
        length*=.42857
    else:
        length*=.375
    print("the length of the first " , length, " and the width is ", width)
    #loops to draw vertical rectangle
    for x in range(5):
        if(x%5==0):
            #draws first half of left vertical line
            turtle.forward((length))
            print("drawing length")
        #draws from top of vertical to bottom of flag
        elif(x%2==0):
            turtle.forward(length*2+width)
            print("drawing long side")
        #draws small side of vertical rectangle
        elif(x!=5):
            turtle.forward(width)
        turtle.right(90)
    turtle.end_fill()
Exemple #25
0
def draw_star(size, color):

    turtle.pendown()
    turtle.begin_fill()
    turtle.color(1,1,1)
    turtle.forward(2.5) 
    turtle.left(size)
    turtle.forward(2.5)
    turtle.right(144)
    turtle.forward(2.5)
    turtle.left(size)
    turtle.forward(2.5)
    turtle.right(144)
    turtle.forward(2.5)
    turtle.left(size)
    turtle.forward(2.5)
    turtle.right(144)
    turtle.forward(2.5)
    turtle.left(size)
    turtle.forward(2.5)
    turtle.right(144)
    turtle.forward(2.5)
    turtle.left(size)
    turtle.forward(2.5)
    turtle.right(144)
    turtle.end_fill()
    turtle.penup()
def draw_rectangle(x,y,width,height):
    """
    Draws a rectangle with the upper left hand corner starting at point (x,y).
    The said rectangle has the dimensions width x height.
    :param x:
    :param y:
    :param width:
    :param height:
    :return: None
    """
    turtle.penup()
    turtle.setx(x)
    turtle.sety(y)
    turtle.pendown()
    turtle.setheading(0)  # Set heading in x+ direction
    turtle.begin_fill()
    turtle.begin_poly()
    turtle.fd(width)
    turtle.right(90)
    turtle.fd(height)
    turtle.right(90)
    turtle.fd(width)
    turtle.right(90)
    turtle.fd(height)
    turtle.end_poly()
    turtle.end_fill()
    return None
Exemple #27
0
def drawHead(circum, colour="yellow"):

    #turtle.pencolor("yellow")
    turtle.color("black", colour)
    turtle.begin_fill()
    drawCircle(circum)
    turtle.end_fill()
def draw_tree(x,y):
    startPosX = x
    startPosY = y
    turtle.setpos(x,y)
    turtle.fillcolor("green")
    turtle.begin_fill()
    for i in range(0,4):
        x -=40
        y -=80
        turtle.goto(x,y)
        coords.append(turtle.pos())
        x += 20
        turtle.goto(x,y)
    bottomCorner = turtle.pos()
    x = startPosX
    y = startPosY
    turtle.setpos(x,y)
    for i in range(0,4):
        x +=40
        y -=80
        turtle.goto(x,y)
        coords.append(turtle.pos())
        x -= 20
        turtle.goto(x,y)
    turtle.goto(bottomCorner)
    turtle.end_fill()
def draw_leaf(no_of_leafs):
    """
    Draws leafs at the end of branch. Min 0 and max = no_of_leafs
    :pre: pos(0,0), heading east, up
    :post: pos(0,0), heading east, up
    :param no_of_leafs: maximum number of leads drawn
    :return: None
    """
    for i in range(no_of_leafs):
        # draws random poylgon from triangle to hexagon
        sides = random.randint(3, 6)
        color = random.choice(COLORS)
        size = 10
        angle = 360/sides
        t.left(90 - i * angle)
        t.right(90)
        t.begin_fill()
        t.down()
        t.color(color)
        for _ in range(sides):
            t.forward(size)
            t.left(angle)
        t.left(90)
        t.up()
        t.end_fill()
        t.right(90 - i * angle)

    global LEAF_COUNTER
    LEAF_COUNTER += 1
def draw_rectangle():
    Fline = line.split()
    if Fline[1] == 'not_int':
        print(Fline)
        print("I'm sorry, I cannot understand that integer")
        return
    if len(Fline) < 4:
        print(Fline)
        print("I'm sorry, I do not understand that value")
        return
    x = int(Fline[1])
    y = int(Fline[2])
    width = int(Fline[3])
    height = int(Fline[4])
    turtle.penup()
    turtle.setpos(x, y)
    turtle.setheading(0)
    turtle.pendown()
    turtle.begin_fill()
    turtle.forward(width)
    turtle.setheading(-90)
    turtle.forward(height)
    turtle.setheading(180)
    turtle.forward(width)
    turtle.setheading(90)
    turtle.forward(height)
    turtle.end_fill()
Exemple #31
0
#정오각형 그리기 프로그램

import turtle as t

n = 5  #오각형을 그림
t.color("purple")
t.begin_fill()  #색칠할 영역을 시작함
for x in range(n):  #n 번 반복
    t.forward(50)  #거북이 50만큼 앞으로 이동
    t.left(360 / n)  #거북이 360/n만큼 왼쪽으로 회전
t.end_fill()  #색칠할 영역을 마무리
Exemple #32
0
def hexagone (coordonnee,longueur,col,centre,rayon):
    turtle.speed(0) # vitesse d'excution du dessin: vitesse lente
    turtle.up()
    x=coordonnee[0]  #coordonnes d'origine du premier cube: cela correspond au coinf inferieur gauche et coin sup droite
    y=coordonnee[1] # de la fenetre du dessin
    turtle.goto(x,y) # deplacement de la tortue au point d'origine du dessin
    turtle.down()

    # dessin de la premiere face du cube
    turtle.color(col[0])  # couleur de la face sup
    turtle.begin_fill()  # debuter le remplissage
    x = x + longueur * (math.cos(0))  # abscisse avant deformation
    y = y + longueur * (math.sin(0))  # ordonnée avant deformation
    p = (x, y, 0)
    pprim = deformation(p, centre, rayon)  # coordonnées apres deformation
    turtle.goto(pprim[0], pprim[1])  # la tortue va au point déformé

    x = x + longueur * (math.cos(-1 * math.pi / 3))
    y = y + longueur * (math.sin(-1 * math.pi / 3))
    p = (x, y, 0)
    pprim = deformation(p, centre, rayon)
    turtle.goto(pprim[0], pprim[1])

    x = x + longueur * (math.cos(-1 * math.pi))
    y = y + longueur * (math.sin(-1 * math.pi))
    p = (x, y, 0)
    pprim = deformation(p, centre, rayon)
    turtle.goto(pprim[0], pprim[1])

    x = x + longueur * (math.cos(-120 * math.pi / 180))
    y = y + longueur * (math.sin(120 * math.pi / 180))
    p = (x, y, 0)
    pprim = deformation(p, centre, rayon)
    turtle.goto(pprim[0], pprim[1])
    turtle.end_fill()

    # dessin de la deuxieme face du cube
    turtle.color(col[1])
    turtle.begin_fill()
    x=x+longueur*(math.cos(-60*math.pi/180))
    y=y+longueur*(math.sin(-60*math.pi/180))
    p = (x, y, 0)
    pprim = deformation(p, centre, rayon)
    turtle.goto(pprim[0],pprim[1])

    x=x+longueur*(math.cos(-120*math.pi/180))
    y=y+longueur*(math.sin(-120*math.pi/180))
    p = (x, y, 0)
    pprim = deformation(p, centre, rayon)
    turtle.goto(pprim[0],pprim[1])

    x=x+longueur*(math.cos(-240*math.pi/180))
    y=y+longueur*(math.sin(-240*math.pi/180))
    p = (x, y, 0)
    pprim = deformation(p, centre, rayon)
    turtle.goto(pprim[0],pprim[1])

    x = x + longueur * (math.cos(60 * math.pi / 180))
    y = y + longueur * (math.sin(60 * math.pi / 180))
    p = (x, y, 0)
    pprim = deformation(p, centre, rayon)
    turtle.goto(pprim[0], pprim[1])
    turtle.end_fill()




# dessin de la    troisieme face du cube
    turtle.color(col[2])
    turtle.down()
    turtle.begin_fill()
    x=x+longueur*(math.cos(0*math.pi/180))
    y=y+longueur*(math.sin(0*math.pi/180))
    p = (x, y, 0)
    pprim = deformation(p, centre, rayon)
    turtle.goto(pprim[0],pprim[1])
    x=x+longueur*(math.cos(-120*math.pi/180))
    y=y+longueur*(math.sin(-120*math.pi/180))
    p = (x, y, 0)
    pprim = deformation(p, centre, rayon)
    turtle.goto(pprim[0],pprim[1])
    x=x+longueur*(math.cos(-180*math.pi/180))
    y=y+longueur*(math.sin(-180*math.pi/180))
    p = (x, y, 0)
    pprim = deformation(p, centre, rayon)
    turtle.goto(pprim[0],pprim[1])
    x = x + longueur * (math.cos(60 * math.pi / 180))
    y = y + longueur * (math.sin(60 * math.pi / 180))
    p = (x, y, 0)
    pprim = deformation(p, centre, rayon)
    turtle.goto(pprim[0], pprim[1])
    turtle.end_fill()
Exemple #33
0
# 基于 turtle 库的小猪佩奇
import turtle as t

t.pensize(4)
t.hideturtle()
t.colormode(255)
t.color((255,155,192),"pink")
t.setup(840,500)
t.speed(10)

#鼻子
t.pu()
t.goto(-100,100)
t.pd()
t.seth(-30)
t.begin_fill()
a=0.4
for i in range(120):
    if 0<=i<30 or 60<=i<90:
        a=a+0.08
        t.lt(3) #向左转3度
        t.fd(a) #向前走a的步长
    else:
        a=a-0.08
        t.lt(3)
        t.fd(a)
t.end_fill()

t.pu()
t.seth(90)
t.fd(25)
    def hexagone(point, longueur, col, centre, rayon):
        """Dessine un hexagone divisé en trois losanges de différents
           couleurs et déformé par une sphère émergente; utilise la
           fonction deformation
           Entrées :
            point : triple contenant les coordonnées (x,y,z) du
                    centre de l'hexagone avant déformation
            longueur : float qui précise la distance entre le
                   centre et n'importe quel sommet de l'hexagone
                   (étant un hexagone régulier, il represent
                   aussi la longueur des arrête)
            col : triple contenant les couleurs des trois losanges
                  par lesquels l'hexagone est divisé
            centre : triple contenant le coordonnées (x,y,z)
                     du centre de la sphère émergente
            rayon : float qui précise le rayon de la sphère
                    émergente
           Sorties:
            dessin de l'hexagone
        """

        def deformation(p, centre, rayon):
            """ Calcul des coordonnées d'un point suite à la déformation
                engendrée par la sphère émergeante
                Entrées :
                  p : coordonnées (x, y, z) du point du dalage à tracer
                     (z = 0) AVANT déformation
                  centre : coordonnées (X0, Y0, Z0) du centre de la sphère
                  rayon : rayon de la sphère
                Sorties : coordonnées (xprim, yprim, zprim) du point du dallage
                     à tracer APRÈS déformation
            """
            x, y, z = p
            xprim, yprim, zprim = x, y, z
            xc, yc, zc = centre
            if rayon ** 2 > zc ** 2:
                zc = zc if zc <= 0 else -zc
                r = sqrt(
                    (x - xc) ** 2 + (y - yc) ** 2)  # distance horizontale
                # depuis le point à dessiner jusqu'à l'axe de la sphère
                rayon_emerge = sqrt(rayon ** 2 - zc ** 2)  # rayon de la partie
                # émergée de la sphère
                rprim = rayon * sin(acos(-zc / rayon) * r / rayon_emerge)
                if 0 < r <= rayon_emerge:  # calcul de la déformation
                    # dans les autres cas
                    xprim = xc + (x - xc) * rprim / r  # les nouvelles coordonnées
                    # sont proportionnelles aux anciennes
                    yprim = yc + (y - yc) * rprim / r
                if r <= rayon_emerge:
                    beta = asin(rprim / rayon)
                    zprim = zc + rayon * cos(beta)
                    if centre[2] > 0:
                        zprim = -zprim
            return (xprim, yprim, zprim)


        cen=deformation(point,centre,rayon) #calcule les coordonnées du
        #centre de l'hexagone après déformation
        v1=deformation((point[0]+longueur,point[1],point[2]),centre,rayon)
        #calcule les coordonnées du sommet droit de l'hexagone après
        #déformation
        v2=deformation((point[0]+(1/2)*longueur,point[1]+
                          sin(pi/3)*longueur,point[2]),centre,rayon)
        #calcule les coordonnées du sommet supérieur-droit de l'hexagone
        #après déformation
        v3=deformation((point[0]-(1/2)*longueur,point[1]+
                          sin(pi/3)*longueur,point[2]),centre,rayon)
        #calcule les coordonnées du sommet supérieur-gauche de l'hexagone
        #après déformation
        v4=deformation((point[0]-longueur,point[1],point[2]),centre,rayon)
        #calcule les coordonnées du sommet gauche de l'hexagone après
        #déformation
        v5=deformation((point[0]-(1/2)*longueur,point[1]-
                          sin(pi/3)*longueur,point[2]),centre,rayon)
        #calcule les coordonnées du sommet inférieur-gauche de l'hexagone
        #après déformation
        v6=deformation((point[0]+(1/2)*longueur,point[1]-
                          sin(pi/3)*longueur,point[2]),centre,rayon)
        #calcule les coordonnées du sommet inférieur-droit de l'hexagone
        #après déformation
        turtle.up()
        turtle.goto(cen[0], cen[1]) #positionne la tortue au centre de
        #l'hexagone
        turtle.down()
        for i in range(3): #dessine une losange de l'hexagone par loop
            #dans l'ordre: haut-droit, gauche, bas-droit
            a=v1 #sommets de la losange en haut-droit
            b=v2
            c=v3
            if i==1: #variation des sommets de la losange à gauche par
                #rapport à la losange en haut-droit
                a=v5
                b=v4
            elif i==2: #variation des sommets de la losange en bas-droit
                #par rapport à la losange en haut-droit
                b=v6
                c=v5
            turtle.color(col[i]) #sélectionne la couleur parmi
            #les trois donnés en triple
            turtle.begin_fill()
            turtle.goto(a[0],a[1])
            turtle.goto(b[0],b[1])
            turtle.goto(c[0],c[1])
            turtle.goto(cen[0],cen[1])
            turtle.end_fill()
        return
Exemple #35
0
 def draw(self, turtle):
     turtle.fillcolor(self.color)
     turtle.begin_fill()
import turtle

turtle.speed(5)
turtle.circle(50)
turtle.begin_fill()  #画头
turtle.circle(85)
turtle.fillcolor("blue")
turtle.end_fill()

# turtle.penup()
# turtle.goto(0,20)
# turtle.pendown()

# turtle.begin_fill()
# turtle.circle(35)
# turtle.fillcolor("white")
# turtle.end_fill()

turtle.begin_fill()  #画脸
turtle.circle(60)
turtle.fillcolor("white")
turtle.end_fill()

turtle.penup()
turtle.goto(-20, 95)  #化左眼眶
turtle.pendown()
turtle.begin_fill()
turtle.circle(19)
turtle.fillcolor("white")
turtle.end_fill()
Exemple #37
0
import turtle

turtle.shape('turtle')

turtle.fillcolor('red')

turtle.begin_fill() # fill in (with the fillcolor) the following shape

turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)

turtle.end_fill() # I'm done drawing, please fill in my shape Mr. Turtle
Exemple #38
0
# coding:utf-8
import turtle as t
t.pensize(4) # 设置画笔的大小
t.colormode(255) # 设置GBK颜色范围为0-255
t.color((255,155,192),"pink") # 设置画笔颜色和填充颜色(pink)
t.setup(840,500) # 设置主窗口的大小为840*500
t.speed(0) # 设置画笔速度为10
#鼻子
t.pu() # 提笔
t.goto(-100,100) # 画笔前往坐标(-100,100)
t.pd() # 下笔
t.seth(-30) # 笔的角度为-30°
t.begin_fill() # 外形填充的开始标志
a=0.4
for i in range(120):
    if 0<=i<30 or 60<=i<90:
        a=a+0.08
        t.lt(3) #向左转3度
        t.fd(a) #向前走a的步长
    else:
        a=a-0.08
        t.lt(3)
        t.fd(a)
t.end_fill() # 依据轮廓填充
t.pu() # 提笔
t.seth(90) # 笔的角度为90度
t.fd(25) # 向前移动25
t.seth(0) # 转换画笔的角度为0
t.fd(10)
t.pd()
t.pencolor(255,155,192) # 设置画笔颜色
Exemple #39
0
import turtle  # 导入turtle模块
turtle.setup(1200, 800, 0, 0)
turtle.bgcolor("red")  # 背景颜色
turtle.color('yellow')  # 五角星颜色
turtle.speed(5)  # 设置画笔绘制速度
# 绘制最大的主五角星
turtle.begin_fill()  # 填充绘制的五角星
turtle.up()  # 抬笔不绘制
turtle.goto(-520, 240)  # 画笔设置到起始位置
turtle.down()  # 落笔进行绘制
for i in range(5):  # 循环5次
    turtle.forward(240)  # 向前移动150
    turtle.right(144)  # 以角度单位向右转动
turtle.end_fill()  # 结束填充
# 绘制第1颗副星
turtle.begin_fill()
turtle.up()
turtle.goto(-230, 345)
turtle.setheading(305)
turtle.down()
for i in range(5):
    turtle.forward(70)
    turtle.left(144)
turtle.end_fill()

# 绘制第2颗副星
turtle.begin_fill()
turtle.up()
turtle.goto(-150, 230)
turtle.setheading(30)
turtle.down()
Exemple #40
0
 def __init__(self):
     t.setup(500,500);
     t.screensize(100,100);
     t.setworldcoordinates(0,-50,100,50);
     t.bgcolor("skyblue");
     t.penup();
     t.setpos(60,0);
     t.left(90);
     t.pensize(5);
     t.pendown();
     t.pencolor("black");
     t.fillcolor("white");
     t.begin_fill();
     t.circle(10,360);
     t.end_fill();
     t.penup();
     t.setpos(56,3)
     t.pendown();
     t.pensize(1);
     t.fillcolor("black");
     t.begin_fill();
     t.circle(1,360);
     t.end_fill();
     t.penup();
     t.setpos(44,3);
     t.left(180);
     t.pendown();
     t.begin_fill();
     t.circle(1,360);
     t.end_fill();
     t.penup();
     t.pensize(5);
     t.setpos(50,3);
     t.pendown();
     t.forward(3);
     t.penup();
     t.setpos(53,-3);
     t.right(90);
     t.pendown();
     t.forward(6);
     t.penup();
     t.setpos(50,-10);
     t.left(90);
     ##t.pensize(5);
     t.pendown();
     t.forward(10);
     t.penup();
     t.setpos(67.07,-12.93);
     t.right(45);
     t.pendown();
     t.forward(10);
     t.right(45);
     t.forward(20);
     t.right(45);
     t.forward(10);
     t.penup();
     t.setpos(50,-20);
     t.left(135);
     t.pendown();
     t.forward(10);
     t.penup();
     t.setpos(47.07,-37.07);
     t.right(135);
     t.pendown();
     t.forward(10);
     t.right(135);
     t.forward(20);
     t.right(135);
     t.forward(10);
     t.penup();
     t.hideturtle();
     t.onscreenclick(None);
     t.mainloop();
Exemple #41
0
def circle(radius, color):
    turtle.color(color)
    turtle.begin_fill()
    turtle.circle(radius)
    turtle.end_fill()
# 3.6 Write a program that draws a triangle, square, pentagon, hexagon, and octagon

import turtle  # Import turtle module

# Draw a triangle with bottom side parallel to x-axis
turtle.setheading(60)  # Set the turtle’s heading to 60 degrees
turtle.pensize(3)  # Set pen thickness to 3 pixels
turtle.penup()
turtle.goto(-200, -50)
turtle.pendown()
turtle.begin_fill()  # Begin to fill color in the shape
turtle.color("red")
turtle.circle(40, steps=3)  # Draw a triangle
turtle.end_fill()  # Fill the shape

# Draw a square with bottom side parallel to x-axis
turtle.setheading(45)  # Set the turtle’s heading to 45 degrees
turtle.penup()
turtle.goto(-100, -50)
turtle.pendown()
turtle.begin_fill()  # Begin to fill color in the shape
turtle.color("blue")
turtle.circle(40, steps=4)  # Draw a square
turtle.end_fill()  # Fill the shape

# Draw a pentagon with bottom side parallel to x-axis
turtle.setheading(36)  # Set the turtle’s heading to 36 degrees
turtle.penup()
turtle.goto(0, -50)
turtle.pendown()
turtle.begin_fill()  # Begin to fill color in the shape
    for i in range(361):
        tr.goto(x + r * np.cos(i * np.pi / 180),
                y + r * np.sin(i * np.pi / 180))


def arc(x, y, r, angle_1, angle_2):
    tr.penup()
    tr.goto(x + r * np.cos(angle_1 * np.pi / 180),
            y + r * np.sin(angle_1 * np.pi / 180))
    tr.pendown()
    for i in range(angle_1, angle_2 + 1, 1):
        tr.goto(x + r * np.cos(i * np.pi / 180),
                y + r * np.sin(i * np.pi / 180))


tr.begin_fill()
tr.color('black')
circle(0, 0, 100)
tr.color('yellow')
tr.end_fill()
for k in range(-1, 3, 2):
    tr.begin_fill()
    tr.color('black')
    circle(40 * k, 30, 20)
    tr.color('blue')
    tr.end_fill()
tr.color('black')
tr.penup()
tr.goto(0, 30)
tr.pendown()
tr.width(8)
import turtle as t
import math as m

t.color("red")  # 펜 색을 적색으로 설정
t.begin_fill()  # 내부를 칠하도록 명령

for x in range(100):  # 100개의 점으로 나누어 그립니다.
    h = m.pi * x / 50
    x = 160 * m.sin(h)**3
    y = 130 * m.cos(h) - 50 * m.cos(2 * h) - 20 * m.cos(3 * h) - 10 * m.cos(
        4 * h)
    t.goto(x, y)  # 계산된(x, y) 위치로 거북이가 이동합니다.

t.end_fill()
Exemple #45
0
def main():
    # put label on top of page
    turtle.title('Colorful Shapes')

    # setup screen size
    turtle.setup(800, 800, 0, 0)

    # draw a triangle
    turtle.pensize(3)
    turtle.penup()
    turtle.goto(-200, -50)
    turtle.pendown()
    turtle.begin_fill()
    turtle.color('red')
    turtle.circle(40, steps=3)
    turtle.end_fill()

    # draw a square
    turtle.penup()
    turtle.goto(-100, -50)
    turtle.pendown()
    turtle.begin_fill()
    turtle.color('navy')
    turtle.circle(40, steps=4)
    turtle.end_fill()

    # draw a pentagon
    turtle.penup()
    turtle.goto(0, -50)
    turtle.pendown()
    turtle.begin_fill()
    turtle.color('green')
    turtle.circle(40, steps=5)
    turtle.end_fill()

    # draw a hexagon
    turtle.penup()
    turtle.goto(100, -50)
    turtle.pendown()
    turtle.begin_fill()
    turtle.color('yellow')
    turtle.circle(40, steps=6)
    turtle.end_fill()

    # draw a circle
    turtle.penup()
    turtle.goto(200, -50)
    turtle.pendown()
    turtle.begin_fill()
    turtle.color('purple')
    turtle.circle(40)
    turtle.end_fill()

    # write header
    turtle.penup()
    turtle.goto(-100, 50)
    turtle.write('Cool Colorful Shapes', font=('Times', 18, 'bold'))

    # hide turtle
    turtle.hideturtle()

    # persist drawing
    turtle.done()
Exemple #46
0
def mainmassage(name,money):
    #打印姓名
    t.goto(-280,68)
    t.write('收款人:                       出票人姓名:XXX',move=False,align="left",font=("Arial",10,"normal"))
    t.goto(-215,68)
    t.write(name,move=False,align="left",font=("Arial",10,"normal"))
    #绘制金额外方框
    t.goto(-280,68)
    t.pendown()
    t.fd(540)
    t.right(90)
    t.fd(50)
    t.right(90)
    t.fd(540)
    t.right(90)
    t.fd(50)
    #绘制内方框
    t.penup()
    t.goto(-220,65)
    t.right(90)
    t.color("pink")
    t.begin_fill()
    t.pendown()
    t.fd(200)
    t.right(90)
    t.fd(30)
    t.right(90)
    t.fd(200)
    t.right(90)
    t.fd(30)
    t.end_fill()
    t.penup()
    t.color("black")
    #绘制金额表格
    t.right(180)
    num_list=["亿","仟","百","十","万","千","百","十","元","角"]
    for i in range(10):
        t.penup()
        t.goto(10+i*25,68)
        t.pendown()
        t.fd(25)
        t.write(num_list[i],move=False,align="left",font=("Arial",15,"normal"))
        t.fd(25)
    t.penup()
    t.goto(10,43)
    t.pendown()
    t.left(90)
    t.fd(252)
    #打印金额
    t.penup()
    t.goto(-280,40)
    t.write('人民币',move=False,align="left",font=("Arial",15,"normal"))
    t.goto(-220,40)
    t.write(money,move=False,align="left",font=("Arial",15,"normal"))
    m_str=str(money)
    for i in range(11-len(m_str)):
        t.goto(10+i*25,18)
        t.write("0",move=False,align="left",font=("Arial",15,"normal"))
    for i in range(11-len(m_str),9):
        t.goto(10+i*25,18)
        t.write(m_str[i+len(m_str)-11],move=False,align="left",font=("Arial",15,"normal"))
    t.goto(240,18)
    t.write(m_str[len(m_str)-1],move=False,align="left",font=("Arial",15,"normal"))
def drawCircle(x,y,color,radius) :
    turtle.goto(x,y)
    turtle.color(color)
    turtle.begin_fill()
    turtle.circle(radius)
    turtle.end_fill()
Exemple #48
0
 def draw(self):
     turtle.begin_fill()
     super().draw()
     turtle.end_fill()
def focalLength(obj, img):
    print("Welcome to the Focal Length Calculator!!")
    object_distance = (input("Enter an object distance, in mm: ")
                       )  #input object distance
    image_distance = (input("Enter an image distance, in mm: ")
                      )  #input image distance
    focal_length = 1 / (float(image_distance)) + 1 / (float(object_distance))
    print("Focal Length of your lens is: ", 1 / float((focal_length)), "mm")
    line = (1 / float((focal_length)) / 2)
    print("Lens:", line, "mm")  #distance between f points, placed at origin
    turtle.speed(1)  #speed to see the turtle in motion
    turtle.showturtle()
    turtle.screensize(2000, 2000)

    #object
    turtle.forward(
        -float(object_distance))  #to left if positive, to right if negative
    turtle.color(str("#bc1818"))
    turtle.begin_fill()
    turtle.forward(10)
    turtle.left(90)
    turtle.forward(10)
    turtle.left(90)
    turtle.forward(10)
    turtle.left(90)
    turtle.forward(10)
    turtle.left(90)
    turtle.end_fill()
    turtle.color("black")
    turtle.penup()
    turtle.goto(-float(object_distance), 20)
    turtle.write("Object", True, align="center",
                 font=("Ariel", 10, "normal"))  #label above lens axis
    turtle.goto(-float(object_distance), 0)
    turtle.pendown()

    #focalpoint1 -- -120 #have to go to origin for it to be the right distance
    turtle.goto(0, 0)  #go to origin; "reset"
    turtle.forward(-float(1 / focal_length))
    turtle.begin_fill()
    turtle.dot(9, str("#176825"))
    turtle.end_fill()
    turtle.penup()
    turtle.goto(-float(1 / focal_length), -30)
    turtle.write("Focal Point",
                 True,
                 align="center",
                 font=("Ariel", 10, "normal"))  #label below lens axis
    turtle.color("black")
    turtle.goto(-float(1 / focal_length), 0)
    turtle.pendown()

    #focalpoint2 -- 120 #have to go to the origin for it to be the right distance
    turtle.goto(0, 0)  #go to origin; "reset"
    turtle.goto(float(1 / focal_length), 0)
    turtle.begin_fill()
    turtle.dot(9, str("#176825"))
    turtle.end_fill()
    turtle.penup()
    turtle.goto(float(1 / focal_length), -30)
    turtle.write("Focal Point",
                 True,
                 align="center",
                 font=("Ariel", 10, "normal"))
    turtle.color("black")
    turtle.goto(float(1 / focal_length), 0)
    turtle.pendown()
    turtle.goto(0, 0)  #go to origin; "reset"

    #image
    turtle.forward(
        float(image_distance))  #to right if positive, to left if negative
    turtle.color(str("#183870"))
    turtle.begin_fill()
    turtle.forward(10)
    turtle.left(90)
    turtle.forward(10)
    turtle.left(90)
    turtle.forward(10)
    turtle.left(90)
    turtle.forward(10)
    turtle.left(90)
    turtle.end_fill()
    turtle.color("black")
    turtle.penup()
    turtle.goto(float(image_distance), 20)
    turtle.write("Image", True, align="center",
                 font=("Ariel", 10, "normal"))  #label above lens axis
    turtle.goto(float(image_distance), 0)
    turtle.pendown()
    turtle.goto(0, 0)

    #lens
    turtle.color(str("#5e5e5e"))
    turtle.goto(0, 100)  #to make the vertical line
    turtle.goto(0, -100)  #to make the vertical line
	def drawString(self, dstring, distance, angle):
		stack = []
		cstack = []
		modstring = ''
		modval = None
		modgrab = False
		for c in dstring:
			if c == '(':
				modstring = ''
				modgrab = True
				continue
			elif c == ')':
				modval = float(modstring)
				modgrab = False
				continue
			elif modgrab:
				modstring += c
				continue
			elif c == 'F' or c ==  'f':
				if modval == None:
					self.forward(distance)
				else:
					self.forward(distance*modval)
			elif c == '-':
				if modval == None:
					turtle.right(angle)
				else:
					turtle.right(modval)
			elif c == '+':
				if modval == None:
					turtle.left(angle)
				else:
					turtle.left(modval)
			elif c == '!':
				if modval == None:
					w = turtle.width()
					if w > 1:
						turtle.width(w-1)
				else:
					turtle.width(modval)
			elif c == '[':
				stack.append(turtle.position())
				stack.append(turtle.heading())
			elif c == ']':
				turtle.up()
				turtle.setheading(stack.pop())
				turtle.goto(stack.pop())
				turtle.down()
			elif c == 'L':
				#draws a leaf
				#begin and end fil calls work better in this section of code
				turtle.begin_fill()
				turtle.circle(5)
				turtle.end_fill()
			elif c == 'Q':
				#created for task3
				#draws a flower
				pos = turtle.position()
				heading = turtle.heading()
				turtle.begin_fill()
				turtle.right(90)
				turtle.forward(5)
				turtle.left(120)
				turtle.forward(10)
				turtle.left(120)
				turtle.forward(10)
				turtle.left(120)
				turtle.forward(10)
				turtle.end_fill()
				turtle.up()
				turtle.goto(pos)
				turtle.setheading(heading)
				turtle.down()
			elif c == 'P':
				#draws a petal
				#CREATED FOR EXTENSION1
				turtle.begin_fill()
				for i in range(12):
					turtle.forward(5)
					turtle.right(108)
					turtle.forward(5)
					turtle.left(144)
				turtle.end_fill()
			elif c == '<':
				color = turtle.color()[0]
				cstack.append(color)
			elif c == '>':
				turtle.color(cstack.pop())
			elif c == 'g':
				#makes the leaf color medium orchid
				turtle.color("Medium Orchid")
			elif c == 'y':
				#makes the leaf color turquoise
				turtle.color("Turquoise")
			elif c == 'r':
				#makes the leaf color salmon
				turtle.color("Salmon")
			elif c == 'b':
				#CREATED FOR EXTENSION1
				#makes the leaf color salmon
				turtle.color("Plum")
			elif c == 'o':
				#CREATED FOR EXTENSION1
				#makes the leaf color salmon
				turtle.color("Khaki")
			elif c == '{':
				turtle.fill(True)
			elif c == '}':
				turtle.fill(False)
		
			modval = None	
			
		turtle.update()
def yanjing():
    t.begin_fill()

    t.penup()
    t.goto(-125, 140)
    t.pendown()
    t.fillcolor("#000000")
    t.pencolor("black")
    t.seth(100)
    t.circle(-25, 80)
    t.seth(40)
    t.circle(-200, 23)
    t.seth(-90)
    t.fd(45)
    t.seth(195)
    t.circle(200, 27)
    t.seth(150)
    t.circle(-12, 90)
    t.goto(-125, 140)
    t.end_fill()
    # 黑色
    t.begin_fill()

    t.penup()
    t.goto(-39, 205)
    t.pendown()
    t.fillcolor("#E6E8FA")
    t.setheading(90)
    t.circle(-8, 180)
    t.seth(-90)
    t.fd(45)
    t.circle(-8, 180)
    t.goto(-39, 205)
    t.end_fill()
    # 银色
    t.begin_fill()

    t.penup()
    t.goto(-23, 160)
    t.pendown()
    t.fillcolor("#E6E8FA")
    t.seth(-78)
    t.circle(85, 130)
    t.goto(-23, 160)
    t.end_fill()
    # 银色
    t.begin_fill()
    t.penup()
    t.goto(-23, 190)
    t.pendown()
    t.fillcolor("#E6E8FA")
    t.seth(-90)
    t.circle(90)
    t.end_fill()
    # 银色
    t.begin_fill()
    t.penup()
    t.goto(155, 205)
    t.pendown()
    t.fillcolor("#000000")
    t.seth(-15)
    t.circle(-100, 20)
    t.seth(-60)
    t.circle(-105, 25)
    t.seth(160)
    t.circle(200, 13.5)
    t.seth(75)
    t.circle(90, 20)
    t.goto(155, 205)
    t.end_fill()
    # 黑色
    t.begin_fill()
    t.penup()
    t.goto(128, 195)
    t.pendown()
    t.fillcolor("#ffffff")
    t.circle(60)
    t.end_fill()
    # 白色
    t.begin_fill()
    t.penup()
    t.goto(110, 150)
    t.pendown()
    t.fillcolor("#000000")
    t.seth(70)
    t.circle(70, 110)
    t.seth(20)
    t.circle(-60, 150)
    t.end_fill()
    # 黑色
    t.begin_fill()
    t.penup()
    t.goto(25, 210)
    t.pendown()
    t.fillcolor("#B85300")
    t.circle(20)
    t.end_fill()
    # 白色
    t.begin_fill()
    t.penup()
    t.goto(32, 204)
    t.pendown()
    t.fillcolor("#000000")
    t.circle(8)
    t.end_fill()
def color_triangle(side_length, color):
    t.fillcolor(color)
    t.begin_fill()
    draw_triangle(side_length)
    t.end_fill()
    return None
#Developers: Zaytsev A. 40%
#            Sharypov R. 50% (because of debuging)
#            Kurasova P. 40%
import turtle
turtle.setup(1020, 640)
#TODO ALEXANDER
#boat
#trapezoid
turtle.speed(0)
turtle.goto(0, 0)
turtle.pendown()
turtle.fillcolor('grey')
turtle.begin_fill()
turtle.forward(300)
turtle.right(135)
turtle.forward(105)
turtle.right(45)
turtle.forward(150)
turtle.right(45)
turtle.forward(105)
turtle.end_fill()
turtle.up()

# rectangle
turtle.right(135)
turtle.forward(50)
turtle.pendown()
turtle.fillcolor('green')
turtle.begin_fill()
turtle.left(90)
turtle.forward(100)
Exemple #54
0
def draw_circle(r, color):
    turtle.fillcolor(color)
    turtle.begin_fill()
    turtle.circle(r)
    turtle.end_fill()
def drawSVG(filename, w_color):
    global first
    SVGFile = open(filename, 'r')
    SVG = BeautifulSoup(SVGFile.read(), 'lxml')
    Height = float(SVG.svg.attrs['height'][0: -2])
    Width = float(SVG.svg.attrs['width'][0: -2])
    transform(SVG.g.attrs['transform'])
    if first:
        te.setup(height=Height, width=Width)
        te.setworldcoordinates(-Width / 2, 300, Width -
                               Width / 2, -Height + 300)
        first = False
    te.tracer(100)
    te.pensize(1)
    te.speed(Speed)
    te.penup()
    te.color(w_color)

    for i in SVG.find_all('path'):
        attr = i.attrs['d'].replace('\n', ' ')
        f = readPathAttrD(attr)
        lastI = ''
        for i in f:
            if i == 'M':
                te.end_fill()
                Moveto(f.__next__() * scale[0], f.__next__() * scale[1])
                te.begin_fill()
            elif i == 'm':
                te.end_fill()
                Moveto_r(f.__next__() * scale[0], f.__next__() * scale[1])
                te.begin_fill()
            elif i == 'C':
                Curveto(f.__next__() * scale[0], f.__next__() * scale[1],
                        f.__next__() * scale[0], f.__next__() * scale[1],
                        f.__next__() * scale[0], f.__next__() * scale[1])
                lastI = i
            elif i == 'c':
                Curveto_r(f.__next__() * scale[0], f.__next__() * scale[1],
                          f.__next__() * scale[0], f.__next__() * scale[1],
                          f.__next__() * scale[0], f.__next__() * scale[1])
                lastI = i
            elif i == 'L':
                Lineto(f.__next__() * scale[0], f.__next__() * scale[1])
            elif i == 'l':
                Lineto_r(f.__next__() * scale[0], f.__next__() * scale[1])
                lastI = i
            elif lastI == 'C':
                Curveto(i * scale[0], f.__next__() * scale[1],
                        f.__next__() * scale[0], f.__next__() * scale[1],
                        f.__next__() * scale[0], f.__next__() * scale[1])
            elif lastI == 'c':
                Curveto_r(i * scale[0], f.__next__() * scale[1],
                          f.__next__() * scale[0], f.__next__() * scale[1],
                          f.__next__() * scale[0], f.__next__() * scale[1])
            elif lastI == 'L':
                Lineto(i * scale[0], f.__next__() * scale[1])
            elif lastI == 'l':
                Lineto_r(i * scale[0], f.__next__() * scale[1])
    te.penup()
    te.hideturtle()
    te.update()
    SVGFile.close()
from turtle import forward, left, exitonclick, right, shape, circle, fillcolor, begin_fill, end_fill, penup, pendown

shape('turtle')

#dum
fillcolor('blue')
begin_fill()
for ctverec in range(4):
    forward(150)
    left(90)
end_fill()

#strecha
left(90)
forward(150)
fillcolor('red')
begin_fill()
right(30)
forward(150)
right(120)
forward(150)
end_fill()

#presun k slunci
right(75)
penup()
left(180)
forward(250)
pendown()

#slunce
Exemple #57
0
import turtle as t
box_color = "blue"
x = 0
y = 0
height = 100

t.fillcolor(box_color)  # Determine the color of the crescent
t.up()
t.goto(x, y)  # Declare the position of the crescent
t.begin_fill()  # Specif when the fill begins
t.down()
t.circle(height, extent=180)  # Create two partial circles
t.circle(height, extent=-190)
t.end_fill()  # Specify when the fill ends
Exemple #58
0
def fill_circle(color, r1):
    turtle.color(color, color)
    turtle.fillcolor()
    turtle.begin_fill()
    draw_circle(r1)
    turtle.end_fill()
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import turtle
>>> turtle.penup()
>>> turtle.pensize(3)
>>> turtle.goto(-200, 50)
>>> turtle.pendown()
>>> turle.begin_fill()
Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    turle.begin_fill()
NameError: name 'turle' is not defined
>>> turtle.begin_fill()
>>> turtle.color("black")
>>> turtle.circle(40)
>>> 
>>> turtle.penup()
>>> turtle.goto(-100, -50)
>>> turtle.undo()
>>> turtle.goto(-180, -40)
>>> turtle.undo()
>>> turtle.goto(-200, -40)
>>> turtle.undo()
>>> turtle.goto(-190, -50)
>>> turtle.pendown()
>>> turtle.begin_fill()
>>> turtle.color("red")
>>> turtle.circle(40)
>>> turtle.undo()
>>> turtle.undo()
>>> turtle.undo()
Exemple #60
0
def customized_circle(size, color_name):
    color(color_name)
    begin_fill()
    circle(size)
    end_fill()