forked from giladaya/arduino-particle-sys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmitter_Fire.cpp
85 lines (74 loc) · 1.84 KB
/
Emitter_Fire.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
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright (C) 2013 Gilad Dayagi. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
/*
* Emitter_Fire.cpp - emit particles to simulate fire
*/
#include "Emitter_Fire.h"
byte Emitter_Fire::baseHue = 128; //blues
byte Emitter_Fire::maxTtl = 128;
Emitter_Fire::Emitter_Fire()
{
counter = 0;
cycleHue = false;
}
void Emitter_Fire::update()
{
}
void Emitter_Fire::emit(Particle_Abstract *particle)
{
counter++;
if (cycleHue) baseHue = (counter>>2)%240;
if (counter % 2 == 0) {
particle->x = random(PS_MAX_X >> 2, 3 * (PS_MAX_X >> 2));
switch (particle->x / 32) {
case 0:
case 7:
particle->ttl = random(1, 7);
break;
case 1:
case 6:
particle->ttl = random(5, 14);
break;
case 2:
case 5:
particle->ttl = random(15, 21);
break;
case 3:
case 4:
particle->ttl = random(25, 28);
break;
}
particle->hue = baseHue+16;
} else {
particle->x = random(PS_MAX_X);
switch (particle->x / 32) {
case 0:
case 7:
particle->ttl = random(1, 20);
break;
case 1:
case 6:
particle->ttl = random(5, 40);
break;
case 2:
case 5:
particle->ttl = random(20, 70);
break;
case 3:
case 4:
particle->ttl = random(40, 100);
break;
}
particle->hue = baseHue;
}
particle->y = 1;
particle->vx = 0;
particle->vy = 0;
particle->isAlive = true;
}