//Qt C++实现数字雨动画的源码
#include <qapplication>
#include <qwidget>
#include <qlabel>
#include <qtimer>
#include <qpainter>

class DigitalRain : public QWidget
{
public:
    DigitalRain(QWidget *parent = nullptr)
        : QWidget(parent)
    {
        setFixedSize(800, 600);
        setWindowTitle("黑客帝国数字雨动画");
        QTimer *timer = new QTimer(this);
        connect(timer, &QTimer::timeout, this, &DigitalRain::updateAnimation);
        timer->start(100);
    }

protected:
    void paintEvent(QPaintEvent *event) override
    {
        QPainter painter(this);
        painter.setPen(Qt::green);
        QFont font("Consolas", 18);
        painter.setFont(font);
        for (int i = 0; i < m_colCount; ++i) {
            int size = m_items[i].size();
            for (int j = 0; j < size; ++j) {
                painter.drawText(m_items[i][j], i * m_itemSize, j * m_itemSize, m_itemSize, m_itemSize, Qt::AlignCenter, QString(QChar(m_items[i][j])));
            }
        }
    }

private:
    void updateAnimation()
    {
        for (int i = 0; i < m_colCount; ++i) {
            int rowCount = m_items[i].size();
            if (rowCount < m_rowCount) {
                m_items[i].prepend(getRandomChar());
            } else {
                m_items[i].removeLast();
                m_items[i].prepend(getRandomChar());
            }
        }
        update();
    }

    QChar getRandomChar()
    {
        return QChar(0x30A0 + qrand() % (0x30FF - 0x30A0));
    }

private:
    int m_colCount = 80;
    int m_rowCount = 50;
    int m_itemSize = 12;
    QVector<qvector<qchar>> m_items = QVector<qvector<qchar>>(m_colCount, QVector<qchar>(m_rowCount, getRandomChar()));
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    DigitalRain w;
    w.show();
    return a.exec();
}
</qchar></qvector<qchar></qvector<qchar></qpainter></qtimer></qlabel></qwidget></qapplication>