-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfraclevy.cpp
More file actions
58 lines (48 loc) · 1.07 KB
/
Copy pathfraclevy.cpp
File metadata and controls
58 lines (48 loc) · 1.07 KB
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
#include "fraclevy.h"
#include "ui_fraclevy.h"
FracLevy::FracLevy(QWidget *parent) :
QWidget(parent),
ui(new Ui::FracLevy)
{
depth = 10;
ui->setupUi(this);
text = new QLabel("Глубина: ", this);
sbox = new QSpinBox(this);
sbox->setRange(0, 20);
sbox->setValue(depth);
connect(sbox, SIGNAL(valueChanged(int)), SLOT(repaintFractal()));
}
FracLevy::~FracLevy()
{
delete text;
delete sbox;
delete ui;
}
void FracLevy::paintEvent(QPaintEvent *)
{
QPointF first(200,400);
QPointF last(500,400);
painter = new QPainter(this);
painter->setPen(Qt::magenta);
drawLevy(first, last, depth);
}
void FracLevy::drawLevy(QPointF &p1, QPointF &p2, int iter)
{
if (iter == 0)
{
painter->drawLine(p1,p2);
}
else
{
QPointF p;
p.setX((p1.x() + p2.x())/2 + (p2.y() - p1.y())/2);
p.setY((p1.y() + p2.y())/2 - (p2.x() - p1.x())/2);
drawLevy(p,p2,iter-1);
drawLevy(p1,p,iter-1);
}
}
void FracLevy::repaintFractal()
{
depth = sbox->value();
repaint();
}