-
Notifications
You must be signed in to change notification settings - Fork 38
/
Wave.js
56 lines (44 loc) · 1.11 KB
/
Wave.js
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
'use strict';
function drawSine(t) {
var path = `M ${0} ${Math.sin(t) * 100 + 120}`;
var x, y;
for (var i = 0; i <= 10; i += 0.5) {
x = i * 50;
y = Math.sin(t + x) * 100 + 120;
path = path + ` L ${x} ${y}`
}
return path;
}
var React = require('react-native');
var {
StyleSheet,
Text,
View,
} = React;
var Svg = require('./Svg');
var Path = require('./Path');
var TimerMixin = require('react-timer-mixin');
var Wave = React.createClass({
mixins: [TimerMixin],
getInitialState() {
return {t: 0}
},
componentDidMount() {
this.setInterval(this.updateTime, 16);
},
updateTime() {
this.setState({t: this.state.t + 0.05});
},
render() {
return (
<View style={{flex: 1, backgroundColor: 'black', justifyContent: 'center', alignItems: 'center'}}>
<Svg width={500} height={500} style={{width: 320, height: 350}}
forceUpdate={this.state.t.toString()}>
<Path fill="none" stroke="#00D8FF" strokeWidth="3" strokeMiterlimit="10"
d={drawSine(this.state.t)} />
</Svg>
</View>
);
}
});
module.exports = Wave;