Пример #1
0
void Rain::draw(RGBMatrix &matrix)
{
	// fade out the whole board
	for(int i = 0 ; i < LED_ROWS ; i++)
		for(int j = 0 ; j < LED_COLS ; j++)
			matrix.blend(i, j, 16, 0, 0, 0);

	// draw the new positions
	for(int i = 0 ; i < num_drops ; i++)
	{
		const float px = drops[i][0];
		const float py = drops[i][1];

		const int x = px;
		const int y = py;
/*
		const int xf = (px - x) * 256;
		const int yf = (py - y) * 256;

		matrix.blend(x+0, y+0, sqrt((256 - xf)*(256-yf)), colors[i]);
		matrix.blend(x+0, y+1, sqrt((256 - xf)*(yf)), colors[i]);
		matrix.blend(x+1, y+0, sqrt((xf)*(256-yf)), colors[i]);
		matrix.blend(x+1, y+1, sqrt((xf)*(yf)), colors[i]);
*/
		matrix.blend(x+0, y+0, 64, colors[i]);
	}
}
Пример #2
0
void VCMatrix::slotAnimationChanged(QString name)
{
    RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
    if (matrix == NULL || mode() == Doc::Design)
        return;

    RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, name);
    matrix->setAlgorithm(algo);
    if (instantChanges() == true)
        matrix->calculateColorDelta();
}
Пример #3
0
void VCMatrix::slotEndColorChanged(QRgb color)
{
    QColor col(color);
    QPixmap px(42, 42);
    px.fill(col);
    m_endColorButton->setIcon(px);

    RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
    if (matrix == NULL || mode() == Doc::Design)
        return;

    matrix->setEndColor(col);
    if (instantChanges() == true)
        matrix->calculateColorDelta();
}
Пример #4
0
void Pixels::draw(RGBMatrix &matrix)
{
	// interpolate from our last packet to the new packet
	// over the time frame in the packet
	long now = millis();
	long rx_delta = now - rx_millis;
	Serial.println(rx_delta);
	int blend = 0;
	if (rx_delta > pixels.blend_time)
	{
		blend = 255;
	} else
	if (rx_delta < 0)
	{
		blend = 0;
	} else {
		blend = (255 * rx_delta) / pixels.blend_time;
	}

	unsigned offset = 0;
	for(int row = 0 ; row < LED_ROWS ; row++)
	{
		for(int col = 0 ; col < LED_COLS ; col++, offset++)
		{
			int r = pixels.pixels[3*offset + 0];
			int g = pixels.pixels[3*offset + 1];
			int b = pixels.pixels[3*offset + 2];
			matrix.blend(row, col, blend, r, g, b);
		}
	}
}
Пример #5
0
void VCMatrix::slotCustomControlClicked()
{
    QPushButton *btn = qobject_cast<QPushButton*>(sender());
    VCMatrixControl *control = m_controls[btn];
    if (control != NULL)
    {
        RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
        if (matrix == NULL || mode() == Doc::Design)
            return;

        if (control->m_type == VCMatrixControl::StartColor)
        {
            QPixmap px(42, 42);
            px.fill(control->m_color);

            m_startColorButton->setIcon(px);
            matrix->setStartColor(control->m_color);
            matrix->calculateColorDelta();
        }
        else if (control->m_type == VCMatrixControl::EndColor)
        {
            QPixmap px(42, 42);
            px.fill(control->m_color);

            m_endColorButton->setIcon(px);
            matrix->setEndColor(control->m_color);
            matrix->calculateColorDelta();
        }
        else if (control->m_type == VCMatrixControl::Animation)
        {
            RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, control->m_resource);
            matrix->setAlgorithm(algo);
            if (instantChanges() == true)
                matrix->calculateColorDelta();
        }
        else if (control->m_type == VCMatrixControl::Text)
        {
            RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, "Text");
            RGBText* text = static_cast<RGBText*> (algo);
            text->setText(control->m_resource);
            matrix->setAlgorithm(algo);
            if (instantChanges() == true)
                matrix->calculateColorDelta();
        }
    }
}
Пример #6
0
void RGBMatrix_Test::copy()
{
    RGBMatrix mtx(m_doc);
    mtx.setStartColor(Qt::magenta);
    mtx.setEndColor(Qt::yellow);
    mtx.setFixtureGroup(0);
    mtx.setAlgorithm(RGBAlgorithm::algorithm(m_doc, "Stripes"));
    QVERIFY(mtx.algorithm() != NULL);

    RGBMatrix* copyMtx = qobject_cast<RGBMatrix*> (mtx.createCopy(m_doc));
    QVERIFY(copyMtx != NULL);
    QCOMPARE(copyMtx->startColor(), QColor(Qt::magenta));
    QCOMPARE(copyMtx->endColor(), QColor(Qt::yellow));
    QCOMPARE(copyMtx->fixtureGroup(), uint(0));
    QVERIFY(copyMtx->algorithm() != NULL);
    QVERIFY(copyMtx->algorithm() != mtx.algorithm()); // Different object pointer!
    QCOMPARE(copyMtx->algorithm()->name(), QString("Stripes"));
}
Пример #7
0
void VCMatrix::slotCustomControlClicked()
{
    QPushButton *btn = qobject_cast<QPushButton*>(sender());
    VCMatrixControl *control = m_controls[btn];
    if (control != NULL)
    {
        RGBMatrix* matrix = qobject_cast<RGBMatrix*>(m_doc->function(m_matrixID));
        if (matrix == NULL || mode() == Doc::Design)
            return;

        if (control->m_type == VCMatrixControl::StartColor)
        {
            QPixmap px(42, 42);
            px.fill(control->m_color);

            m_startColorButton->setIcon(px);
            matrix->setStartColor(control->m_color);
            matrix->calculateColorDelta();
        }
        else if (control->m_type == VCMatrixControl::EndColor)
        {
            QPixmap px(42, 42);
            px.fill(control->m_color);

            m_endColorButton->setIcon(px);
            matrix->setEndColor(control->m_color);
            matrix->calculateColorDelta();
        }
        else if (control->m_type == VCMatrixControl::Animation)
        {
            RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, control->m_resource);
            if (!control->m_properties.isEmpty())
            {
                RGBScript *script = static_cast<RGBScript*> (algo);
                QHashIterator<QString, QString> it(control->m_properties);
                while(it.hasNext())
                {
                    it.next();
                    script->setProperty(it.key(), it.value());
                }
            }
            matrix->setAlgorithm(algo);
            if (instantChanges() == true)
                matrix->calculateColorDelta();
            m_presetCombo->blockSignals(true);
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
            m_presetCombo->setCurrentText(control->m_resource);
#else
            m_presetCombo->setCurrentIndex(m_presetCombo->findText(control->m_resource));
#endif
            m_presetCombo->blockSignals(false);
        }
        else if (control->m_type == VCMatrixControl::Text)
        {
            RGBAlgorithm* algo = RGBAlgorithm::algorithm(m_doc, "Text");
            RGBText* text = static_cast<RGBText*> (algo);
            text->setText(control->m_resource);
            matrix->setAlgorithm(algo);
            if (instantChanges() == true)
                matrix->calculateColorDelta();
        }
    }
}
Пример #8
0
void PatternDemo::draw(RGBMatrix &matrix)
{
    matrix.set(frameData);
}
Пример #9
0
void RGBMatrix_Test::loadSave()
{
    RGBMatrix* mtx = new RGBMatrix(m_doc);
    mtx->setStartColor(Qt::magenta);
    mtx->setEndColor(Qt::blue);
    mtx->setFixtureGroup(42);
    mtx->setAlgorithm(RGBAlgorithm::algorithm(m_doc, "Stripes"));
    QVERIFY(mtx->algorithm() != NULL);
    QCOMPARE(mtx->algorithm()->name(), QString("Stripes"));

    mtx->setName("Xyzzy");
    mtx->setDirection(Function::Backward);
    mtx->setRunOrder(Function::PingPong);
    mtx->setDuration(1200);
    mtx->setFadeInSpeed(10);
    mtx->setFadeOutSpeed(20);
    mtx->setDimmerControl(false);
    m_doc->addFunction(mtx);

    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly | QIODevice::Text);
    QXmlStreamWriter xmlWriter(&buffer);

    QVERIFY(mtx->saveXML(&xmlWriter) == true);

    xmlWriter.setDevice(NULL);
    buffer.close();

    buffer.open(QIODevice::ReadOnly | QIODevice::Text);
    QXmlStreamReader xmlReader(&buffer);
    xmlReader.readNextStartElement();

    QCOMPARE(xmlReader.name().toString(), QString("Function"));
    QCOMPARE(xmlReader.attributes().value("Type").toString(), QString("RGBMatrix"));
    QCOMPARE(xmlReader.attributes().value("ID").toString(), QString::number(mtx->id()));
    QCOMPARE(xmlReader.attributes().value("Name").toString(), QString("Xyzzy"));

    int speed = 0, dir = 0, run = 0, algo = 0, monocolor = 0, endcolor = 0, grp = 0, dimmer = 0;

    while (xmlReader.readNextStartElement())
    {
        if (xmlReader.name() == "Speed")
        {
            QCOMPARE(xmlReader.attributes().value("FadeIn").toString(), QString("10"));
            QCOMPARE(xmlReader.attributes().value("FadeOut").toString(), QString("20"));
            QCOMPARE(xmlReader.attributes().value("Duration").toString(), QString("1200"));
            speed++;
            xmlReader.skipCurrentElement();
        }
        else if (xmlReader.name() == "Direction")
        {
            QCOMPARE(xmlReader.readElementText(), QString("Backward"));
            dir++;
        }
        else if (xmlReader.name() == "RunOrder")
        {
            QCOMPARE(xmlReader.readElementText(), QString("PingPong"));
            run++;
        }
        else if (xmlReader.name() == "Algorithm")
        {
            // RGBAlgorithms take care of Algorithm tag's contents
            algo++;
            xmlReader.skipCurrentElement();
        }
        else if (xmlReader.name() == "MonoColor")
        {
            QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::magenta).rgb());
            monocolor++;
        }
        else if (xmlReader.name() == "EndColor")
        {
            QCOMPARE(xmlReader.readElementText().toUInt(), QColor(Qt::blue).rgb());
            endcolor++;
        }
        else if (xmlReader.name() == "FixtureGroup")
        {
            QCOMPARE(xmlReader.readElementText(), QString("42"));
            grp++;
        }
        else if (xmlReader.name() == "DimmerControl")
        {
            QCOMPARE(xmlReader.readElementText(), QString("0"));
            dimmer++;
        }
        else
        {
            QFAIL(QString("Unexpected tag: %1").arg(xmlReader.name().toString()).toUtf8().constData());
        }
    }

    QCOMPARE(speed, 1);
    QCOMPARE(dir, 1);
    QCOMPARE(run, 1);
    QCOMPARE(algo, 1);
    QCOMPARE(monocolor, 1);
    QCOMPARE(endcolor, 1);
    QCOMPARE(grp, 1);
    QCOMPARE(dimmer, 1);

    xmlReader.setDevice(NULL);
    buffer.seek(0);
    xmlReader.setDevice(&buffer);
    xmlReader.readNextStartElement();

    RGBMatrix mtx2(m_doc);
    QVERIFY(mtx2.loadXML(xmlReader) == true);
    QCOMPARE(mtx2.direction(), Function::Backward);
    QCOMPARE(mtx2.runOrder(), Function::PingPong);
    QCOMPARE(mtx2.startColor(), QColor(Qt::magenta));
    QCOMPARE(mtx2.endColor(), QColor(Qt::blue));
    QCOMPARE(mtx2.fixtureGroup(), uint(42));
    QVERIFY(mtx2.algorithm() != NULL);
    QCOMPARE(mtx2.algorithm()->name(), mtx->algorithm()->name());
    QCOMPARE(mtx2.duration(), uint(1200));
    QCOMPARE(mtx2.fadeInSpeed(), uint(10));
    QCOMPARE(mtx2.fadeOutSpeed(), uint(20));

    buffer.close();
    buffer.setData(QByteArray());

    buffer.open(QIODevice::WriteOnly | QIODevice::Text);
    xmlWriter.setDevice(&buffer);

    // Put some extra garbage in
    xmlWriter.writeStartElement("Foo");
    xmlWriter.writeEndElement();

    buffer.close();
    buffer.open(QIODevice::ReadOnly | QIODevice::Text);

    xmlReader.setDevice(&buffer);
    xmlReader.readNextStartElement();

    QVERIFY(mtx2.loadXML(xmlReader) == false); // Not a function node

    xmlReader.setDevice(NULL);
    buffer.close();
    buffer.setData(QByteArray());

    buffer.open(QIODevice::WriteOnly | QIODevice::Text);
    xmlWriter.setDevice(&buffer);

    // Put some extra garbage in
    xmlWriter.writeStartElement("Function");
    xmlWriter.writeAttribute("Type", "Scene");
    xmlWriter.writeEndElement();

    buffer.close();
    buffer.open(QIODevice::ReadOnly | QIODevice::Text);

    xmlReader.setDevice(&buffer);
    xmlReader.readNextStartElement();
    QVERIFY(mtx2.loadXML(xmlReader) == false); // Not an RGBMatrix node

}