Desenhe objetos em movimento usando Turtle em Python
Pré-requisito: Princípios básicos da tartaruga Python
Tartaruga é um módulo embutido em python. Oferece desenho em tela (cartolina) e tartaruga (caneta). Para desenhar algo na tela, precisamos mover a tartaruga. Para mover a tartaruga, existem algumas funções, ou seja, para a frente(), para trás(), etc.
1.) Mova o objeto (bola):
As seguintes etapas são usadas:
- Pacote de importação da tartaruga.
- Defina a tela com dimensões e cores.
- Dê forma ao objeto tartaruga com cor.
- Forme o objeto (bola - feita de um círculo colorido).
- Chame a função para fazer objeto repetidamente e limpe a tela.
Abaixo está a implementação:
# import turtle package
import turtle
# function for movement of an object
def moving_object(move):
# to fill the color in ball
move.fillcolor('orange')
# start color filling
move.begin_fill()
# draw circle
move.circle(20)
# end color filling
move.end_fill()
# Driver Code
if __name__ == "__main__" :
# create a screen object
screen = turtle.Screen()
# set screen size
screen.setup(600,600)
# screen background color
screen.bgcolor('green')
# screen updaion
screen.tracer(0)
# create a turtle object object
move = turtle.Turtle()
# set a turtle object color
move.color('orange')
# set turtle object speed
move.speed(0)
# set turtle object width
move.width(2)
# hide turtle object
move.hideturtle()
# turtle object in air
move.penup()
# set initial position
move.goto(-250, 0)
# move turtle object to surface
move.pendown()
# infinite loop
while True :
# clear turtle work
move.clear()
# call function to draw ball
moving_object(move)
# update screen
screen.update()
# forward motion by turtle object
move.forward(0.5)
As postagens do blog Acervo Lima te ajudaram? Nos ajude a manter o blog no ar!
Faça uma doação para manter o blog funcionando.
70% das doações são no valor de R$ 5,00...
Diógenes Lima da Silva