@@ -10,15 +10,43 @@ class Demo extends Component {
10
10
width : 400 ,
11
11
height : 400 ,
12
12
brushRadius : 10 ,
13
- lazyRadius : 12
13
+ lazyRadius : 12 ,
14
+ backgroundImg : "https://upload.wikimedia.org/wikipedia/commons/a/a1/Nepalese_Mhapuja_Mandala.jpg" ,
15
+ imgs : [
16
+ "https://upload.wikimedia.org/wikipedia/commons/a/a1/Nepalese_Mhapuja_Mandala.jpg" ,
17
+ "https://i.imgur.com/a0CGGVC.jpg"
18
+ ]
14
19
} ;
20
+
15
21
componentDidMount ( ) {
16
22
// let's change the color randomly every 2 seconds. fun!
17
23
window . setInterval ( ( ) => {
18
24
this . setState ( {
19
25
color : "#" + Math . floor ( Math . random ( ) * 16777215 ) . toString ( 16 )
20
26
} ) ;
21
27
} , 2000 ) ;
28
+
29
+ // let's change the background image every 2 seconds. fun!
30
+ window . setInterval ( ( ) => {
31
+ if (
32
+ this . state . imgs &&
33
+ this . state . imgs . length &&
34
+ this . state . backgroundImg
35
+ ) {
36
+ let img = '' ;
37
+ let imgs = this . state . imgs ;
38
+ for ( let i = 0 ; i < imgs . length ; i ++ ) {
39
+ if ( this . state . backgroundImg !== imgs [ i ] ) {
40
+ img = imgs [ i ] ;
41
+ }
42
+ }
43
+
44
+ this . setState ( {
45
+ backgroundImg : img ,
46
+ } ) ;
47
+ }
48
+ } , 2000 ) ;
49
+
22
50
}
23
51
render ( ) {
24
52
return (
@@ -69,6 +97,13 @@ class Demo extends Component {
69
97
brushColor = "rgba(155,12,60,0.3)"
70
98
imgSrc = "https://upload.wikimedia.org/wikipedia/commons/a/a1/Nepalese_Mhapuja_Mandala.jpg"
71
99
/>
100
+
101
+ < h2 > Refreshable Background Image</ h2 >
102
+ < p > This will refresh the background in every two seconds.</ p >
103
+ < CanvasDraw
104
+ brushColor = "rgba(155,12,60,0.3)"
105
+ imgSrc = { this . state . backgroundImg }
106
+ />
72
107
< h2 > Hide UI</ h2 >
73
108
< p > To hide the UI elements, set the `hideInterface` prop. You can also hide the grid with the `hideGrid` prop.</ p >
74
109
< CanvasDraw hideInterface hideGrid />
0 commit comments