24 lines
790 B
Python
24 lines
790 B
Python
import turtle
|
|
from random import randint
|
|
|
|
# Configurar la velocidad de la tortuga y ocultar el trazo inicial
|
|
t = turtle.Turtle()
|
|
t.speed('fastest') # Velocidad más rápida
|
|
|
|
# Configurar el tamaño de la pantalla
|
|
screen = turtle.Screen()
|
|
screen.setup(width=500, height=500) # Dimensiones de la pantalla
|
|
screen.bgcolor("lightblue") # Fondo claro para mejor visibilidad
|
|
|
|
def wander():
|
|
"""Movimiento aleatorio continuo dentro de un área limitada."""
|
|
while True:
|
|
t.forward(3) # Avanzar 3 unidades
|
|
|
|
# Comprobar si la tortuga alcanza los límites de la pantalla
|
|
if t.xcor() > 200 or t.xcor() < -200 or t.ycor() > 200 or t.ycor() < -200:
|
|
t.left(randint(90, 180)) # Girar un ángulo aleatorio entre 90 y 180 grados
|
|
|
|
# Ejecutar la función
|
|
wander()
|