Primer Commit. Codigo escritoo en el añoo 2022
This commit is contained in:
0
universo/__init__.py
Executable file
0
universo/__init__.py
Executable file
BIN
universo/__pycache__/__init__.cpython-39.pyc
Executable file
BIN
universo/__pycache__/__init__.cpython-39.pyc
Executable file
Binary file not shown.
BIN
universo/__pycache__/cielo.cpython-39.pyc
Executable file
BIN
universo/__pycache__/cielo.cpython-39.pyc
Executable file
Binary file not shown.
BIN
universo/__pycache__/estrellas.cpython-39.pyc
Executable file
BIN
universo/__pycache__/estrellas.cpython-39.pyc
Executable file
Binary file not shown.
29
universo/cielo.py
Executable file
29
universo/cielo.py
Executable file
@@ -0,0 +1,29 @@
|
||||
#Importar los componentes necesarios
|
||||
import tkinter as tk
|
||||
|
||||
#Importar los componentes que contienen las clases que hemos creado
|
||||
import universo.estrellas
|
||||
|
||||
#Crear una variable globlal para la cantidad de estrellas en pantalla.
|
||||
CANTIDAD_ESTRELLAS = 2
|
||||
|
||||
# Definir la clase componentes
|
||||
class componentes(tk.Canvas):
|
||||
# Definir la clase inicial, que recibira los parametros desde donde sea inicializada.
|
||||
def __init__(self, *args, **kwargs):
|
||||
tk.Canvas.__init__(self, *args, **kwargs) # Crear un objeto tkinter con los parametros iniciales
|
||||
self.estrellas = [] # Establecer un arreglo de «estrellas» obtenidas de la clase «universo.estrellas.componentes»
|
||||
self.crear_estrellas() # Llamar a funcion crear_estrellas() al inicializar la clase
|
||||
|
||||
# Funcion para crear estrellas
|
||||
def crear_estrellas(self):
|
||||
for i in range(CANTIDAD_ESTRELLAS): # Crea un arreglo de instancias de universo.estrellas.componentes de acuerdo a la cantidad definida en la variable CANTIDAD_ESTRELLAS
|
||||
self.estrellas.append(universo.estrellas.componentes(self))
|
||||
return
|
||||
|
||||
#Funcion para actualizar la posicion de las estrellas en el cielo
|
||||
def actualizar_pantalla(self):
|
||||
for i in self.estrellas:
|
||||
i.actualizar()
|
||||
return
|
||||
|
||||
43
universo/estrellas.py
Executable file
43
universo/estrellas.py
Executable file
@@ -0,0 +1,43 @@
|
||||
import tkinter as tk
|
||||
import random
|
||||
|
||||
CANTIDAD_ESTRELLAS = 2
|
||||
VELOCIDAD_RADIO=SPEED_GEARS = [i/10.0 for i in range(-10,-2)]+[i/10.0 for i in range(2,10)]
|
||||
RADIO=25
|
||||
COLOR_ESTRELLA = "yellow"
|
||||
|
||||
|
||||
|
||||
class componentes:
|
||||
def __init__(self, padre):
|
||||
self.padre = padre
|
||||
self.comenzar_movimiento()
|
||||
self.crear_circulo_pequeño()
|
||||
|
||||
def comenzar_movimiento(self):
|
||||
self.x1 = self.padre.winfo_width()/2
|
||||
self.y1 = self.padre.winfo_height()/2
|
||||
self.velocity_x = random.choice(VELOCIDAD_RADIO)
|
||||
self.velocity_y = random.choice(VELOCIDAD_RADIO)
|
||||
return
|
||||
|
||||
def crear_circulo_pequeño(self):
|
||||
x1=self.x1
|
||||
y1=self.y1
|
||||
x2,y2=x1+RADIO, y1+RADIO
|
||||
self.estrella = self.padre.create_oval(x1,y1,x2,y2, fill=COLOR_ESTRELLA)
|
||||
return
|
||||
|
||||
def parar_movimiento(self):
|
||||
self.padre.coords(self.estrella, self.x1,self.y1,self.x1+RADIO,self.y1+RADIO)
|
||||
self.comenzar_movimiento()
|
||||
return
|
||||
|
||||
def actualizar(self):
|
||||
self.padre.move(self.estrella, self.velocity_x, self.velocity_y)
|
||||
x,y = self.padre.coords(self.estrella)[:2]
|
||||
if x<0 or x>1500:
|
||||
self.parar_movimiento()
|
||||
elif y<0 or y>1000:
|
||||
self.parar_movimiento()
|
||||
return
|
||||
Reference in New Issue
Block a user