-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paththread.cpp
74 lines (65 loc) · 1.79 KB
/
thread.cpp
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
#include "thread.h"
MyThread::MyThread(GLWidget *widget,QObject * parent):
QThread(parent)
{
ui = widget;
}
void MyThread::run()
{
for(;;)
{
if(ui->painter)
{
unsigned int w = ui->image->width();
unsigned int h = ui->image->height();
unsigned char *pixels = ui->image->bits();
unsigned int index;
unsigned char r,g,b;
unsigned int last = w * (h - 1) - _gher + 1;
for (unsigned int i = _wind; i < last; i++)
{
index = (i+w)*4;
r = pixels[index+2];
g = pixels[index+1];
b = pixels[index];
if(ui->random->nextInt(100) < _flame)
NextColor(&r,&g,&b);
index = (i+ui->random->nextInt(_gher) - _wind)*4;
pixels[index+2] = r;
pixels[index+1] = g;
pixels[index] = b;
}
for(int i=0; i<ui->cursorX.count(); i++)
ui->painter->drawEllipse(ui->cursorX[i],ui->cursorY[i],20,20);
for(int i=0; i<ui->cursorX.count()-1; i++)
{
ui->cursorX.removeFirst();
ui->cursorY.removeFirst();
}
}
emit ShowOnUI();
}
}
inline void MyThread::NextColor(unsigned char *r,unsigned char *g, unsigned char *b)
{
if(*b == 0)
{
if (*r == 255 && *g > 0)
{
if(*g > 0)
{
if (*g >= _flame)
*g = *g - _flame;
else
*g = 0;
}
}
else if (*r > 0 && *g == 0)
{
if (*r >= _flame)
*r = *r - _flame;
else
*r = 0;
}
}
}