diff --git a/effects/light-clock.json b/effects/light-clock.json new file mode 100644 index 00000000..10a1c705 --- /dev/null +++ b/effects/light-clock.json @@ -0,0 +1,8 @@ +{ + "name" : "Light clock", + "script" : "light-clock.py", + "args" : + { + "show_seconds" : true + } +} diff --git a/effects/light-clock.py b/effects/light-clock.py new file mode 100644 index 00000000..aafdeb05 --- /dev/null +++ b/effects/light-clock.py @@ -0,0 +1,54 @@ +import hyperion, time, datetime + +# Get the parameters +showSeconds = bool(hyperion.args.get('show_seconds', True)) +centerX = int(round(hyperion.imageWidth)/2) +centerY = int(round(float(hyperion.imageHeight)/2)) + +colorsSecond = bytearray([ + 0, 255,255,0,255, + 5, 255,255,0,255, + 30, 0,0,0,0, +]) + +colorsMinute = bytearray([ + 0, 0,255,0,255, + 5, 0,255,0,250, + 90, 0,0,0,0, + +]) + +colorsHour = bytearray([ + 0, 0,0,255,255, + 10, 0,0,255,255, + 127, 0,0,196,127, + 255, 0,0,196,5, +]) + +colorsHourTop = bytearray([ + 0, 0,0,255,250, + 10, 0,0,255,128, + 20, 0,0,0,0, +]) + +# effect loop +while not hyperion.abort(): + now = datetime.datetime.now() + + angleH = 449 - 30*(now.hour if now.hour<12 else now.hour-12) + angleM = 449 - 6*now.minute + angleS = 449 - 6*now.second + + angleH -= 0 if angleH<360 else 360 + angleM -= 0 if angleM<360 else 360 + angleS -= 0 if angleS<360 else 360 + + hyperion.imageSolidFill(127,127,127); + hyperion.imageCanonicalGradient(centerX, centerY, angleH, colorsHour) + hyperion.imageCanonicalGradient(centerX, centerY, angleM, colorsMinute) + hyperion.imageCanonicalGradient(centerX, centerY, angleH, colorsHourTop) + if showSeconds: + hyperion.imageCanonicalGradient(centerX, centerY, angleS, colorsSecond) + + hyperion.imageShow() + time.sleep(0.01 ) diff --git a/effects/rainbow-swirl.py b/effects/rainbow-swirl.py index 6aeaaa56..94f7877a 100644 --- a/effects/rainbow-swirl.py +++ b/effects/rainbow-swirl.py @@ -14,15 +14,22 @@ increment = -1 if reverse else 1 # table of stop colors for rainbow gradient, first is the position, next rgb, all values 0-255 rainbowColors = bytearray([ - 0 ,255,0 ,0, - 25 ,255,230,0, - 63 ,255,255,0, - 100,0 ,255,0, - 127,0 ,255,200, - 159,0 ,255,255, - 191,0 ,0 ,255, - 224,255,0 ,255, - 255,255,0 ,127, + 0 ,255,0 ,0, 255, + 25 ,255,230,0, 255, + 63 ,255,255,0, 255, + 100,0 ,255,0, 255, + 127,0 ,255,200, 255, + 159,0 ,255,255, 255, + 191,0 ,0 ,255, 255, + 224,255,0 ,255, 255, + 255,255,0 ,127, 255, + #0, 255, 0, 0, 255, + #42, 255, 255, 0, 255, + #85, 0, 255, 0, 255, + #128, 0, 255, 255, 255, + #170, 0, 0, 255, 255, + #212, 255, 0, 255, 255, + #255, 255, 0, 0, 255, ]) # effect loop diff --git a/libsrc/effectengine/Effect.cpp b/libsrc/effectengine/Effect.cpp index d5707e5d..d5118c32 100644 --- a/libsrc/effectengine/Effect.cpp +++ b/libsrc/effectengine/Effect.cpp @@ -27,6 +27,7 @@ PyMethodDef Effect::effectMethods[] = { {"imageShow", Effect::wrapImageShow, METH_NOARGS, "set current effect image to hyperion core."}, {"imageCanonicalGradient", Effect::wrapImageCanonicalGradient, METH_VARARGS, ""}, {"imageRadialGradient" , Effect::wrapImageRadialGradient, METH_VARARGS, ""}, + {"imageSolidFill" , Effect::wrapImageSolidFill, METH_VARARGS, ""}, // {"imageSetPixel",Effect::wrapImageShow, METH_VARARGS, "set pixel color of image"}, // {"imageGetPixel",Effect::wrapImageShow, METH_VARARGS, "get pixel color of image"}, {NULL, NULL, 0, NULL} @@ -454,8 +455,9 @@ PyObject* Effect::wrapImageCanonicalGradient(PyObject *self, PyObject *args) { if (PyByteArray_Check(bytearray)) { - int length = PyByteArray_Size(bytearray); - if (length % 4 == 0) + const int length = PyByteArray_Size(bytearray); + const unsigned arrayItemLength = 5; + if (length % arrayItemLength == 0) { QPainter * painter = effect->_painter; @@ -463,25 +465,25 @@ PyObject* Effect::wrapImageCanonicalGradient(PyObject *self, PyObject *args) QConicalGradient gradient(QPoint(centerX,centerY), angle ); char * data = PyByteArray_AS_STRING(bytearray); - for (int idx=0; idxfillRect(myQRect, gradient); return Py_BuildValue(""); } else { - PyErr_SetString(PyExc_RuntimeError, "Length of bytearray argument should multiple of 4"); + PyErr_SetString(PyExc_RuntimeError, "Length of bytearray argument should multiple of 5"); return nullptr; } } @@ -582,6 +584,49 @@ PyObject* Effect::wrapImageRadialGradient(PyObject *self, PyObject *args) } } +PyObject* Effect::wrapImageSolidFill(PyObject *self, PyObject *args) +{ + Effect * effect = getEffect(); + + int argCount = PyTuple_Size(args); + int r, g, b; + int a = 255; + int startX = 0; + int startY = 0; + int width = effect->_imageSize.width(); + int height = effect->_imageSize.height(); + + bool argsOK = false; + + if ( argCount == 8 && PyArg_ParseTuple(args, "iiiiiiii", &startX, &startY, &width, &height, &r, &g, &b, &a) ) + { + argsOK = true; + } + if ( argCount == 7 && PyArg_ParseTuple(args, "iiiiiii", &startX, &startY, &width, &height, &r, &g, &b) ) + { + argsOK = true; + } + if ( argCount == 4 && PyArg_ParseTuple(args, "iiii",&r, &g, &b, &a) ) + { + argsOK = true; + } + if ( argCount == 3 && PyArg_ParseTuple(args, "iii",&r, &g, &b) ) + { + argsOK = true; + } + + if (argsOK) + { + QRect myQRect(startX,startY,width,height); + effect->_painter->fillRect(myQRect, QColor(r,g,b,a)); + return Py_BuildValue(""); + } + else + { + return nullptr; + } +} + Effect * Effect::getEffect() { diff --git a/libsrc/effectengine/Effect.h b/libsrc/effectengine/Effect.h index 12672f26..4a475485 100644 --- a/libsrc/effectengine/Effect.h +++ b/libsrc/effectengine/Effect.h @@ -58,7 +58,8 @@ private: static PyObject* wrapImageShow(PyObject *self, PyObject *args); static PyObject* wrapImageCanonicalGradient(PyObject *self, PyObject *args); static PyObject* wrapImageRadialGradient(PyObject *self, PyObject *args); - + static PyObject* wrapImageSolidFill(PyObject *self, PyObject *args); + static Effect * getEffect(); #if PY_MAJOR_VERSION >= 3