-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell_automaton.h
63 lines (50 loc) · 1.44 KB
/
cell_automaton.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
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QWidget>
#include <vector>
#include <QLabel>
#include <QPainter>
#include <QPixmap>
#include <QString>
#include <QColor>
#include <QTime>
#include <QTimer>
#include <QElapsedTimer>
#include <QResizeEvent>
#include <cmath>
#include <iostream>
class CellAutomaton : public QWidget
{
Q_OBJECT
static const int DEFAULT_COLORS_AMOUNT = 21;
static const int DEFAULT_SCALING_FACTOR = 3;
static const int TICK_LENGTH_MS = 25;
static const int RESTART_TIME = 800;
//static const int LIFE_LENGTH_MS = 10 * 60 * 1000; // 10 minutes
public:
explicit CellAutomaton(QWidget *parent = 0);
public slots:
void restart(int old_y = 0, int old_x = 0);
void advance();
private:
void resizeEvent(QResizeEvent*);
void paintEvent(QPaintEvent*);
void keyPressEvent(QKeyEvent* event);
void change_random_pixels(int amount);
typedef std::vector<std::vector<int> > map_type;
inline int pixel_next(int y, int x);
inline int map_get(int y, int x);
inline int& get(map_type const& map, int y, int x);
std::vector<QColor> colors;
int scaling_factor;
map_type map, buf;
QTimer* tick_timer;
QTimer* restart_timer;
QElapsedTimer life_timer;
void (*gen_ptr)(std::vector<QColor>&);
qint64 steps;
qint64 dead_cells;
};
void random_colors(std::vector<QColor>& colors);
void melting_ice(std::vector<QColor>& colors);
#endif // MAINWINDOW_H