Qtので心臓の形を描きます

MainWindow.h
#ifndefのMAINWINDOW_H
 の#define MAINWINDOW_H 

の#include <QMainWindow> 
の#include <QTimer> クラスのメインウィンドウ:公共QMainWindow 
{ 
    Q_OBJECTの公共
    メインウィンドウ(QWidgetの *親= 0 )。
    メインウィンドウ();  timerEvent(QTimerEvent * )。
    無効 paintEvent(QPaintEvent * イベント)。プライベートint型m_x、m_y。
    int型のm_k。
    フロートm_t。
}。#endifの//





    



  MAINWINDOW_H
MainWindow.cpp
#include " mainwindow.h " 
の#include <QDebug> 
の#include <math.h>の
書式#include <QPainterの> 

メインウィンドウ::メインウィンドウ(QWidgetの * 親)
    :QMainWindow(親)
{ 
    この - > setFixedSize(600600 )。
    m_k = 10 
    m_t = 0 ; 
    startTimer(1 )。

} 

メインウィンドウ::メインウィンドウ()
{ 

} 

のMainWindow :: timerEvent(QTimerEvent * 
{ 
    qDebug() << " タイマーイベント" << m_t。
    もし(m_t> 500 
    { 
        更新()。
        m_t = 0 ; 
    } 
    m_x = 16 * m_k * SIN(m_k * m_t)* SIN(m_k * m_t)* SIN(m_k * m_t)。
    m_y = 13 * m_k * COS(m_k * m_t) - 5つの * m_k * COS(2 * m_k * m_t) - 2つの * m_k * COS(3 * m_k * m_t) - COS(4 * m_k * m_t)。
    m_x + = この - >幅()/2
    m_y - = この - >高さ()/ 2 
    m_y * = - 1 ; 
    アップデート(m_x、m_y、11 )。

    m_t + = 0.1 
} 

の#if 1つの
 空隙メインウィンドウ:: paintEvent(QPaintEvent * イベント
{ 
    qDebug() << " paintEvent " << m_x << "  " << m_y。
    QPainterの画家(この); 
    painter.setPen(Qtの::赤)。
    painter.drawPoint(m_x、m_y)。
}
#else 
ボイドメインウィンドウ:: paintEvent(QPaintEvent * イベント
{ 
   ダブル K = 10 
   QPainterの画家(この); 
   painter.setRenderHint(QPainterの::アンチエイリアシング、真の); 
   QColorのmy_color(237162255255 )。
   QBrushのmy_brush(my_color)。
   painter.setPen(Qtの::赤)。
   / * painter.setBrush(my_brush)。* / 
   painter.translate(これ - >幅()/ 2この - >高さ()/ 2 )。
   QPainterPath polygonPath; 
   polygonPath.setFillRule(Qtの:: WindingFill)。
   フロート X = 16 * K * SIN(0.0)* SIN(0.0)* SIN(0.0 )。
   フロート Yが= 13の * K * COS(0.0 - )5つの * K * COS(0.0) - 2つの * K * COS(0.0) - COS(0.0 )。
   polygonPath.moveTo(x、 - Y)。
   ダブル T = 0.01 ; T < 100 ; T + = 0.05 
   { 
       X= 16 * K * SIN(K * tの)* SIN(K * tの)* SIN(k個*のT); 
       Y = 13 * K * COS(k個の*トン) - 5 * K * COS(2 * k個の*トン) - 2 * K * COS(3 * k個* T) - COS(4 * k個*のT); 
       polygonPath.lineTo(x、 - Y)。
#if 0 
       painter.drawPoint(x、 - Y)。
       painter.drawLine(00、X、 - Y)
       painter.drawLine(00、X + 100、 - Y)。
#endifの 
   }
   painter.drawPath(polygonPath)。
} 
#endifの

 

おすすめ

転載: www.cnblogs.com/nanqiang/p/11542164.html