From de5bcb763e3a49d84b331e9c6313d60053e75305 Mon Sep 17 00:00:00 2001 From: egutierrez Date: Sun, 15 Dec 2024 22:48:01 +0100 Subject: [PATCH] Add initial project files including .gitignore, VSCode settings, and turtle graphics scripts --- .gitignore | 3 ++ .vscode/settings.json | 22 ++++++++++++++ pruebas_turtle.py | 71 +++++++++++++++++++++++++++++++++++++++++++ turtle_2.py | 23 ++++++++++++++ 4 files changed, 119 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 pruebas_turtle.py create mode 100644 turtle_2.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..790ee3d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +venv +env +.env \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5be0973 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,22 @@ +{ + "workbench.colorCustomizations": { + "activityBar.activeBackground": "#93e6fc", + "activityBar.background": "#93e6fc", + "activityBar.foreground": "#15202b", + "activityBar.inactiveForeground": "#15202b99", + "activityBarBadge.background": "#fa45d4", + "activityBarBadge.foreground": "#15202b", + "commandCenter.border": "#15202b99", + "sash.hoverBorder": "#93e6fc", + "statusBar.background": "#61dafb", + "statusBar.foreground": "#15202b", + "statusBarItem.hoverBackground": "#2fcefa", + "statusBarItem.remoteBackground": "#61dafb", + "statusBarItem.remoteForeground": "#15202b", + "titleBar.activeBackground": "#61dafb", + "titleBar.activeForeground": "#15202b", + "titleBar.inactiveBackground": "#61dafb99", + "titleBar.inactiveForeground": "#15202b99" + }, + "peacock.color": "#61dafb" +} \ No newline at end of file diff --git a/pruebas_turtle.py b/pruebas_turtle.py new file mode 100644 index 0000000..c239dfa --- /dev/null +++ b/pruebas_turtle.py @@ -0,0 +1,71 @@ +import turtle +import random + + +# Función para dibujar un cuadrado +def cuadrado(t, size): + for _ in range(4): # Dibujar un cuadrado + t.forward(size) + t.right(90) + +def triangulo(t, size): + for _ in range(3): # Dibujar un cuadrado + t.forward(size) + t.right(120) + + +def estrella(t, size): + for _ in range(5): # Una estrella tiene 5 puntos + t.forward(size) + t.right(144) # Ángulo para formar una estrella + +def infinito(t, size): + for _ in range(2): + t.circle(size, 90) + t.circle(size // 2, 90) + + +def flor(t, petalos, radio): + for _ in range(petalos): + t.circle(radio) + t.right(360 / petalos) + +def estrella_multipuntas(t, size, puntas): + for _ in range(puntas): + t.forward(size) + t.right(180 - (180 / puntas)) + +def color_aleatorio(): + """Genera un color RGB aleatorio.""" + r = random.randint(0, 255) + g = random.randint(0, 255) + b = random.randint(0, 255) + return (r, g, b) + + +# Función para dibujar cuadrados rotando +def draw_rotating_squares(): + import turtle # Aseguramos importar turtle dentro de la función si se usa de forma independiente + + # Configurar la pantalla y la tortuga + screen = turtle.Screen() + t = turtle.Turtle() + + # Inicializar la longitud del lado + length = 50 # Tamaño inicial del cuadrado + + # Aumentar la velocidad al máximo + t.speed('fastest') + + # Dibujar 60 cuadrados, aumentando el tamaño y girando 5 grados después de cada uno + for _ in range(1000): + flor(t,6, length) # Llamar a la función para dibujar un triángulo + t.right(10) # Girar 5 grados después de cada figura + length += 10 # Aumentar el tamaño del triángulo + + # Cerrar la ventana al hacer clic + screen.exitonclick() + + +# Ejecutar la función +draw_rotating_squares() diff --git a/turtle_2.py b/turtle_2.py new file mode 100644 index 0000000..c10d6d7 --- /dev/null +++ b/turtle_2.py @@ -0,0 +1,23 @@ +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()