快速制作哪吒电影中元始天尊使用的粒子动画

本文详细介绍了使用Qt5和QtCreator进行复杂动画绘制的方法,包括绘图机制、多线程实时更新、窗口属性修改等技术要点,以及如何实现点、线、三角形的动态生成与鼠标交互效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

电影回顾:

实现效果:

由于图片大小限制(这里只演示一部分)

使用工具:

     至少掌握一种GUI工具:这里我用的是Qt5+QtCreator

需要掌握:

     绘图机制

     多线程(实时更新画面)

     windows窗口属性修改(窗口透明,隐藏边框,鼠标穿透)

动画机制:

点:

    动画中有很多飘散的点(实际是一个很小的圆),这些点按不同的速度,不同的方向在运动,为了防止点跑出屏幕外,我们需要增加一个碰撞机制,当点碰到屏幕的时候,需要改变点的运动方向(遵循光的反射机制),并且我这里在碰撞的时候随机给点一个速度。

线: 

    通过检测上面的点集合,当两个点距离达到某一范围时,画线,且线的透明的与线的长度相关联。

三角形:

    当画完一条线之后,遍历点集,查看这个点是否可以构成三角形,如果可以,则进行绘制,并且关联透明度

鼠标移动:

   设置一个点,跟踪鼠标位置,这样鼠标的位置也可以画线和画三角形。记录鼠标的历史轨迹,当鼠标的移动速度到达某个值时,随机将点集中的一个点放到历史轨迹上。

配置:

绘制代码:

void Widget::paintEvent(QPaintEvent *e)
{
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing,true);
    QPen pen;
    pen.setWidthF(1.2);
    painter.setPen(pen);
    QColor c(Config::lineColor);
    c.lighter();
    QPolygon p;
    for(unsigned int i=0;i<points.size();++i){      //注意去重
        for(unsigned int j=i+1;j<points.size();++j){
            if(points[i].getDistance(points[j])<Config::maxLen_of_line){
                c.setAlpha(Config::maxLen_of_line-points[i].getDistance(points[j]));
                pen.setBrush(c);
                painter.setPen(pen);
                painter.drawLine(points[i].getX(),points[i].getY(),points[j].getX(),points[j].getY());      //画线
                c.setAlpha((Config::maxLen_of_line-points[i].getDistance(points[j]))/3);
                painter.setBrush(c);
                for(int k=j+1;k<points.size();++k){
                    if(points[k].getDistance(points[i])<Config::maxLen_of_line&&points[k].getDistance(points[j])<Config::maxLen_of_line){
                        p.setPoints(3,int(points[i].getX()),int(points[i].getY()),int(points[j].getX()),int(points[j].getY()),int(points[k].getX()),int(points[k].getY()));
                        painter.drawPolygon(p);                                 //画三角形
                    }
                }
            }

        }
        painter.setBrush(QColor(252,251,243));
        painter.setPen(Qt::NoPen);
        if(i)           //画点,第一个点用作鼠标
            painter.drawEllipse(points[i].getRect());
    }

}

点运行代码:

void Widget::run()
{
    collisionDetection();

    points[0].setX(QCursor::pos().x());
    points[0].setY(QCursor::pos().y());
    for(int i=1;i<points.size();++i)
    {
        points[i].run();
    }
    int x=(lastPos-QCursor::pos()).x(),
        y=(lastPos-QCursor::pos()).y();
    if(sqrt(x*x+y*y)>Config::len_of_link)
    {
        int index=1+qrand()%(points.size()-1);
        points[index].setX(lastPos.x());
        points[index].setY(lastPos.y());
    }
    lastPos=QCursor::pos();
    update();
}

可执行文件及Qt源代码:

蓝奏云:https://www.lanzous.com/i6uce1i

 

 

### 使用 Python Turtle 库绘制《哪吒》电影角色 要使用 `turtle` 库绘制《哪吒》电影中的角色,可以通过分解角色的主要特征并逐步实现其各个部分。以下是详细的说明以及代码示例。 #### 准备工作 在开绘制前,需先导入 `turtle` 模块,并初化画布和画笔的相关属性[^4]。 ```python import turtle # 设置屏幕大小、背景颜色 turtle.screensize(800, 600, 'white') # 配置画笔初状态 turtle.speed(1) # 调整速度以便观察过程 turtle.pencolor('black') turtle.fillcolor('orange') # 主体填充颜色设为橙色 turtle.penup() turtle.goto(-100, -100) # 移动到起位置 turtle.pendown() ``` #### 绘制头部 哪吒的头部可以用圆形表示,通过调整半径和填充颜色完成。 ```python def draw_head(): turtle.begin_fill() turtle.circle(100) # 半径为100像素的圆代表头部 turtle.end_fill() draw_head() ``` #### 添加眼睛 哪吒的眼睛可以由两个较小的椭圆构成,利用 `circle()` 方法配合旋转角度实现。 ```python def draw_eyes(): eye_radius = 15 # 左眼 turtle.penup() turtle.goto(-40, 70) turtle.setheading(90) # 方向朝上 turtle.pendown() turtle.color('black', 'white') # 白色眼球黑色边框 turtle.begin_fill() turtle.circle(eye_radius, 180) # 只画半个圆形成椭圆效果 turtle.circle(eye_radius / 2, 90) turtle.circle(eye_radius, 180) turtle.circle(eye_radius / 2, 90) turtle.end_fill() # 黑瞳孔 turtle.penup() turtle.goto(-35, 80) turtle.dot(10) # 右眼重复上述逻辑 turtle.penup() turtle.goto(10, 70) turtle.pendown() turtle.color('black', 'white') turtle.begin_fill() turtle.circle(eye_radius, 180) turtle.circle(eye_radius / 2, 90) turtle.circle(eye_radius, 180) turtle.circle(eye_radius / 2, 90) turtle.end_fill() turtle.penup() turtle.goto(15, 80) turtle.dot(10) draw_eyes() ``` #### 制作嘴巴 哪吒的嘴可用弧线模拟微笑形状。 ```python def draw_mouth(): turtle.penup() turtle.goto(-30, 40) turtle.pendown() turtle.right(90) turtle.circle(30, 180) # 微笑曲线 draw_mouth() ``` #### 补充装饰物 为了更贴近原形象,可增加发髻或其他标志性配饰。 ```python def add_accessories(): # 发髻(左侧) turtle.penup() turtle.goto(-120, 120) turtle.pendown() turtle.color('brown', 'red') turtle.begin_fill() turtle.circle(20) turtle.end_fill() # 发髻(右侧) turtle.penup() turtle.goto(120, 120) turtle.pendown() turtle.color('brown', 'red') turtle.begin_fill() turtle.circle(20) turtle.end_fill() add_accessories() ``` #### 结束绘图 当所有部件完成后,调用 `done()` 方法保持窗口不关闭。 ```python turtle.hideturtle() # 隐藏箭头光标 turtle.done() ``` 以上即是一个简单的基于 `turtle` 的哪吒角色绘制教程[^1]。可以根据需求进一步优化细节或扩展功能[^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值