1
+ class Rectangle {
2
+ constructor ( w , h , color , context ) {
3
+ this . w = w ;
4
+ this . h = h ;
5
+ this . color = color ;
6
+ this . context = context ;
7
+ }
8
+ draw ( ) {
9
+ this . context . fillStyle = this . color ;
10
+ this . context . fillRect ( - this . w / 2 , - this . h / 2 , this . w , this . h ) ;
11
+ }
12
+ }
13
+
14
+
1
15
window . onload = function ( ) {
2
16
var canvas = document . getElementById ( "landing_canvas" ) ;
3
17
var context = canvas . getContext ( "2d" )
@@ -12,6 +26,10 @@ window.onload = function(){
12
26
var prevTick = Date . now ( ) ;
13
27
var deltaTime = 0 ;
14
28
var rot = 0
29
+ var whiteSquare = new Rectangle ( 4000 , 4000 , "white" , context ) ;
30
+ var redStripe = new Rectangle ( 33 , 100 , "red" , context ) ;
31
+ var squareX = window . innerWidth / 2 ;
32
+ var squareY = window . innerHeight / 2 ;
15
33
var draw = function ( ) {
16
34
requestAnimationFrame ( draw ) ;
17
35
context . canvas . width = window . innerWidth ;
@@ -20,24 +38,30 @@ window.onload = function(){
20
38
deltaTime = ( currentTick - prevTick ) / 1000 ;
21
39
prevTick = currentTick ;
22
40
23
- if ( ticker < 2.125 ) {
24
- rot += 360 * deltaTime ;
41
+ if ( ticker < 1 ) {
42
+ squareX = window . innerWidth / 2 ;
43
+ squareY = window . innerHeight / 2 ;
44
+ whiteSquare . w -= deltaTime * 3900 ;
45
+ whiteSquare . h -= deltaTime * 3900 ;
46
+ rot += 765 * deltaTime ;
47
+ } else if ( ticker > 1 && ticker < 1.5 ) {
48
+ rot -= 720 * ( deltaTime * 1.5 ) ;
49
+ squareX = window . innerWidth / 2 - ( ticker - 1 ) * 500 ;
50
+ //TODO:
51
+ //scaling with window maybe
52
+ //uhhh finish animation
25
53
}
26
- context . translate ( window . innerWidth / 2 , window . innerHeight / 2 )
54
+
55
+ context . translate ( squareX , squareY )
27
56
context . rotate ( rot * ( Math . PI / 180 ) )
28
- rect ( 100 , 100 , "white" ) ;
29
- rect ( 33 , 100 , "red" ) ;
57
+ whiteSquare . draw ( ) ;
58
+ //redStripe.draw( );
30
59
ticker += deltaTime ;
31
60
}
32
61
33
62
var fillBg = function ( color ) {
34
63
context . fillStyle = color ;
35
64
context . fillRect ( 0 , 0 , window . innerWidth , window . innerHeight ) ;
36
65
}
37
-
38
- var rect = function ( w , h , color ) {
39
- context . fillStyle = color ;
40
- context . fillRect ( - w / 2 , - h / 2 , w , h ) ;
41
- }
42
66
requestAnimationFrame ( draw ) ;
43
67
}
0 commit comments