Dibuja formas llenas de color en Turtle – Python

Prerrequisito: Conceptos básicos de la Turtle python

Turtle es un módulo incorporado en python. Proporciona dibujo utilizando una pantalla (cartón) y una Turtle (bolígrafo). Para dibujar algo en la pantalla, necesitamos mover la Turtle. Para mover la Turtle, hay algunas funciones, es decir forward(), backward(), etc.

Para llenar los colores en las formas dibujadas por la Turtle, la Turtle proporciona tres funciones:

fillcolor() : Esto ayuda a elegir el color para rellenar la forma. Toma el parámetro de entrada como el nombre del color o el valor hexadecimal del color y rellena los próximos objetos geográficos cerrados con el color elegido. Los nombres de colores son nombres de colores básicos, es decir, rojo, azul, verde, naranja.
El valor hexadecimal del color es una string (que comienza con ‘#’) de números hexadecimales, es decir, #RRGGBB. R, G y B son los números hexadecimales (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F).

begin_fill() : Esta función le dice a la Turtle que todos los objetos gráficos cerrados próximos deben llenarse con el color elegido.

end_fill() : esta función le dice a la Turtle que detenga el llenado de los próximos objetos gráficos cerrados.

Cuadrado relleno de color de dibujo:

# draw color-filled square in turtle
  
import turtle
  
# creating turtle pen
t = turtle.Turtle()
  
# taking input for the side of the square
s = int(input("Enter the length of the side of the square: "))
  
# taking the input for the color
col = input("Enter the color name or hex value of color(# RRGGBB): ")
  
# set the fillcolor
t.fillcolor(col)
  
# start the filling color
t.begin_fill()
  
# drawing the square of side s
for _ in range(4):
  t.forward(s)
  t.right(90)
  
# ending the filling of the color
t.end_fill()

Aporte :

200
green

Producción :

Triángulo relleno de color de dibujo:

# draw color filled triangle in turtle
  
import turtle
  
# creating turtle pen
t = turtle.Turtle()
  
# taking input for the side of the triangle
s = int(input("Enter the length of the side of the triangle: "))
  
# taking the input for the color
col = input("Enter the color name or hex value of color(# RRGGBB): ")
  
# set the fillcolor
t.fillcolor(col)
  
# start the filling color
t.begin_fill()
  
# drawing the triangle of side s
for _ in range(3):
  t.forward(s)
  t.right(-120)
  
# ending the filling of the color
t.end_fill()

Aporte :

200
red

Producción :

Hexágono relleno de color de dibujo:

# draw color-filled hexagon in turtle
  
import turtle
  
# creating turtle pen
t = turtle.Turtle()
  
# taking input for the side of the hexagon
s = int(input("Enter the length of the side of the hexagon: "))
  
# taking the input for the color
col = input("Enter the color name or hex value of color(# RRGGBB): ")
  
# set the fillcolor
t.fillcolor(col)
  
# start the filling color
t.begin_fill()
  
# drawing the hexagon of side s
for _ in range(6):
  t.forward(s)
  t.right(-60)
  
# ending the filling of the color
t.end_fill()

Aporte :

100
#113300

Producción :

Estrella llena de color de dibujo:

# draw color filled star in turtle
  
import turtle
  
# creating turtle pen
t = turtle.Turtle()
  
# taking input for the side of the star
s = int(input("Enter the length of the side of the star: "))
  
# taking the input for the color
col = input("Enter the color name or hex value of color(# RRGGBB): ")
  
# set the fillcolor
t.fillcolor(col)
  
# start the filling color
t.begin_fill()
  
# drawing the star of side s
for _ in range(5):
  t.forward(s)
  t.right(144)
  
# ending the filling of color
t.end_fill()

Aporte :

200
#551122

Producción :

Círculo relleno de color de dibujo:

# draw color filled circle in turtle
  
import turtle
  
# creating turtle pen
t = turtle.Turtle()
  
# taking input for the radius of the circle
r = int(input("Enter the radius of the circle: "))
  
# taking the input for the color
col = input("Enter the color name or hex value of color(# RRGGBB): ")
  
# set the fillcolor
t.fillcolor(col)
  
# start the filling color
t.begin_fill()
  
# drawing the circle of radius r
t.circle(r)
  
# ending the filling of the color
t.end_fill()

Aporte :

100
blue

Producción :

Publicación traducida automáticamente

Artículo escrito por iamjpsonkar y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *