Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from ._baseclass import ArtBaseClass
from math import sqrt
from opc.hue import hsvToRgb
class Art(ArtBaseClass):
description = "Slow transition of hues across the display"
def __init__(self, matrix, config):
self.base = 0
def start(self, matrix):
pass
def refresh(self, matrix):
self.base += 4
h = matrix.height - 1
for x in range(matrix.width):
hue = (self.base+32*x) / (sqrt(matrix.numpix) * 64.0)
for y in range(matrix.height):
from .. _baseclass import ArtBaseClass
from opc.matrix import OPCMatrix
from art.utils.diamondsquare import DiamondSquareAlgorithm
DFLTTICKS = 350
class DiamondSquare(ArtBaseClass):
def __init__(self, matrix, generate, maxticks=DFLTTICKS, interpolate=True):
self.diamond = DiamondSquareAlgorithm(matrix.width, matrix.height)
self.matrix = OPCMatrix(matrix.width, matrix.height, None)
self.generate = generate
self.ticks = 0
self.maxticks = maxticks
self.interpolate = interpolate
def start(self, matrix):
matrix.clear()
def refresh(self, matrix):
# ticks allow us to keep track of how much time has passed
# since the last generation. This gives us opportunity for
from .. _baseclass import ArtBaseClass
from math import fmod
from random import random
from opc.hue import hsvToRgb
class Bilinear(ArtBaseClass):
def __init__(self, matrix, config):
self.cornerValueDeltas = [
self._delta(), self._delta(), self._delta(), self._delta(),
]
self.cornerValues = [
.1, .2, .3, .4,
]
def _delta(self):
return 0.001 + random() * 0.007
def start(self, matrix):
matrix.clear()
from .. _baseclass import ArtBaseClass
from opc.text import OPCText, typeface_bbc
class ScrollText(ArtBaseClass):
description = "Scroll text across the display"
fg = None
bg = None
def __init__(self, matrix, config):
self.config = config
self._initText()
self.thisMessage = self._getText()
self.nextMessage = self._getText()
self.typeface = OPCText(typeface_bbc)
self.base = 0
def _initText(self):
from .. _baseclass import ArtBaseClass
from random import random, uniform
from opc.matrix import HQ
from .. utils.pen import Pen
PENS = 4
SCALE = 3
SIZE = 6
class Blobs(ArtBaseClass):
def __init__(self, matrix, config):
with HQ(matrix):
self.pens = []
for i in range(PENS):
dx = 1 if (i/2) % 2 == 0 else -1
dy = 1 if i % 2 == 0 else -1
pen = Pen(
matrix.width, matrix.height,
matrix.width/4 + random()*matrix.width/2,
matrix.height/4 + random()*matrix.height/2,
dx=dx, dy=dy, radius=matrix.smallest/SIZE,
huedelta=uniform(0.005, 0.001),
)
pen.setBumpStrategy(pen.reverse, x=True, y=True)
self.pens.append(pen)
if self.y > self.mid:
return False
if self.x-1 <= value <= self.x+1:
return True
return False
def next(self, matrix):
matrix.drawPixel(self.x, self.y, self.color)
self.y += 1
return self.y < matrix.height
class Art(ArtBaseClass):
description = "Pixels floating upwards with a trail"
def __init__(self, matrix, config):
self.count = matrix.width/3
self.color = getColorGen(step=0.015, hue=random())
self.y = matrix.height
def start(self, matrix):
self.instances = []
def _vote(self, matrix):
while True:
value = randint(0, matrix.width-1)
if any([instance.vote(value) for instance in self.instances]):
continue
def add(self, matrix, x, y):
x0, y0 = self.points[self.head]
matrix.drawPixel(x0, y0, BLACK)
self.points[self.head] = (x, y)
self.head = (self.head + 1) % self.length
DELTA_AMP = 0.09
DELTA_ANG = 0.033
DELTA_HUE = 0.006
TRAIN_LEN = 16
class Art(ArtBaseClass):
description = "Color cascade (needs tuning for > 32x32)"
def __init__(self, matrix, config):
self.hue = 0
self.ang = 0
self.amp = 0
self.mult = 1+sqrt(matrix.numpix/32)/90
self.train = ClearTrain(TRAIN_LEN)
def start(self, matrix):
matrix.clear()
def refresh(self, matrix):
# this relies on the fact that the pixels we seed get multiplied and
# overfow the uint8 in intresting ways
self.delta = random()*0.5+0.2
def refresh(self, matrix):
self.x += self.delta
self.y += self.delta
c1 = self.x/16
c2 = self.y/8
c3 = (self.x+self.y)/16
c4 = np.sqrt((self.x*self.x)+(self.y*self.y))/8
channel = np.sum(np.sin(c) for c in (c1, c2, c3, c4))
return np.fmod(np.fabs(1+channel/2), 1.0)
class Art(ArtBaseClass):
description = "Plasma by RGB channel"
def __init__(self, matrix, config):
with HQ(matrix):
self.channels = [Channel(matrix) for channel in range(3)]
def start(self, matrix):
matrix.hq()
def refresh(self, matrix):
channels = [255*channel.refresh(matrix) for channel in self.channels]
for y in range(matrix.height):
for x in range(matrix.width):
from ._baseclass import ArtBaseClass
from opc.nphue import h_to_rgb
import numpy as np
class Art(ArtBaseClass):
description = "Classic plasma (almost)"
def __init__(self, matrix, config):
ones = np.ones(matrix.numpix).reshape((matrix.height, matrix.width))
self.x = ones*np.arange(matrix.width)
self.y = np.flipud(np.rot90(np.rot90(ones)*np.arange(matrix.height)))
self.base = 128000
def start(self, matrix):
pass
def _dist(self, a, b, c, d):
return np.sqrt((c-a)*(c-a)+(d-b)*(d-b))
def move(self):
self.x += self.h
self.y += self.v
# take into account bouncing off top or bottom while the
# ball is in flight
if self.y <= 0:
self.v = abs(self.v)
elif self.y >= self.height-1:
self.v = -abs(self.v)
def display(self, matrix):
matrix.drawPixel(self.x, self.y, rgb["white"])
class Art(ArtBaseClass):
description = "Automated pong"
def __init__(self, matrix, config):
self.ball = Ball(matrix.width, matrix.height)
self.net = Net()
self.players = {}
for left in [True, False]:
self.players[left] = Player(matrix.width, matrix.height, left)
self._newGame()
def start(self, matrix):
matrix.setFirmwareConfig(nointerp=True)