zoukankan      html  css  js  c++  java
  • Qt之图形(简笔画-绘制卡通蚂蚁)

    简述

    关于简笔画的介绍很多,有动物、水果、蔬菜、交通工具等,通常会对绘制一步步进行拆分、组合。然后绘制为我们想要的结果。

    下面来介绍另外的一个种类:昆虫类-卡通蚂蚁。

    绘制

    效果

    具体的效果如下所示,我们可以再进行更好的完善。

    这里写图片描述

    源码

    主要分为以下三部:

    • 绘制屁股
    • 绘制肚子
    • 绘制头部

    注意:绘制的时候,由于各个部分的颜色不同,而且坐标不好定位,所以我们采用的图形覆盖的方式。

    void MainWindow::paintEvent(QPaintEvent *)
    {
        QPainter painter(this);
        painter.setRenderHint(QPainter :: Antialiasing, true);
    
        /*****屁股*****/
        QPainterPath path;
        path.addRoundRect(QRect(200, 60, 150, 150), 1000);
        painter.setBrush(Qt::white);
        painter.setPen(Qt::black);
        painter.drawPath(path);
    
        /*****肚子*****/
        // 腿
        path = QPainterPath();
        path.moveTo(170, 180);
        path.lineTo(120, 260);
        path.moveTo(185, 180);
        path.lineTo(145, 280);
        path.moveTo(200, 180);
        path.lineTo(180, 290);
    
        path.moveTo(200, 180);
        path.lineTo(220, 290);
        path.moveTo(215, 180);
        path.lineTo(250, 280);
        path.moveTo(230, 180);
        path.lineTo(280, 260);
        painter.setBrush(Qt::NoBrush);
        painter.setPen(Qt::white);
        painter.drawPath(path);
    
        // 肚子
        path = QPainterPath();
        path.addRoundRect(QRect(150, 130, 100, 100), 1000);
        painter.setBrush(Qt::white);
        painter.setPen(Qt::black);
        painter.drawPath(path);
    
        /*****头*****/
        // 犄角
        path = QPainterPath();
        path.moveTo(80, 100);
        path.lineTo(60, 20);
        path.moveTo(140, 100);
        path.lineTo(160, 20);
        painter.setBrush(Qt::NoBrush);
        painter.setPen(Qt::white);
        painter.drawPath(path);
    
        path = QPainterPath();
        path.addRoundRect(QRect(50, 80, 120, 120), 1000);
        painter.setBrush(Qt::white);
        painter.setPen(Qt::black);
        painter.drawPath(path);
    
        // 左眼
        path = QPainterPath();
        path.addRoundRect(QRect(70, 120, 25, 25), 1000);
        painter.setBrush(Qt::black);
        painter.setPen(Qt::NoPen);
        painter.drawPath(path);
    
        path = QPainterPath();
        path.addRoundRect(QRect(75, 126, 10, 10), 1000);
        painter.setBrush(Qt::white);
        painter.setPen(Qt::NoPen);
        painter.drawPath(path);
    
        // 右眼
        path = QPainterPath();
        path.addRoundRect(QRect(120, 110, 25, 25), 1000);
        painter.setBrush(Qt::black);
        painter.setPen(Qt::NoPen);
        painter.drawPath(path);
    
        path = QPainterPath();
        path.addRoundRect(QRect(125, 118, 10, 10), 1000);
        painter.setBrush(Qt::white);
        painter.setPen(Qt::NoPen);
        painter.drawPath(path);
    
        // 嘴
        path = QPainterPath();
        path.moveTo(160, 108);
        path.arcTo(QRect(130, 48, 60, 60), 270, 100);
        painter.rotate(30);
        painter.setBrush(Qt::NoBrush);
        painter.setPen(Qt::black);
        painter.drawPath(path);
    }

    对于一般图形的绘制比较简单,因为常用、有规律,而且比较规则,像圆、椭圆、矩形、直线这些。如果存在各种复杂的图形那么用原生的绘制方案就很难实现了,需要消耗大量的时间来回折腾,所以这里就不再介绍了。

  • 相关阅读:
    关于Maya Viewport 2.0 API 开发的介绍视频
    春节大假
    Some tips about the life cycle of Maya thread pool
    Can I compile and run Dx11Shader for Maya 2015 on my side?
    How to get current deformed vertex positions in MoBu?
    想加入全球首届的 欧特克云加速计划吗?
    三本毕业(非科班),四次阿里巴巴面试,终拿 offer(大厂面经)
    mac、window版编辑器 webstorm 2016... 永久破解方法。
    node 搭载本地代理,处理web本地开发跨域问题
    js 一维数组,转成嵌套数组
  • 原文地址:https://www.cnblogs.com/itrena/p/5938339.html
Copyright © 2011-2022 走看看