1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| function universe() { window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame; var e, t, o, n, a = .05, s = document.getElementById("universe"), c = !0, i = "226,225,224", r = [];
function l() { e = window.innerWidth, t = window.innerHeight, o = .216 * e, s.setAttribute("width", e), s.setAttribute("height", t) }
function d() { n.clearRect(0, 0, e, t); for (var o = r.length, a = 0; a < o; a++) { var s = r[a]; s.move(), s.fadeIn(), s.fadeOut(), s.draw() } }
function b() { this.reset = function() { this.giant = u(3), this.comet = !this.giant && !c && u(10), this.x = m(0, e - 10), this.y = m(0, t), this.r = m(1.1, 2.6), this.dx = m(a, 6 * a) + (this.comet + 1 - 1) * a * m(50, 120) + .1, this.dy = -m(a, 6 * a) - (this.comet + 1 - 1) * a * m(50, 120), this.fadingOut = null, this.fadingIn = !0, this.opacity = 0, this.opacityTresh = m(.2, 1 - .4 * (this.comet + 1 - 1)), this.do = m(5e-4, .002) + .001 * (this.comet + 1 - 1) }, this.fadeIn = function() { this.fadingIn && (this.fadingIn = !(this.opacity > this.opacityTresh), this.opacity += this.do) }, this.fadeOut = function() { this.fadingOut && (this.fadingOut = !(this.opacity < 0), this.opacity -= this.do / 2, (this.x > e || this.y < 0) && (this.fadingOut = !1, this.reset())) }, this.draw = function() { if (n.beginPath(), this.giant) n.fillStyle = "rgba(180,184,240," + this.opacity + ")", n.arc(this.x, this.y, 2, 0, 2 * Math.PI, !1); else if (this.comet) { n.fillStyle = "rgba(" + i + "," + this.opacity + ")", n.arc(this.x, this.y, 1.5, 0, 2 * Math.PI, !1); for (var e = 0; e < 30; e++) n.fillStyle = "rgba(" + i + "," + (this.opacity - this.opacity / 20 * e) + ")", n.rect(this.x - this.dx / 4 * e, this.y - this.dy / 4 * e - 2, 2, 2), n.fill() } else n.fillStyle = "rgba(226,225,142," + this.opacity + ")", n.rect(this.x, this.y, this.r, this.r); n.closePath(), n.fill() }, this.move = function() { this.x += this.dx, this.y += this.dy, !1 === this.fadingOut && this.reset(), (this.x > e - e / 4 || this.y < 0) && (this.fadingOut = !0) }, setTimeout((function() { c = !1 }), 50) }
function u(e) { return Math.floor(1e3 * Math.random()) + 1 < 10 * e }
function m(e, t) { return Math.random() * (t - e) + e } l(), window.addEventListener("resize", l, !1), function() { n = s.getContext("2d"); for (var e = 0; e < o; e++) r[e] = new b, r[e].reset(); d() }(), function e() { d(), window.requestAnimationFrame(e) }() } universe()
|