Created
March 31, 2013 16:17
-
-
Save segfault87/5281147 to your computer and use it in GitHub Desktop.
술먹고 만든 포니스크립트
This file contains hidden or 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
var pony = { | |
items: [], | |
limit: 4, | |
active: true, | |
initialize: function() { | |
var cookie = document.cookie.split(';'); | |
$('#phj').text('포확찢'); | |
$.each(cookie, function(idx, item) { | |
if (item.indexOf('pohwakjjit') >= 0) { | |
var kv = item.split('='); | |
if (kv[1] == '1') { | |
$('#phj').text('안포확찢'); | |
pony.active = false; | |
return; | |
} | |
} | |
}); | |
setInterval(pony.update, 33); | |
setInterval(pony.emitter, 5000); | |
$('#phj').click(pony.toggle); | |
}, | |
toggle: function() { | |
if (pony.active) | |
pony.activate(false); | |
else | |
pony.activate(true); | |
return false; | |
}, | |
setcookie: function(v) { | |
var date = new Date(); | |
date.setMonth(date.getMonth() + 12); | |
document.cookie = 'pohwakjjit=' + (v ? '1' : '0') + ';expires=' + date + ';domain=s.excf.com;path=/'; | |
}, | |
activate: function(v) { | |
pony.active = v; | |
pony.setcookie(!v); | |
if (v) { | |
$('#phj').text('포확찢'); | |
} else { | |
$.each(pony.items, function(idx, item) { | |
$('body').append($('<img></img>').attr('src', '/static/ponies/bloodsplat.png').attr('class', 'pony').css('top', item.y + 'px').css('left', item.x + 'px')); | |
item.elem.remove(); | |
}); | |
pony.items = []; | |
$('#phj').text('안포확찢'); | |
} | |
}, | |
random: function(min, max) { | |
return Math.floor((Math.random() * (max-min+1)) + min); | |
}, | |
update: function() { | |
if (!pony.active) | |
return; | |
var removeflag = false; | |
$.each(pony.items, function(idx, item) { | |
item.elem.css('top', (item.y + Math.abs(Math.cos(item.life * 0.15)) * 15) + 'px'); | |
item.elem.css('left', item.x + 'px'); | |
item.elem.css('-webkit-transform', 'rotate(' + (Math.cos(item.life * 0.15) * 10) + 'deg)'); | |
item.life += item.velocity; | |
item.x += item.velocity; | |
if (item.x > document.body.clientWidth) { | |
removeflag = true; | |
item.elem.remove(); | |
item.remove = true; | |
} | |
}); | |
if (removeflag) { | |
pony.items = $.grep(pony.items, function(v) { | |
return v.remove == false; | |
}); | |
} | |
}, | |
emitter: function() { | |
if (!pony.active) | |
return; | |
if (pony.items.length > pony.limit) | |
return; | |
/* 50% of chance */ | |
if (pony.random(0, 1) == 0) { | |
var y = pony.random(0, document.body.clientHeight - 8); | |
var elem = $('<img></img>').attr('src', '/static/ponies/pony' + pony.random(1, 6) + '.png').attr('alt', '포확찢').attr('class', 'pony').css('left', '-100px').css('z-index', y); | |
$('body').append(elem); | |
pony.items.push({ | |
elem: elem, | |
y: y, | |
velocity: Math.random() * 4.0 + 0.5, | |
x: -75.0, | |
life: 0.0, | |
remove: false | |
}); | |
} | |
} | |
} | |
$(document).ready(function() { | |
pony.initialize(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment