
{source}<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/TweenMax.min.js"></script><svg id="galaxy">
<g id="stars"></g>
</svg>
<style>
#galaxy {
background-image: url("/images/suto.png");
background-size: contain;
background-repeat: no-repeat;
left: 0;
top: 0;
width: 2661px;
height: 200px;
position: relative;
}
</style>
<script>
function mainFunc() {
var svgNS = "http://www.w3.org/2000/svg"
var starsGroup = document.getElementById("stars");
var galaxy = document.getElementById("galaxy").getBoundingClientRect();
var center = { x: galaxy.width / 2, y: galaxy.height / 2 };
var stars = []
var tweens = []
window.onresize = function () {
galaxy = document.getElementById("galaxy").getBoundingClientRect();
center = { x: galaxy.width / 2, y: galaxy.height / 2 };
};
// STAR OPTIONS //////////////////////////////////////////////////////////////
var maxRad = Math.sqrt(Math.pow(center.x, 2) + Math.pow(center.y, 2));
var starCount = 100;
var speed = 1;
var innerRadius = 200;
var minSize = 1;
var maxSize = 2;
//////////////////////////////////////////////////////////////////////////////
var startPos, tranOrigin, time;
for (var i = 0; i < starCount; ++i) {
// add new star
var star = document.createElementNS(svgNS, "circle");
startPos = {
x: Math.random() * center.x * 2,
y: Math.random() * center.y * 2
};
// set basic tag attributes
star.setAttribute("class", "star");
star.setAttribute("fill", "#A8A8A8");
star.setAttribute("stroke", "none");
star.setAttribute("cx", startPos.x);
star.setAttribute("cy", startPos.y);
star.setAttribute("r", Math.random() * maxSize + minSize);
// add to internal array and svg group
stars.push(star);
starsGroup.appendChild(star);
tranOrigin = "" + (center.x - startPos.x) + "px " +
(center.y - startPos.y) + "px";
time = Math.pow(speed * 0.01, -1) * Math.pow(star.getAttribute("r"), -1);
//console.log(time)
tweens.push(TweenMax.to(star, time, {
transformOrigin: tranOrigin,
rotation: 360,
ease: Power0.easeNone,
repeat: -1
}));
}
}
document.addEventListener("DOMContentLoaded", mainFunc);
</script>{/source}
Certificate of Attendance - MCH23
