Angel Beats! EDっぽいアレ mumoshu Follow 2010-07-02 01:54:25 License: MIT License Fork1 Fav2 View2134 Play Stop Reload Fullscreen Smart Phone Fork tree Readme JavaScript 253 lines HTML 1 lines CSS 1 lines Angel Beats! EDっぽいアレ jQuery v1.4.2 function Point(x, y, text) { this.x = x; this.y = y; this.text = text; } Point.prototype.clone = function() { return new Point(this.x, this.y); }; Point.prototype.add = function(other) { var newPoint = this.clone(); newPoint.x += other.x; newPoint.y += other.y; return newPoint; }; Point.prototype.subtract = function(other) { var newPoint = this.clone(); newPoint.x -= other.x; newPoint.y -= other.y; return newPoint; }; Point.prototype.multiply = function(other) { var newPoint = this.clone(); newPoint.x *= other; newPoint.y *= other; return newPoint.validate(); }; Point.prototype.direction = function() { return Math.atan2(this.y, this.x); }; Point.prototype.toString = function() { return '[Point x=' + this.x + ' y=' + this.y + ']'; }; Point.prototype.validate = function() { if (isNaN(this.x) || isNaN(this.y)) throw new Error('ValidationError: ' + this); return this; }; Point.prototype.drawTo = function(context) { var radius = 2.0; if (this.text) { context.fillStyle = 'black'; context.font = '20px sans-serif'; context.strokeText(this.text, this.x + radius + 5, this.y + radius); } context.fillStyle = 'white'; context.beginPath(); context.arc(this.x, this.y, radius, 0, Math.PI * 2, false); context.closePath(); context.stroke(); context.fill(); }; function Line(begin, end) { this.begin = begin; this.end = end; } Line.prototype.drawTo = function(context) { var b = this.begin; var e = this.end; context.fillStyle = 'red'; context.lineJoin = 'miter'; context.moveTo(b.x, b.y); context.lineTo(e.x, e.y); context.stroke(); context.fill(); }; var number_of_speechs = 0; function Speech(text, position) { var textSplittingStrategies = [ { precondition: function(text) { return text.indexOf(',') > -1; }, split: function(text) { return text.split(" "); } }, { precondition: function(text) { return text.indexOf(' ') > -1; }, split: function(text){ return text.split(" "); } }, { precondition: function(text) { return !text.match(/\s|,|、/); }, split: function(text) { var texts = []; var length = 5; for (var i=0; i<text.length; i+=length) { texts.push(text.substr(i, length)); } return texts; } }, { precondition: function(text) { return text.indexOf('、') > -1; }, split: function(text) { return text.replace("、", "、<d>").split("<d>"); } } ]; function Array_randomSample(ary) { return ary[parseInt(Math.random() * ary.length - 0.00001)]; } this.text = text; var strategies= $.grep(textSplittingStrategies, function(s, index) { return s.precondition(text); }); this.texts = Array_randomSample(strategies).split(text); this.position = position || new Point(50, 50); this.opacity = 1.0; this.fadePerFrame = 0.02; this.magnificationPerFrame = 0.995; this.velocity = 0.2; this.fontSize = 100; this.lifetime = 180; this.restTime = this.lifetime; this.id = number_of_speechs++; } Speech.prototype.fade = function() { this.opacity -= this.fadePerFrame; return this; }; Speech.prototype.minify = function() { var a = this.magnificationPerFrame; this.width *= a; this.height *= a; this.fontSize *= a; return this; }; Speech.prototype.slideTo = function(point) { var velocity = this.velocity; var direction = point.subtract(this.position).direction(); var displacement = new Point(Math.cos(direction), Math.sin(direction)).multiply(velocity); var begin = this.position; this.position = this.position.add(displacement); var end = this.position; new Line(begin, begin.add(displacement.multiply(60))).drawTo(worldContext); return this; }; Speech.prototype.drawTo = function(context) { var c = context; var fontSize = this.fontSize; var position = this.position; c.fillStyle = 'rgba(0, 0, 0, ' + this.restTime / this.lifetime + ')'; c.font = parseInt((fontSize / 4).toFixed(0)) + 'px sans-serif'; c.textAlign = 'left'; c.fillText('[c ' + this.id + ']', position.x, position.y - fontSize); c.font = parseInt(fontSize.toFixed(0)) + 'px sans-serif'; var texts = this.texts.slice(0, parseInt((this.lifetime - this.restTime) / 60) + 1); $.each(texts, function(index, text) { c.fillText(text, position.x, position.y + (index * fontSize)); }); return this; }; var FPS = 60; var WIDTH = 465; var HEIGHT = 465; var worldCanvas = document.getElementById('world'); worldCanvas.width = WIDTH; worldCanvas.height = HEIGHT; var worldContext = worldCanvas.getContext('2d'); var speech = new Speech("Hello! World"); var center = new Point(WIDTH / 2.0, HEIGHT / 2.0, "center"); var texts = [ "Knockin' on heaven's door", "神様もびっくり仰天", "戦いが・・・終わるのか・・・", "消えろっ!", "トイレットペーパーのように惨めに消えろ!", "このままいなくなっても、誰も気づかなそうだからなぁ!", "俺が動くのはゆりっぺの助けになるときだけだ!", "百人・・・戦力が増えたと思え", "次もバンドやるよ!", "よく辿り着けましたね", "手を伸ばせ!", "ここから消えたら、・・・やり直せますかね" ]; var speeches = {}; function spawnSpeech() { var index = parseInt(Math.random() * texts.length - 0.00001); var x = Math.random() * WIDTH; var y = Math.random() * HEIGHT; var position = new Point(x, y); var speech = new Speech(texts[index], position); speeches[speech.id] = speech; } spawnSpeech(); var ticks = 0; var intervalId = setInterval(function() { worldContext.fillStyle = 'white'; worldContext.fillRect(0, 0, WIDTH, HEIGHT); worldContext.fill(); center.drawTo(worldContext); if (ticks++) { if (ticks % 45 === 0) spawnSpeech(); } try { $.each(speeches, function(id, speech) { speech.fade() .minify() .slideTo(center) .drawTo(worldContext); if (--speech.restTime < 0) delete speeches[id]; }); } catch (e) { clearInterval(intervalId); throw e; }; }, 1000.0 / FPS); <canvas id='world'></canvas> Angel Beats! EDっぽいアレ body { background-color: #DDDDDD; } function Point(x, y, text) { this.x = x; this.y = y; this.text = text; } Point.prototype.clone = function() { return new Point(this.x, this.y); }; Point.prototype.add = function(other) { var newPoint = this.clone(); newPoint.x += other.x; newPoint.y += other.y; return newPoint; }; Point.prototype.subtract = function(other) { var newPoint = this.clone(); newPoint.x -= other.x; newPoint.y -= other.y; return newPoint; }; Point.prototype.multiply = function(other) { var newPoint = this.clone(); newPoint.x *= other; newPoint.y *= other; return newPoint.validate(); }; Point.prototype.direction = function() { return Math.atan2(this.y, this.x); }; Point.prototype.toString = function() { return '[Point x=' + this.x + ' y=' + this.y + ']'; }; Point.prototype.validate = function() { if (isNaN(this.x) || isNaN(this.y)) throw new Error('ValidationError: ' + this); return this; }; Point.prototype.drawTo = function(context) { var radius = 2.0; if (this.text) { context.fillStyle = 'black'; context.font = '20px sans-serif'; context.strokeText(this.text, this.x + radius + 5, this.y + radius); } context.fillStyle = 'white'; context.beginPath(); context.arc(this.x, this.y, radius, 0, Math.PI * 2, false); context.closePath(); context.stroke(); context.fill(); }; function Line(begin, end) { this.begin = begin; this.end = end; } Line.prototype.drawTo = function(context) { var b = this.begin; var e = this.end; context.fillStyle = 'red'; context.lineJoin = 'miter'; context.moveTo(b.x, b.y); context.lineTo(e.x, e.y); context.stroke(); context.fill(); }; var number_of_speechs = 0; function Speech(text, position) { var textSplittingStrategies = [ { precondition: function(text) { return text.indexOf(',') > -1; }, split: function(text) { return text.split(" "); } }, { precondition: function(text) { return text.indexOf(' ') > -1; }, split: function(text){ return text.split(" "); } }, { precondition: function(text) { return !text.match(/\s|,|、/); }, split: function(text) { var texts = []; var length = 5; for (var i=0; i<text.length; i+=length) { texts.push(text.substr(i, length)); } return texts; } }, { precondition: function(text) { return text.indexOf('、') > -1; }, split: function(text) { return text.replace("、", "、<d>").split("<d>"); } } ]; function Array_randomSample(ary) { return ary[parseInt(Math.random() * ary.length - 0.00001)]; } this.text = text; var strategies= $.grep(textSplittingStrategies, function(s, index) { return s.precondition(text); }); this.texts = Array_randomSample(strategies).split(text); this.position = position || new Point(50, 50); this.opacity = 1.0; this.fadePerFrame = 0.02; this.magnificationPerFrame = 0.995; this.velocity = 0.2; this.fontSize = 100; this.lifetime = 180; this.restTime = this.lifetime; this.id = number_of_speechs++; } Speech.prototype.fade = function() { this.opacity -= this.fadePerFrame; return this; }; Speech.prototype.minify = function() { var a = this.magnificationPerFrame; this.width *= a; this.height *= a; this.fontSize *= a; return this; }; Speech.prototype.slideTo = function(point) { var velocity = this.velocity; var direction = point.subtract(this.position).direction(); var displacement = new Point(Math.cos(direction), Math.sin(direction)).multiply(velocity); var begin = this.position; this.position = this.position.add(displacement); var end = this.position; new Line(begin, begin.add(displacement.multiply(60))).drawTo(worldContext); return this; }; Speech.prototype.drawTo = function(context) { var c = context; var fontSize = this.fontSize; var position = this.position; c.fillStyle = 'rgba(0, 0, 0, ' + this.restTime / this.lifetime + ')'; c.font = parseInt((fontSize / 4).toFixed(0)) + 'px sans-serif'; c.textAlign = 'left'; c.fillText('[c ' + this.id + ']', position.x, position.y - fontSize); c.font = parseInt(fontSize.toFixed(0)) + 'px sans-serif'; var texts = this.texts.slice(0, parseInt((this.lifetime - this.restTime) / 60) + 1); $.each(texts, function(index, text) { c.fillText(text, position.x, position.y + (index * fontSize)); }); return this; }; var FPS = 60; var WIDTH = 465; var HEIGHT = 465; var worldCanvas = document.getElementById('world'); worldCanvas.width = WIDTH; worldCanvas.height = HEIGHT; var worldContext = worldCanvas.getContext('2d'); var speech = new Speech("Hello! World"); var center = new Point(WIDTH / 2.0, HEIGHT / 2.0, "center"); var texts = [ "Knockin' on heaven's door", "神様もびっくり仰天", "戦いが・・・終わるのか・・・", "消えろっ!", "トイレットペーパーのように惨めに消えろ!", "このままいなくなっても、誰も気づかなそうだからなぁ!", "俺が動くのはゆりっぺの助けになるときだけだ!", "百人・・・戦力が増えたと思え", "次もバンドやるよ!", "よく辿り着けましたね", "手を伸ばせ!", "ここから消えたら、・・・やり直せますかね" ]; var speeches = {}; function spawnSpeech() { var index = parseInt(Math.random() * texts.length - 0.00001); var x = Math.random() * WIDTH; var y = Math.random() * HEIGHT; var position = new Point(x, y); var speech = new Speech(texts[index], position); speeches[speech.id] = speech; } spawnSpeech(); var ticks = 0; var intervalId = setInterval(function() { worldContext.fillStyle = 'white'; worldContext.fillRect(0, 0, WIDTH, HEIGHT); worldContext.fill(); center.drawTo(worldContext); if (ticks++) { if (ticks % 45 === 0) spawnSpeech(); } try { $.each(speeches, function(id, speech) { speech.fade() .minify() .slideTo(center) .drawTo(worldContext); if (--speech.restTime < 0) delete speeches[id]; }); } catch (e) { clearInterval(intervalId); throw e; }; }, 1000.0 / FPS); <canvas id='world'></canvas> body { background-color: #DDDDDD; } use an iframe compat browser, deer Play on jsdo.it games Share Embed QR Tag Download Complete! Description どんなゲームですか? Control Device スマートフォンコントローラー jsdo.it WebSocket Controller» マウス キーボード タッチデバイス Fullscreen 有効 無効 jsdo.it games から削除する Submit Tweet style Design view Code view code <script type="text/javascript" src="http://jsdo.it/blogparts/2Ac6/js?view=design"></script><p class="ttlBpJsdoit" style="width: 465px; margin: 0; text-align: right; font-size: 11px;"><a href="http://jsdo.it/mumoshu/2Ac6" title="Angel Beats! EDっぽいアレ">Angel Beats! EDっぽいアレ - jsdo.it - share JavaScript, HTML5 and CSS</a></p> Tweet twitter Favorite by fingaholic nahibari Forked sort new page view favorite forked forked from: Angel Beats! EDっぽ.. spagetty 00 154views 244/1/1