-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Kresten Laust <[email protected]>
- Loading branch information
1 parent
9133300
commit ecc5358
Showing
5 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
d = new Date(); | ||
|
||
if(d.getMonth() == 3 && d.getDate() == 20){ | ||
spawn_man(); | ||
spawn_beaver(); | ||
animate_man(); | ||
animate_beaver(); | ||
} | ||
|
||
function spawn_beaver() { | ||
const beaver = document.createElement('div'); | ||
beaver.classList.add("beaver"); | ||
const beaverpng = document.createElement("img") | ||
beaverpng.src = "/static/stregsystem/beaver.gif"; | ||
beaverpng.classList.add("beaverpng"); | ||
beaver.appendChild(beaverpng); | ||
document.body.querySelector(".beaver-container").appendChild(beaver); | ||
} | ||
|
||
function spawn_man() { | ||
|
||
const manden = document.createElement('div'); | ||
manden.classList.add("manden"); | ||
const mandpng = document.createElement("img") | ||
mandpng.src = "/static/stregsystem/man.gif"; | ||
mandpng.classList.add("mandenpng") | ||
manden.appendChild(mandpng); | ||
document.body.querySelector(".men-container").appendChild(manden); | ||
} | ||
|
||
function animate_man() { | ||
const man = document.body.querySelector(".manden"); | ||
const manpng = document.body.querySelector(".mandenpng"); | ||
const beaver = document.body.querySelector(".beaver"); | ||
|
||
const manRect = man.getBoundingClientRect(); | ||
const beaverRect = beaver.getBoundingClientRect(); | ||
|
||
var dx = beaverRect.left - manRect.left; | ||
var dy = beaverRect.top - manRect.top; | ||
|
||
var newX = manRect.left + Math.sign(dx) * Math.min(Math.abs(dx), 1); | ||
var newY = manRect.top + Math.sign(dy) * Math.min(Math.abs(dy), 1); | ||
|
||
var angle = Math.atan2(dy, dx); | ||
|
||
man.style.left = newX + "px"; | ||
man.style.top = newY + "px"; | ||
|
||
manpng.style.transform = `rotate(${angle}rad)`; | ||
requestAnimationFrame(animate_man); | ||
} | ||
|
||
function animate_beaver() { | ||
const beaver = document.body.querySelector(".beaver"); | ||
|
||
var currentRect = beaver.getBoundingClientRect(); | ||
var screenWidth = window.innerWidth; | ||
var screenHeight = window.innerHeight; | ||
|
||
var random_x = (Math.random() - 0.5) * 30; | ||
var random_y = (Math.random() - 0.5) * 30; | ||
|
||
var next_x = currentRect.left + random_x; | ||
var next_y = currentRect.top + random_y; | ||
|
||
if (next_x < 0) { | ||
next_x = 0; | ||
} else if (next_x > screenWidth - currentRect.width) { | ||
next_x = screenWidth - currentRect.width; | ||
} | ||
if (next_y < 0) { | ||
next_y = 0; | ||
} else if (next_y > screenHeight - currentRect.height) { | ||
next_y = screenHeight - currentRect.height; | ||
} | ||
|
||
beaver.style.left = next_x + "px"; | ||
beaver.style.top = next_y + "px"; | ||
|
||
requestAnimationFrame(animate_beaver); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.mandenpng{ | ||
width: 100px; | ||
} | ||
|
||
.beaverpng{ | ||
width: 100px; | ||
} | ||
|
||
.manden{ | ||
position: fixed; | ||
} | ||
|
||
.beaver{ | ||
|
||
position: fixed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters