@@ -2,72 +2,72 @@ import Engine from "./engine";
2
2
import { Leafer , Rect } from "leafer-ui" ;
3
3
4
4
class LeaferEngine extends Engine {
5
- constructor ( ) {
6
- super ( ) ;
7
- this . canvas = document . createElement ( "canvas" ) ;
8
- this . canvas . width = this . width ;
9
- this . canvas . height = this . height ;
10
- this . content . appendChild ( this . canvas ) ;
11
- }
5
+ constructor ( ) {
6
+ super ( ) ;
7
+ this . canvas = document . createElement ( "canvas" ) ;
8
+ this . canvas . width = this . width ;
9
+ this . canvas . height = this . height ;
10
+ this . content . appendChild ( this . canvas ) ;
11
+ }
12
12
13
- init ( ) {
14
- this . leaferCanvas = new Leafer ( {
15
- view : this . canvas ,
16
- width : this . width ,
17
- height : this . height ,
18
- } )
19
- this . leaferCanvas . pixelRatio = window . devicePixelRatio ;
20
- window . canvas = this . leaferCanvas ;
21
- }
13
+ init ( ) {
14
+ this . leaferCanvas = new Leafer ( {
15
+ view : this . canvas ,
16
+ width : this . width ,
17
+ height : this . height ,
18
+ } )
19
+ this . leaferCanvas . pixelRatio = window . devicePixelRatio ;
20
+ window . canvas = this . leaferCanvas ;
21
+ }
22
22
23
- animate ( ) {
23
+ animate ( ) {
24
24
25
- for ( let i = 0 ; i < this . count . value ; i ++ ) {
26
- const rect = this . rects [ i ] ;
27
- rect . x -= rect . speed ;
28
- rect . el . x = rect . x ;
29
- if ( rect . x + rect . width < 0 ) {
30
- rect . x = this . width + rect . width ;
31
- }
32
- }
25
+ for ( let i = 0 ; i < this . count . value ; i ++ ) {
26
+ const rect = this . rects [ i ] ;
27
+ rect . x -= rect . speed ;
28
+ rect . el . x = rect . x ;
29
+ if ( rect . x + rect . width < 0 ) {
30
+ rect . x = this . width + rect . width ;
31
+ }
32
+ }
33
33
34
- this . meter . tick ( ) ;
34
+ this . meter . tick ( ) ;
35
35
36
- this . request = requestAnimationFrame ( ( ) => this . animate ( ) ) ;
37
- }
36
+ this . request = requestAnimationFrame ( ( ) => this . animate ( ) ) ;
37
+ }
38
38
39
- render ( ) {
40
- // clear the canvas
41
- this . leaferCanvas . removeAll ( true ) ;
42
- this . cancelAnimationFrame ( this . request ) ;
39
+ render ( ) {
40
+ // clear the canvas
41
+ this . leaferCanvas . removeAll ( true ) ;
42
+ this . cancelAnimationFrame ( this . request ) ;
43
43
44
- // rectangle creation
45
- const rects = new Array ( this . count ) ;
46
- for ( let i = 0 ; i < this . count . value ; i ++ ) {
47
- const x = Math . random ( ) * this . width ;
48
- const y = Math . random ( ) * this . height ;
49
- const size = 10 + Math . random ( ) * 40 ;
50
- const speed = 1 + Math . random ( ) ;
44
+ // rectangle creation
45
+ const rects = new Array ( this . count ) ;
46
+ for ( let i = 0 ; i < this . count . value ; i ++ ) {
47
+ const x = Math . random ( ) * this . width ;
48
+ const y = Math . random ( ) * this . height ;
49
+ const size = 10 + Math . random ( ) * 40 ;
50
+ const speed = 1 + Math . random ( ) ;
51
51
52
- const fRect = new Rect ( {
53
- width : size ,
54
- height : size ,
55
- fill : "white" ,
56
- stroke : "black" ,
57
- y,
58
- x,
59
- } ) ;
60
- rects [ i ] = { x, y, width : size , height : size / 2 , speed, el : fRect } ;
61
- }
62
- this . rects = rects ;
63
- this . leaferCanvas . addMany ( ...rects . map ( ( rect ) => rect . el ) ) ;
52
+ const fRect = new Rect ( {
53
+ width : size ,
54
+ height : size ,
55
+ fill : "white" ,
56
+ stroke : "black" ,
57
+ y,
58
+ x,
59
+ } ) ;
60
+ rects [ i ] = { x, y, width : size , height : size / 2 , speed, el : fRect } ;
61
+ }
62
+ this . rects = rects ;
63
+ this . leaferCanvas . addMany ( ...rects . map ( ( rect ) => rect . el ) ) ;
64
64
65
- this . request = requestAnimationFrame ( ( ) => this . animate ( ) ) ;
66
- }
65
+ this . request = requestAnimationFrame ( ( ) => this . animate ( ) ) ;
66
+ }
67
67
}
68
68
69
69
document . addEventListener ( "DOMContentLoaded" , ( ) => {
70
- const engine = new LeaferEngine ( ) ;
71
- engine . init ( ) ;
72
- engine . render ( ) ;
70
+ const engine = new LeaferEngine ( ) ;
71
+ engine . init ( ) ;
72
+ engine . render ( ) ;
73
73
} ) ;
0 commit comments