forked from jasoncoon/arduino-particle-sys
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathEmitter_Side.cpp
67 lines (60 loc) · 1.77 KB
/
Emitter_Side.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
/*
* 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_Side.cpp - emit particles from one side of the box
*/
#include "Emitter_Side.h"
byte Emitter_Side::baseHue = 128; //blues
byte Emitter_Side::maxTtl = 128;
Emitter_Side::Emitter_Side(char side)
{
counter = 0;
this->side = side;
this->minVelocity = 1;
this->maxVelocity = 4;
}
Emitter_Side::Emitter_Side(char side, uint8_t minVelocity, uint8_t maxVelocity) {
counter = 0;
this->side = side;
this->minVelocity = minVelocity;
this->maxVelocity = maxVelocity;
}
void Emitter_Side::emit(Particle_Abstract *particle, ParticleSysConfig *g)
{
counter++;
switch(side) {
case 'b':
particle->x = random(g->max_x);
particle->y = g->max_y-g->res_y;
particle->vx = 0;
particle->vy = random(-maxVelocity,(-minVelocity)+1);
break;
case 'r':
particle->x = g->max_x-g->res_x;
particle->y = random(g->max_y);
particle->vx = random(-maxVelocity,(-minVelocity)+1);
particle->vy = 0;
break;
case 't':
particle->x = random(g->max_x);
particle->y = 1;
particle->vx = 0;
particle->vy = random(minVelocity,maxVelocity+1);
break;
case 'l':
particle->x = 1;
particle->y = random(g->max_y);
particle->vx = random(minVelocity,maxVelocity+1);
particle->vy = 0;
break;
}
particle->ttl = random(1, maxTtl);
particle->hue = baseHue;
particle->isAlive = true;
}