mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
update
This commit is contained in:
parent
7cec010df5
commit
fa71d14c9f
@ -5,12 +5,13 @@ import random
|
||||
|
||||
min_len = int(hyperion.args.get('min_len', 3))
|
||||
max_len = int(hyperion.args.get('max_len', 3))
|
||||
height = int(hyperion.args.get('height', 8))
|
||||
#iHeight = int(hyperion.args.get('iHeight', 8))
|
||||
trails = int(hyperion.args.get('int', 8))
|
||||
sleepTime = float(hyperion.args.get('speed', 1)) / 1000.0
|
||||
color = list(hyperion.args.get('color', (255,255,255)))
|
||||
randomise = bool(hyperion.args.get('random', False))
|
||||
whidth = hyperion.ledCount / height
|
||||
iWidth = hyperion.imageWidth()
|
||||
iHeight = hyperion.imageHeight()
|
||||
|
||||
class trail:
|
||||
def __init__(self):
|
||||
@ -48,17 +49,17 @@ for i in range(trails):
|
||||
r = {'exec': trail()}
|
||||
|
||||
if randomise:
|
||||
col = (random.uniform(0.1, 1.0), random.uniform(0.1, 1.0), random.uniform(0.1, 1.0))
|
||||
col = (random.uniform(0.0, 1.0),1,1)
|
||||
else:
|
||||
col = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
|
||||
|
||||
r['exec'].start(
|
||||
random.randint(0, whidth),
|
||||
random.randint(0, height),
|
||||
random.randint(0, iWidth),
|
||||
random.randint(0, iHeight),
|
||||
random.uniform(0.2, 0.8),
|
||||
col,
|
||||
random.randint(min_len, max_len),
|
||||
height
|
||||
iHeight
|
||||
)
|
||||
tr.append(r)
|
||||
|
||||
@ -70,21 +71,21 @@ while not hyperion.abort():
|
||||
r['x'], r['data'], c = r['exec'].getdata()
|
||||
if c:
|
||||
if randomise:
|
||||
col = (random.uniform(0.1, 1.0), random.uniform(0.1, 1.0), random.uniform(0.1, 1.0))
|
||||
col = (random.uniform(0.0, 1.0),1,1)
|
||||
else:
|
||||
col = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
|
||||
|
||||
r['exec'].start(
|
||||
random.randint(0, whidth),
|
||||
random.randint(0, height),
|
||||
random.randint(0, iWidth),
|
||||
random.randint(0, iHeight),
|
||||
random.uniform(0.2, 0.8),
|
||||
col,
|
||||
random.randint(min_len, max_len),
|
||||
height
|
||||
iHeight
|
||||
)
|
||||
|
||||
for y in range(0, height):
|
||||
for x in range(0, whidth):
|
||||
for y in range(0, iHeight):
|
||||
for x in range(0, iWidth):
|
||||
for r in tr:
|
||||
if x == r['x']:
|
||||
led = bytearray(r['data'][y])
|
||||
@ -92,6 +93,6 @@ while not hyperion.abort():
|
||||
led = bytearray((0,0,0))
|
||||
ledData += led
|
||||
|
||||
hyperion.setImage(whidth,height,ledData)
|
||||
hyperion.setImage(iWidth,iHeight,ledData)
|
||||
time.sleep(sleepTime)
|
||||
|
||||
|
@ -32,13 +32,14 @@ PyMethodDef Effect::effectMethods[] = {
|
||||
{"imageDrawLine" , Effect::wrapImageDrawLine , METH_VARARGS, ""},
|
||||
{"imageDrawPoint" , Effect::wrapImageDrawPoint , METH_VARARGS, ""},
|
||||
{"imageDrawRect" , Effect::wrapImageDrawRect , METH_VARARGS, ""},
|
||||
{"imageDrawPolygon" , Effect::wrapImageDrawPolygon , METH_VARARGS, ""},
|
||||
{"imageDrawPie" , Effect::wrapImageDrawPie , METH_VARARGS, ""},
|
||||
{"imageSetPixel" , Effect::wrapImageSetPixel , METH_VARARGS, "set pixel color of image"},
|
||||
{"imageGetPixel" , Effect::wrapImageGetPixel , METH_VARARGS, "get pixel color of image"},
|
||||
{"imageSave" , Effect::wrapImageSave , METH_NOARGS, "adds a new background image"},
|
||||
{"imageMinSize" , Effect::wrapImageMinSize , METH_VARARGS, "sets minimal dimension of background image"},
|
||||
{"imageWidth" , Effect::wrapImageWidth , METH_NOARGS, "gets image width"},
|
||||
{"imageHeight" , Effect::wrapImageHeight , METH_NOARGS, "gets image height"},
|
||||
{"hsvF_to_rgb" , Effect::wrapHsvFtoRgb , METH_NOARGS, "convert hsvF (double) to rgb (int)"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
@ -603,6 +604,147 @@ PyObject* Effect::wrapImageRadialGradient(PyObject *self, PyObject *args)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject* Effect::wrapImageDrawPolygon(PyObject *self, PyObject *args)
|
||||
{
|
||||
Effect * effect = getEffect();
|
||||
|
||||
int argCount = PyTuple_Size(args);
|
||||
int r, g, b;
|
||||
int a = 255;
|
||||
PyObject * bytearray = nullptr;
|
||||
|
||||
bool argsOK = false;
|
||||
|
||||
if ( argCount == 4 && PyArg_ParseTuple(args, "Oiii", &bytearray, &r, &g, &b) )
|
||||
{
|
||||
argsOK = true;
|
||||
}
|
||||
|
||||
if (argsOK)
|
||||
{
|
||||
if (PyByteArray_Check(bytearray))
|
||||
{
|
||||
int length = PyByteArray_Size(bytearray);
|
||||
if (length % 2 == 0)
|
||||
{
|
||||
QVector <QPoint> points;
|
||||
char * data = PyByteArray_AS_STRING(bytearray);
|
||||
|
||||
for (int idx=0; idx<length; idx+=2)
|
||||
{
|
||||
points.append(QPoint((int)(data[idx]),(int)(data[idx+1])));
|
||||
}
|
||||
|
||||
QPainter * painter = effect->_painter;
|
||||
painter->setBrush(QBrush(QColor(r,g,b,a), Qt::SolidPattern));
|
||||
effect->_painter->drawPolygon(points, length/2);
|
||||
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_RuntimeError, "Length of bytearray argument should multiple of 2");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_RuntimeError, "Argument 1 is not a bytearray");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject* Effect::wrapImageDrawPie(PyObject *self, PyObject *args)
|
||||
{
|
||||
Effect * effect = getEffect();
|
||||
|
||||
int argCount = PyTuple_Size(args);
|
||||
int r, g, b, radius,
|
||||
int startAngle = 0;
|
||||
int spanAngle = 359;
|
||||
int a = 255;
|
||||
int centerX = 0;
|
||||
int centerY = 0;
|
||||
int width = effect->_imageSize.width();
|
||||
int height = effect->_imageSize.height();
|
||||
|
||||
bool argsOK = false;
|
||||
|
||||
if ( argCount == 9 && PyArg_ParseTuple(args, "iiiiiiiii", ¢erX, ¢erY, &radius, &startAngle, &spanAngle, &r, &g, &b, &a) )
|
||||
{
|
||||
argsOK = true;
|
||||
}
|
||||
if ( argCount == 8 && PyArg_ParseTuple(args, "iiiiiiii", ¢erX, ¢erY, &radius, &startAngle, &spanAngle, &r, &g, &b) )
|
||||
{
|
||||
argsOK = true;
|
||||
}
|
||||
//if ( argCount == 7 && PyArg_ParseTuple(args, "iiiiiiO", ¢erX, ¢erY, &radius, &startAngle, &spanAngle, &brush, &bytearray) )
|
||||
//{
|
||||
// argsOK = true;
|
||||
//}
|
||||
//if ( argCount == 5 && PyArg_ParseTuple(args, "iiiiO", ¢erX, ¢erY, &radius, &brush, &bytearray) )
|
||||
//{
|
||||
// argsOK = true;
|
||||
//}
|
||||
|
||||
if (argsOK)
|
||||
{
|
||||
QPainter * painter = effect->_painter;
|
||||
|
||||
if( argCount == 7 || argCount == 5 )
|
||||
{
|
||||
a = 0;
|
||||
if (PyByteArray_Check(bytearray))
|
||||
{
|
||||
int length = PyByteArray_Size(bytearray);
|
||||
if (length % 4 == 0)
|
||||
{
|
||||
|
||||
//QRect myQRect(startX,startY,width,height);
|
||||
//QRadialGradient gradient(QPoint(centerX,centerY), std::max(radius,0) );
|
||||
//char * data = PyByteArray_AS_STRING(bytearray);
|
||||
|
||||
//for (int idx=0; idx<length; idx+=4)
|
||||
//{
|
||||
// gradient.setColorAt(
|
||||
// ((uint8_t)data[idx])/255.0,
|
||||
// QColor(
|
||||
// (uint8_t)(data[idx+1]),
|
||||
// (uint8_t)(data[idx+2]),
|
||||
// (uint8_t)(data[idx+3])
|
||||
// ));
|
||||
}
|
||||
|
||||
//set a brush
|
||||
painter->setBrush(QBrush(Qt::green));
|
||||
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_RuntimeError, "Length of bytearray argument should multiple of 4");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_RuntimeError, "Last argument is not a bytearray");
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
QPen oldPen = painter->pen();
|
||||
QPen newPen(QColor(r,g,b,a));
|
||||
painter->setPen(newPen);
|
||||
painter->drawPie(centerX - radius, centerY - radius, centerX + radius, centerY + radius, startAngle * 16, spanAngle * 16);
|
||||
painter->setPen(oldPen);
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
PyObject* Effect::wrapImageSolidFill(PyObject *self, PyObject *args)
|
||||
{
|
||||
Effect * effect = getEffect();
|
||||
@ -837,20 +979,6 @@ PyObject* Effect::wrapImageHeight(PyObject *self, PyObject *args)
|
||||
return Py_BuildValue("i", effect->_imageSize.height());
|
||||
}
|
||||
|
||||
PyObject* Effect::wrapHsvFtoRgb(PyObject *self, PyObject *args)
|
||||
{
|
||||
int argCount = PyTuple_Size(args);
|
||||
double h, s, v, a;
|
||||
|
||||
if ( argCount == 3 && PyArg_ParseTuple(args, "ddd", &h, &s, &v) )
|
||||
{
|
||||
QColor cC;
|
||||
cC.fromHsvF(h,s,v,a = 1.0).toRgb();
|
||||
return Py_BuildValue("iii", cC.red(), cC.green(), cC.blue());
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Effect * Effect::getEffect()
|
||||
{
|
||||
// extract the module from the runtime
|
||||
|
Loading…
Reference in New Issue
Block a user