1
1
class Rectangle {
2
2
constructor ( w , h , color , context ) {
3
- this . w = w ;
4
- this . h = h ;
3
+ this . size = new vec2 ( w , h ) ;
5
4
this . color = color ;
6
5
this . context = context ;
6
+ this . rotation = 0 ;
7
+ this . position = new vec2 ( 0 , 0 ) ;
8
+ this . parent ;
9
+ }
10
+ transform ( ) {
11
+ if ( this . parent ) {
12
+ this . context . translate ( this . parent . position . x , this . parent . position . y ) ;
13
+ this . context . rotate ( this . parent . rotation * ( Math . PI / 180 ) ) ;
14
+ }
15
+ this . context . translate ( this . position . x , this . position . y )
16
+ this . context . rotate ( this . rotation * ( Math . PI / 180 ) ) ;
17
+
7
18
}
8
19
draw ( ) {
20
+ this . transform ( ) ;
9
21
this . context . fillStyle = this . color ;
10
- this . context . fillRect ( - this . w / 2 , - this . h / 2 , this . w , this . h ) ;
22
+ this . context . fillRect ( - this . size . x / 2 , - this . size . y / 2 , this . size . x , this . size . y ) ;
23
+ this . context . resetTransform ( ) ;
11
24
}
12
25
}
13
26
27
+ class vec2 {
28
+ constructor ( x , y ) {
29
+ this . x = x ;
30
+ this . y = y ;
31
+ }
32
+ add ( v ) {
33
+ return new vec2 ( this . x + v . x , this . y + v . y ) ;
34
+ }
35
+ sub ( v ) {
36
+ return new vec2 ( this . x - v . x , this . y - v . y ) ;
37
+ }
38
+ set ( x , y ) {
39
+ this . x = x ;
40
+ this . y = y ;
41
+ }
42
+ }
14
43
15
44
window . onload = function ( ) {
16
45
var canvas = document . getElementById ( "landing_canvas" ) ;
@@ -27,35 +56,56 @@ window.onload = function(){
27
56
var deltaTime = 0 ;
28
57
var rot = 0
29
58
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 ;
59
+ var redStripe = new Rectangle ( 0 , 0 , "red" , context ) ;
60
+ redStripe . parent = whiteSquare ;
61
+
62
+ var squareOffset = new vec2 ( 0 , 0 ) ;
63
+ var screenCenter = new vec2 ( window . innerWidth / 2 , window . innerHeight / 2 ) ;
64
+
65
+ whiteSquare . position = screenCenter ;
66
+
33
67
var draw = function ( ) {
34
68
requestAnimationFrame ( draw ) ;
35
69
context . canvas . width = window . innerWidth ;
36
70
context . canvas . height = window . innerHeight ;
71
+
72
+ screenCenter . set ( window . innerWidth / 2 , window . innerHeight / 2 )
73
+
37
74
let currentTick = Date . now ( )
38
75
deltaTime = ( currentTick - prevTick ) / 1000 ;
39
76
prevTick = currentTick ;
77
+ let minimumDimension = Math . min ( window . innerWidth , window . innerHeight ) ;
78
+ context . font = ( window . innerWidth / 10 ) + 'px Roboto' ;
79
+ console . log ( context . font )
40
80
41
81
if ( ticker < 1 ) {
42
- squareX = window . innerWidth / 2 ;
43
- squareY = window . innerHeight / 2 ;
44
- whiteSquare . w -= deltaTime * 3900 ;
45
- whiteSquare . h -= deltaTime * 3900 ;
82
+ whiteSquare . position = screenCenter ;
83
+ whiteSquare . size . x -= deltaTime * ( 4000 - minimumDimension / 6 ) ;
84
+ whiteSquare . size . y -= deltaTime * ( 4000 - minimumDimension / 6 ) ;
46
85
rot += 765 * deltaTime ;
47
86
} else if ( ticker > 1 && ticker < 1.5 ) {
48
- rot -= 720 * ( deltaTime * 1.5 ) ;
87
+ let sqDiam = Math . sqrt ( 2 * ( Math . pow ( whiteSquare . size . x / 2 , 2 ) ) ) ;
88
+ squareOffset . x += ( context . measureText ( "FradZGenius" ) . width / 2 + sqDiam + 25 ) * ( deltaTime / .5 ) ;
89
+ console . log ( squareOffset . x )
90
+ whiteSquare . position = screenCenter . sub ( squareOffset ) ;
91
+ whiteSquare . size . x = minimumDimension / 6 ;
92
+ whiteSquare . size . y = minimumDimension / 6 ;
93
+ whiteSquare . rotation -= 855 * ( deltaTime / .5 ) ;
49
94
squareX = window . innerWidth / 2 - ( ticker - 1 ) * 500 ;
50
95
//TODO:
51
96
//scaling with window maybe
52
97
//uhhh finish animation
98
+ } else {
99
+ context . fillStyle = 'rgba(255,255,255,' + 1 + ')' ;
100
+ context . textAlign = "center"
101
+ context . textBaseline = "middle"
102
+ context . fillText ( "FradZGenius" , window . innerWidth / 2 , window . innerHeight / 2 ) ;
103
+ redStripe . size . x = whiteSquare . size . x / 3
104
+ redStripe . size . y = whiteSquare . size . y ;
53
105
}
54
106
55
- context . translate ( squareX , squareY )
56
- context . rotate ( rot * ( Math . PI / 180 ) )
57
107
whiteSquare . draw ( ) ;
58
- // redStripe.draw();
108
+ redStripe . draw ( ) ;
59
109
ticker += deltaTime ;
60
110
}
61
111
0 commit comments