-
Notifications
You must be signed in to change notification settings - Fork 1
/
particles.jsx
134 lines (105 loc) · 3.4 KB
/
particles.jsx
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { css } from "uebersicht"
import { ParticleNetwork } from "./src/particleNetwork"
export const refreshFrequency = 60000;
// The percent battery where we shut this down to save power
const batteryCutoff = 75;
export const opts = {
// Particle colors
colors: ["#fffb96", "#f47cd4", "#01cdfe"], // a e s t h e t i c
speed: 500,
// The min and max wind speed
windSpeed: [2,5],
// How often the wind changes
windFlicker: 0.01,
// The range of wind directions, in degrees, that the wind can blow.
// If both numbers are the same, the wind will never change direction.
// Guide:
// 0: up, 90: Down, 180: Left, 270: Right
// So, for example, if you want the wind to always blow mostly upwards,
// use [250, 290]. For any direction, use [0, 359].
// The first number must always be less than the second, but you can
// pick negative numbers like [-10, 10]
windDirection: [250, 290],
// How often the particles change direction. (0.0 - 1.0)
wander: 0.8,
// How flickery the particles appear. (0.0+)
flicker: 0.5,
// Particles per 500x500 block of pixels
density: 8,
// Distance at which particles are close enough to glow
range: 500,
// Minimum particle size
sizeMin: 2,
// Max particle size
sizeMax: 5,
// Skip frames to save CPU cycles. If this number is zero, the animation will
// run at around 60 fps.
frameSkip: 2,
// Only spawn particles at the edge of the screen.
// Particles will only move along the edges.
edgeOnly: false,
// Only useful if edgeOnly is true. When spawning particles, also spawn particles
// at screen_width / 2 or screen_height / 2.
edgeAndCentre: false,
// Show debugging info
debug: false
};
export const className = `
width: 100%;
height: 100%;
margin: 0;
padding: 0;
z-index: 10;
whatever: 3333;
`
let particleNetwork = null;
export const command = "pmset -g batt | egrep '([0-9]+\%).*' -o --colour=auto | cut -f1 -d';'";
export const getInitialState = () => {
const canvasStyle = {
width: '100%',
height: '100%',
padding: 0,
border: 0,
position: 'absolute'
};
const debugStyle = {
position: 'relative',
maxWidth: '20%',
maxHeight: '20%',
left: '20%',
right: '0',
top: '20%',
color: 'white',
backgroundColor: 'black'
};
return (
<div style={{width: "100%", height: "100%"}}>
<div id="particle-canvas" style={canvasStyle}></div>
<div id="debug-info" style={debugStyle}></div>
</div>
);
};
export const initialState = { output: getInitialState() };
export const updateState = (event, previousState) => {
if (!particleNetwork) {
let canvasDiv = document.getElementById('particle-canvas');
// Ensure the canvas div has been set up. I think there is a weird
// race condition somewhere between initialState and updateState
if(canvasDiv == null) {
return previousState;
}
particleNetwork = new ParticleNetwork(canvasDiv, opts);
particleNetwork.start();
}
// Don't waste power
const batt = parseInt(event.output.split("%")[0]);
if (batt > batteryCutoff) {
const scale = (batt - batteryCutoff) / (100.0 - batteryCutoff);
console.log(`Particles: Scale is now ${scale}`);
particleNetwork.start(scale);
} else {
console.log(`Particles: Network in power save mode`);
particleNetwork.stop();
}
return previousState;
}