• 大小: 11KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-19
  • 语言: 其他
  • 标签: Qt界面  

资源简介

绘制魔法鱼儿 鼠标按哪,鱼儿游哪

资源截图

代码片段和文件信息

#include “magic_fish.h“
#include 
#include 
#include 

MagicFish::MagicFish(QWidget *parent)
    : QWidget(parent)
      fish_r(30)
      fin_length(30 * 1.3)
      body_height(30 * 3.2)
      head_alpha(200)
      body_alpha(225)
      fin_alpha(120)
      main_angle(0.0)
      current_value(0)
      speed(30)
      start_fin(false)
      paint_point(false)
      wave(1.0)
{
    this->timer = new QTimer(this);
    this->timer->setInterval(100);
    connect(timer &QTimer::timeout this &MagicFish::updateValue);
    this->timer->start();
    this->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::framelessWindowHint);
}

void MagicFish::updateValue()
{
    this->current_value = (this->current_value + this->speed) % 54000;
    this->update();
}

void MagicFish::paintEvent(QPaintEvent *e)
{
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing);
    QPointF middle_pos = QPointF(this->width() / 2 this->height() / 2);
    this->head_pos = this->calcPoint(middle_pos this->body_height / 2.0 this->main_angle);
    this->paintMyPoint(painter this->head_pos);
    this->paintMyPoint(painter middle_pos);
    painter.setPen(Qt::NoPen);
    painter.setBrush(QBrush(QColor(20 203 232 50)));
    painter.setBrush(QBrush(QColor(244 92 71 this->head_alpha)));
    painter.drawEllipse(this->head_pos this->fish_r this->fish_r);

    float angle = this->main_angle + qSin(qDegreesToRadians(this->current_value * 1.2 * wave)) * 2;
    QPointF end_pos = this->calcPoint(this->head_pos this->body_height angle - 180);
    QPointF pos1 = calcPoint(this->head_pos this->fish_r angle - 80);
    QPointF pos2 = calcPoint(end_pos this->fish_r * 0.7 angle - 90);
    QPointF pos3 = calcPoint(end_pos this->fish_r * 0.7 angle + 90);
    QPointF pos4 = calcPoint(this->head_pos this->fish_r angle + 80);

    QPointF central_left = this->calcPoint(this->head_pos this->body_height * 0.56 angle - 130);
    QPointF central_right = this->calcPoint(this->head_pos this->body_height * 0.56 angle + 130);
    QPainterPath path;
    path.moveTo(pos1);
    path.quadTo(central_left pos2);
    path.lineTo(pos3);
    path.quadTo(central_right pos4);
    path.lineTo(pos1);

    painter.setBrush(QBrush(QColor(244 92 71 this->body_alpha)));
    painter.drawPath(path);

    this->paintMyBody(painter end_pos this->fish_r * 0.7 0.6 angle);
    QPointF left_fin_pos = this->calcPoint(head_pos this->fish_r * 0.9 angle + 110);
    this->paintMyFishFins(painter left_fin_pos true angle);
    QPointF right_fin_pos = this->calcPoint(head_pos this->fish_r * 0.9 angle - 110);
    this->paintMyFishFins(painter right_fin_pos false angle);

    QWidget::paintEvent(e);
}

void MagicFish::resizeEvent(QResizeEvent *e)
{
    QWidget::resizeEvent(e);
    this->fish_r = qMin(this->width() this->height()) / 10.0;
    this->fin_length = this->fish_r 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-12-28 00:26  magic-fish\
     文件        1109  2017-12-19 19:03  magic-fish\magic-fish.pro
     文件       23917  2017-12-28 00:26  magic-fish\magic-fish.pro.user
     文件       23493  2017-12-18 15:25  magic-fish\magic-fish.pro.user.43ca8d8
     文件        8434  2017-12-21 11:29  magic-fish\magic_fish.cpp
     文件        1493  2017-12-21 11:25  magic-fish\magic_fish.h
     文件        4666  2017-12-21 11:33  magic-fish\magic_pool.cpp
     文件         926  2017-12-21 11:21  magic-fish\magic_pool.h
     文件         183  2017-12-18 15:25  magic-fish\main.cpp
     文件         333  2017-12-21 11:20  magic-fish\mainwindow.cpp
     文件         313  2017-12-21 11:21  magic-fish\mainwindow.h
     文件         571  2017-12-18 16:05  magic-fish\mainwindow.ui

评论

共有 条评论