Last active
June 9, 2017 13:28
-
-
Save delacannon/f21d2f3df93e8f30650e to your computer and use it in GitHub Desktop.
Tyranobuilder Snow Effect
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
;============================================================ | |
; Particles - Snow | |
;============================================================ | |
*init_particles | |
[html name='part_layer'] | |
<script> | |
$(".layer_free").css({ | |
"z-index":29 | |
}) | |
</script> | |
<canvas id="part_canvas"></canvas> | |
[endhtml] | |
[iscript] | |
tf.part_speed=1; | |
[endscript] | |
[macro name="snow"] | |
[iscript] | |
(function() { | |
var requestAnimationFrame = window.requestAnimationFrame | |
|| window.mozRequestAnimationFrame | |
|| window.webkitRequestAnimationFrame | |
|| window.msRequestAnimationFrame || | |
function(callback) { | |
window.setTimeout(callback, 1000 / 60); | |
}; | |
window.requestAnimationFrame = requestAnimationFrame; | |
})(); | |
var canvas = document.getElementById("part_canvas"); | |
var ctx = canvas.getContext("2d"); | |
var W = window.innerWidth; | |
var H = window.innerHeight; | |
canvas.width = W; | |
canvas.height = H; | |
var angle = 0; | |
var numParticles = 500; | |
var particles = []; | |
for (var i = 0; i < numParticles; i++) { | |
particles.push({ | |
x: Math.random()*W, | |
y: Math.random()*H, | |
radius: Math.random()*4+1, | |
d:Math.random()*numParticles | |
}) | |
} | |
function drawParticles() { | |
ctx.clearRect(0, 0, W, H); | |
ctx.fillStyle = "rgba(255, 255, 255, "+0.8+""; | |
ctx.beginPath(); | |
for (var i = 0; i < numParticles; i++) { | |
var f = particles[i]; | |
ctx.moveTo(f.x, f.y); | |
ctx.arc(f.x, f.y, f.radius, 0, Math.PI*2, true); | |
} | |
ctx.fill(); | |
moveParticles(); | |
} | |
function moveParticles() { | |
angle +=0.01 | |
for (var i = 0; i < numParticles; i++) { | |
var f = particles[i]; | |
f.y += Math.cos(angle+f.d) + 1 + f.radius/2 * tf.part_speed; | |
f.x += Math.sin(angle); | |
if (f.x > W+5 || f.x < -5 || f.y > H) { | |
if (i%3 > 0) { | |
particles[i] = {x: Math.random()*W, y: -10, radius: f.radius,d:f.d}; | |
} else { | |
if (Math.sin(angle) > 0) { | |
particles[i] = {x: -5, y: Math.random()*H, radius: f.radius,d:f.d}; | |
} else { | |
particles[i] = {x: W+5, y: Math.random()*H, radius: f.radius,d:f.d}; | |
} | |
} | |
} | |
} | |
} | |
function init() { | |
canvas.style.webkitFilter = "blur(0.75px)"; | |
drawParticles(); | |
} | |
setInterval(init, 30); | |
[endscript] | |
[endmacro] | |
;remove particles layer | |
[macro name="remove_particles"] | |
[anim name='part_layer' opacity=0] | |
[wt] | |
[iscript] | |
$("#canvas").remove(); | |
$(".part_layer").remove(); | |
[endscript] | |
[endmacro] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi! delacannon! i wonder if u answer this question..im learning.
thx in advance!
ps. im working on minigame in tyranobuilder. it seems hard to destroy the minigame and the html layer and get out naturally.