Skip to content

Commit fef3c09

Browse files
committed
Created a small little animation thing.
1 parent 54b6acc commit fef3c09

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

landing/landing.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
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+
115
window.onload = function(){
216
var canvas = document.getElementById("landing_canvas");
317
var context = canvas.getContext("2d")
@@ -12,6 +26,10 @@ window.onload = function(){
1226
var prevTick = Date.now();
1327
var deltaTime = 0;
1428
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;
1533
var draw = function(){
1634
requestAnimationFrame(draw);
1735
context.canvas.width = window.innerWidth;
@@ -20,24 +38,30 @@ window.onload = function(){
2038
deltaTime = (currentTick - prevTick) / 1000;
2139
prevTick = currentTick;
2240

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
2553
}
26-
context.translate(window.innerWidth/2, window.innerHeight/2)
54+
55+
context.translate(squareX, squareY)
2756
context.rotate(rot * (Math.PI/180))
28-
rect(100, 100, "white");
29-
rect(33, 100, "red");
57+
whiteSquare.draw();
58+
//redStripe.draw();
3059
ticker += deltaTime;
3160
}
3261

3362
var fillBg = function(color){
3463
context.fillStyle = color;
3564
context.fillRect(0, 0, window.innerWidth, window.innerHeight);
3665
}
37-
38-
var rect = function(w, h, color){
39-
context.fillStyle = color;
40-
context.fillRect(-w/2, -h/2, w, h);
41-
}
4266
requestAnimationFrame(draw);
4367
}

0 commit comments

Comments
 (0)