-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.h
137 lines (107 loc) · 3.29 KB
/
mainwindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QGraphicsItem>
#include <QPropertyAnimation>
#include <QGraphicsScene>
#include <QPainter>
#include <iostream>
#include <QtMath>
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
constexpr double PI = 3.141592653589793;
static int line_counter = 0;
static int widthCounter = 0;
class line : public QObject, public QGraphicsItem {
Q_OBJECT
Q_PROPERTY(QPointF end READ end WRITE setEnd)
public:
line(QGraphicsItem *parent, QPointF start, QPointF end) : start(start), finalEnd(end), end_m(start), QGraphicsItem(parent)
{
setPos(start);
pen.setWidth(100);
pen.setColor(QColor::fromRgb(20,20,200,10));
/* For Trees and Flowers*/
pen.setWidth(++widthCounter % 300);
if(id%30>10)
pen.setColor(QColor::fromRgb(200,0,10,2*widthCounter%20));
else if(id%30>20)
pen.setColor(QColor::fromRgb(255,widthCounter%150,220,2*widthCounter%20));
else
pen.setColor(QColor::fromRgb(20,0,200,2*widthCounter%20));
//For Tree. Makes Leaves green
if(widthCounter > 200)
pen.setColor(QColor::fromRgb(20,200,20,10));
}
void startAnimation() {
QPropertyAnimation *animation = new QPropertyAnimation(this, "end", this);
animation->setStartValue(start);
// std::cerr << "start = (" << start.x() << ", " << start.y() << ")" << std::endl;
// std::cerr << "finalEnd = (" << finalEnd.x() << ", " << finalEnd.y() << ")" << std::endl;
animation->setEndValue(finalEnd);
animation->setDuration(100);
animation->setEasingCurve(QEasingCurve::Linear);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
QPointF end()
{
return end_m;
}
void setEnd(QPointF end)
{
end_m = end;
update();
}
protected:
QRectF boundingRect() const override
{
return QRectF();//this->mapFromScene(start),this->mapFromScene(end_m));
//return QRectF(-100,-100,1000,1000);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
{
painter->setPen(pen);
painter->drawLine(this->mapFromScene(start),this->mapFromScene(end_m));
}
private:
QPointF start;
QPointF end_m;
QPointF finalEnd;
int id = ++line_counter;
QPen pen;
};
class MainWindow : public QMainWindow
{
Q_OBJECT
Q_PROPERTY(int frame READ frame WRITE setFrame)
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
void drawTriangleHexagonPattern();
void drawTree();
void makeRing();
void applyRules();
void makeLines();
void draw();
void drawFast();
int frame() const
{
return frame_m;
}
void setFrame(int frame);
private:
Ui::MainWindow *ui;
QGraphicsScene *scene;
std::vector<QPointF> cursors;
std::vector<qreal> thetas;
std::vector<std::pair<QString,QString>> rules;
std::vector<line *> lineBank;
std::vector<line *>::const_iterator lineCursor;
std::vector<line *> lines;
int frame_m = 0;
int lastFrameDrawn = 0;
QPropertyAnimation *animation = new QPropertyAnimation(this, "frame", this);
QString string;
};
#endif // MAINWINDOW_H