Skip to content

Commit 6c08bc4

Browse files
committed
made particles 3d and slowed things down
1 parent dab2658 commit 6c08bc4

File tree

4 files changed

+49
-21
lines changed

4 files changed

+49
-21
lines changed

bin/build-latest.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33
cd $ACTIVE_HOME/src;
44
make
55

6+
sudo cp $ACTIVE_HOME/bin/env.sh /boot/uboot/
7+
68
cd $OPC_SERVER_HOME
79
make

src/dot.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
#include "lib/effect.h"
77
#include "lib/texture.h"
88

9-
#ifndef __APPLE
10-
#include "lib/BlackLib.h"
11-
#include "lib/BlackDef.h"
12-
#endif
13-
149
class DotEffect : public Effect
1510
{
1611
public:
@@ -27,25 +22,28 @@ class DotEffect : public Effect
2722

2823
virtual void beginFrame(const FrameInfo &f)
2924
{
30-
const float speed = 1.0;
25+
26+
const float speed = 0.01; // SLOW
27+
// const float speed = 1.01; // FAST
3128

3229
// Several bounded state variables, rotating at different rates
33-
/*
30+
///*
3431
angle1 = fmodf(angle1 + f.timeDelta * speed, 2 * M_PI);
3532
angle2 = fmodf(angle2 + f.timeDelta * speed * 0.2f, 2 * M_PI);
3633
angle3 = fmodf(angle3 + f.timeDelta * speed * 0.7f, 2 * M_PI);
37-
*/
34+
//*/
3835
// Several bounded state variables, rotating at different rates
36+
/*
3937
angle1 = fmodf(angle1 * speed, 2 * M_PI);
4038
angle2 = fmodf(angle2 * speed , 2 * M_PI);
4139
angle3 = fmodf(angle3 + f.timeDelta * speed , 2 * M_PI);
40+
*/
4241
}
4342

4443
virtual void shader(Vec3& rgb, const PixelInfo &p) const
4544
{
4645
// Project onto the XZ plane
47-
// Vec2 plane = Vec2(p.point[0]*0.5f, p.point[2]);
48-
Vec2 plane = Vec2(p.point[0], p.point[2]);
46+
Vec2 plane = Vec2(p.point[0]*-0.5f, p.point[1]);
4947

5048
// rotate this
5149
// plane
@@ -61,4 +59,5 @@ class DotEffect : public Effect
6159

6260
// rgb = dot.sample( (plane - position) / size + center );
6361
}
62+
6463
};

src/images.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "lib/effect_mixer.h"
66

77
#include "dot.h"
8-
8+
#include "particle_trail.h"
99
#include "rings.h"
1010

1111
int main(int argc, char **argv)
@@ -16,15 +16,18 @@ int main(int argc, char **argv)
1616
DotEffect img2("external/img2.png");
1717
DotEffect img3("external/img3.png");
1818
DotEffect img4("external/img4.png");
19+
ParticleTrailEffect e;
1920

2021

2122
EffectMixer mixer;
22-
mixer.add(&rings);
23+
2324
mixer.add(&img0);
2425
mixer.add(&img1);
2526
mixer.add(&img2);
2627
mixer.add(&img3);
2728
mixer.add(&img4);
29+
mixer.add(&rings);
30+
mixer.add(&e);
2831

2932
EffectRunner r;
3033
r.setEffect(&mixer);
@@ -37,13 +40,31 @@ int main(int argc, char **argv)
3740

3841
while (true) {
3942
EffectRunner::FrameStatus frame = r.doFrame();
40-
const float speed = 0.1f;
43+
// const float speed = 1.01f; //FAST
44+
const float speed = 0.001f; //SLOW
4145

4246
// Animate the mixer's fader controls
4347
state = fmod(state + frame.timeDelta * speed, 2 * M_PI);
4448
for (int i = 0; i < mixer.numChannels(); i++) {
45-
float theta = state + i * (2 * M_PI) / mixer.numChannels();
46-
mixer.setFader(i, std::max(0.0f, sinf(theta)));
49+
50+
mixer.setFader(i, 0.0);
51+
52+
float remainder = state - i;
53+
// is this state
54+
if ( i == (int)state) {
55+
mixer.setFader(i, remainder);
56+
}
57+
58+
// is next state
59+
int nextState = (int) state;
60+
nextState += 1;
61+
nextState % mixer.numChannels();
62+
if (i == nextState) {
63+
mixer.setFader(i, 1-remainder);
64+
}
65+
66+
// float theta = state + i * (2 * M_PI) / mixer.numChannels();
67+
// mixer.setFader(i, std::max(0.0f, sinf(theta)));
4768
}
4869

4970
// Main loops and Effects can both generate verbose debug output (-v command line option)

src/particle_trail.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,43 @@ class ParticleTrailEffect : public ParticleEffect
1616

1717
float angle1;
1818
float angle2;
19+
float angle3;
20+
1921
float baseHue;
2022

2123
virtual void beginFrame(const FrameInfo &f)
2224
{
2325
const float tailLength = 8.0f;
24-
const float speed = 9.0f;
26+
const float speed = 0.04f; //SLOW
27+
// const float speed = 5.09f; //FAST
2528
const float lfoRatio = 0.15f;
29+
const float notLfoRatio = 0.01f;
2630
const float hueRate = 0.01f;
2731
const float brightness = 40.0f;
2832
const unsigned numParticles = 200;
2933

3034
// Low frequency oscillators
3135
angle1 = fmodf(angle1 + f.timeDelta * speed, 2 * M_PI);
3236
angle2 = fmodf(angle2 + f.timeDelta * speed * lfoRatio, 2 * M_PI);
37+
angle3 = fmodf(angle3 + f.timeDelta * speed * notLfoRatio, 2 * M_PI);
3338
baseHue = fmodf(baseHue + f.timeDelta * speed * hueRate, 1.0f);
3439

3540
appearance.resize(numParticles);
3641
for (unsigned i = 0; i < numParticles; i++) {
3742
float s = float(i) / numParticles;
3843
float tail = s * tailLength;
3944

40-
float radius = 0.2 + 1.5 * s;
41-
float x = radius * cos(angle1 + tail);
45+
float radius = 0.2 + 2.0 * s;
46+
float x = radius * cos(angle1 + tail) * 2.0 + 1.0;
4247
float y = radius * sin(angle1 + tail + 10.0 * sin(angle2 + tail * lfoRatio));
48+
float z = radius * cos(angle3 + tail);
4349
float hue = baseHue + s * 0.4;
4450

4551
ParticleAppearance& p = appearance[i];
46-
p.point = Vec3(x, 0, y);
52+
p.point = Vec3(x, y, z);
4753
p.intensity = (brightness / numParticles) * s;
48-
p.radius = 0.1 + 0.4f * s;
49-
hsv2rgb(p.color, hue, 0.5, 0.8);
54+
p.radius = 0.1 + 1.2f * s; //MADE BIG
55+
hsv2rgb(p.color, hue, 0.5, 1.0);
5056
}
5157

5258
ParticleEffect::beginFrame(f);

0 commit comments

Comments
 (0)