from clases import Boton
from random import random
from clases import OLED
import array
boton2 = Boton(19)
oled = OLED()
# Clase Punto
class Punto():
# Constructor
def __init__(self, x, y, vx, vy):
self.x = x
self.y = y
self.vx = vx
self.vy = vy
# Calcula la siguiente posición central
def mueve(self):
if (self.x > (oled.width)) or ( self.x < 0 ):
self.vx = -self.vx
if (self.y > (oled.height)) or ( self.y < 0 ):
self.vy = -self.vy
self.x += self.vx
self.y += self.vy
# Borra el elemento anterior y muestra el siguiente
def muestra(self):
oled.pixel(int(self.x),int(self.y),0)
self.mueve() # Actualiza posición
oled.pixel(int(self.x),int(self.y),1)
class Caracter(Punto):
# Constructor
def __init__(self, x, y, vx, vy):
super().__init__(x, y, vx, vy)
# Borra el elemento anterior y muestra el siguiente
def muestra(self):
oled.text("A", int(self.x), int(self.y), 0)
self.mueve() # Actualiza posición
oled.text("A", int(self.x), int(self.y), 1)
# --- Programa principal ---
oled.fill(0)
caracter = []
for i in range(20):
caracter.append(Caracter(0, 0, 2*random(), 2*random()))
while True:
for i in range(len(caracter)):
caracter[i].muestra()
oled.show()
from clases import Boton
from random import random
from clases import OLED
import array
boton2 = Boton(19)
oled = OLED()