forked from gre/gl-react-native-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPieProgress.js
More file actions
64 lines (59 loc) · 1.17 KB
/
PieProgress.js
File metadata and controls
64 lines (59 loc) · 1.17 KB
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
const React = require("react-native");
const GL = require("gl-react-native");
const shaders = GL.Shaders.create({
pieProgress: {
frag: `
precision mediump float;
varying vec2 uv;
uniform vec4 colorInside, colorOutside;
uniform float radius;
uniform float progress;
uniform vec2 dim;
const vec2 center = vec2(0.5);
const float PI = acos(-1.0);
void main () {
vec2 norm = dim / min(dim.x, dim.y);
vec2 p = uv * norm - (norm-1.0)/2.0;
vec2 delta = p - center;
float inside =
step(length(delta), radius) *
step((PI + atan(delta.y, -delta.x)) / (2.0 * PI), progress);
gl_FragColor = mix(
colorOutside,
colorInside,
inside
);
}
`
}
});
module.exports = GL.createComponent(
({
width,
height,
progress,
colorInside,
colorOutside,
radius
}) =>
<GL.View
width={width}
height={height}
shader={shaders.pieProgress}
opaque={false}
uniforms={{
dim: [ width, height ],
progress,
colorInside,
colorOutside,
radius
}}
/>,
{
displayName: "PieProgress",
defaultProps: {
colorInside: [0, 0, 0, 0],
colorOutside: [0, 0, 0, 0.5],
radius: 0.4
}
});