método turtle.color() en Python

El módulo de Turtle proporciona primitivos de gráficos de Turtle, tanto en formas orientadas a objetos como orientadas a procedimientos. Debido a que usa Tkinter para los gráficos subyacentes, necesita una versión de Python instalada con soporte Tk.

Turtle.color()

Este método se utiliza para cambiar el color de la Turtle. El color predeterminado es negro.

Sintaxis:

turtle.color(*args)

Parámetros:

Formato  Argumentos  Descripción
 Turtle.color(string de colores)  string de colores  Una string de nombre de color como «rojo», «verde», etc.
 Turtle.color( (r, g, b) )   (r, g, b)  Una tupla de tres valores r, g y b usando el código de color rgb
 Turtle.color( r, g, b )  r, g, b  Tres valores r, g y b usando el código de color rgb

A continuación se muestra la implementación del método anterior con algunos ejemplos:

Ejemplo 1 :

Python3

# importing package
import turtle
 
 
# use forward by 50 (default = black)
turtle.forward(50)
 
# change the color of turtle
turtle.color("red")
 
# use forward by 50 (color = red)
turtle.forward(50)

Producción :

Ejemplo 2:

Python3

# importing package
import turtle
 
 
# use forward by 100 (default = black)
turtle.forward(100)
 
# change the color of turtle
turtle.color("red")
 
# use forward by 100 in 90 degrees
# right (color = red)
turtle.right(90)
turtle.forward(100)
 
# change the color of turtle
turtle.color((41,41,253))
 
# use forward by 100 in 90 degrees
# right (color = blue)
turtle.right(90)
turtle.forward(100)
 
# change the color of turtle
turtle.color(41,253,41)
 
# use forward by 100 in 90 degrees
# right (color = green)
turtle.right(90)
turtle.forward(100)

Producción :

Publicación traducida automáticamente

Artículo escrito por deepanshu_rustagi 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 *