forked from gre/gl-react-native-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimatedHelloGL.js
More file actions
47 lines (42 loc) · 895 Bytes
/
AnimatedHelloGL.js
File metadata and controls
47 lines (42 loc) · 895 Bytes
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
const React = require("react-native");
const GL = require("gl-react-native");
const shaders = GL.Shaders.create({
helloGL: {
frag: `
precision highp float;
varying vec2 uv;
uniform float value;
void main () {
gl_FragColor = vec4(uv.x, uv.y, value, 1.0);
}
`
}
});
class HelloGL extends React.Component {
constructor (props) {
super(props);
this.state = {
value: 0
};
}
componentDidMount () {
const loop = time => {
requestAnimationFrame(loop);
this.setState({
value: (1 + Math.cos(time / 1000)) / 2 // cycle between 0 and 1
});
};
requestAnimationFrame(loop);
}
render () {
const { width, height } = this.props;
const { value } = this.state;
return <GL.View
shader={shaders.helloGL}
width={width}
height={height}
uniforms={{ value }}
/>;
}
}
module.exports = HelloGL;