Created
August 6, 2013 06:57
-
-
Save esmasui/6162662 to your computer and use it in GitHub Desktop.
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
importJS(["lib/MOON.js", "lib/enchant.js", "lib/ui.enchant.js", "lib/puppet.enchant.js", "lib/moon.puppet.enchant.js"], function() { | |
enchant(); | |
enchant.puppet.prepareTheatre(); | |
StickerPuppet.create("", { | |
filename: "chara1.png", | |
w: 48, | |
h: 48, | |
behavior: [{ | |
stickertap: function(event) { | |
MOON.uploadCurrentPageToEvernote(function() { | |
var sx = this.x, | |
sy = this.y, | |
sw = this.width, | |
sh = this.height, | |
cx = sx + sw / 2, | |
cy = sy + sh / 2; | |
var theatre = enchant.puppet.Theatre.instance; | |
var page = MOON.getCurrentPage(); | |
var backing = page.backing; | |
var paper = MOON.getPaperJSON(backing); | |
var strokes = paper.strokes; | |
var positions = []; | |
var data, x, y; | |
for(var i = 0, l = strokes.length; i < l; i++) { | |
data = strokes[i].data; | |
for(var j = 0, ll = data.length; j < ll; j += 3) { | |
x = data[j]; | |
y = data[j + 1]; | |
positions.push(x, y); | |
} | |
} | |
var positionsNum = positions.length / 2; | |
var k = 0; | |
function kirakira() { | |
if(this.frame % 3 !== 0) { | |
return; | |
} | |
var particles = []; | |
var t = positionsNum / 50; | |
var p, x, y, vx, vy; | |
for(var i = 0; i < t; i++) { | |
p = Math.floor(Math.random() * positionsNum) * 2; | |
x = positions[p]; | |
y = positions[p + 1]; | |
vx = (cx - x) / 200; | |
vy = (cy - y) / 200; | |
if(Math.random() < 0.3) { | |
vx = vy = 0; | |
} | |
particles.push(x, y, vx, vy, 20); | |
} | |
MOON.showParticles(particles); | |
if(k == 2) { | |
theatre.addEventListener(enchant.Event.ENTER_FRAME, tame); | |
} | |
if(k > 10) { | |
theatre.removeEventListener(enchant.Event.ENTER_FRAME, kirakira); | |
} | |
k++; | |
} | |
var a = 0; | |
function tame() { | |
if(this.frame % 3 !== 0) { | |
return; | |
} | |
var particles = []; | |
var l = a == 6 ? 45 : 15; | |
var x, y, vx, vy; | |
for(var i = 0; i < l; i++) { | |
x = cx + Math.random() * sw / 2 - sw / 4; | |
y = cy + Math.random() * sh / 2 - sh / 4; | |
vx = vy = 0; | |
if(a == 6) { | |
vy = -1.5; | |
} | |
particles.push(x, y, vx, vy, 40); | |
} | |
if(a > 5) { | |
theatre.removeEventListener(enchant.Event.ENTER_FRAME, tame); | |
setTimeout(function() { | |
MOON.showParticles(particles); | |
setTimeout(function() { | |
MOON.alert("Evernoteに保存しました", function() { | |
enchant.puppet.stopTheatre(); | |
}); | |
}, 1500); | |
}, 1500); | |
} else { | |
MOON.showParticles(particles); | |
} | |
a++; | |
} | |
theatre.addEventListener(enchant.Event.ENTER_FRAME, kirakira); | |
}.bind(this), function() { | |
MOON.alert('Evernoteへの\nアップロードに失敗しました', function() { | |
MOON.finish(); | |
}); | |
}); | |
} | |
}] | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment