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(600、600 )。 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、1、1 )。 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(237、162、255、255 )。 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(0、0、X、 - Y) painter.drawLine(0、0、X + 100、 - Y)。 #endifの } painter.drawPath(polygonPath)。 } #endifの