silverwire #9382(2009/07/17 13:15 GMT) [ JavaScript ] Rating0/0=0.00
自分のマシンは CPUが Pentium 4 (2.66GHz)、メモリが 512MBとリ ソースが貧弱なためか、うまく動作してくれませんでした。 なので、 #9331を参考に table要素を利用したものへと書き直して みました。 念のため、以下のブラウザーで動作を確認してあります。 Firefox 2.0.0.6 Internet Explorer 6.0.29 Google Chrome 1.0.154.48 Opera 9.23 Safari 3.1.2 Firefox, Google Chrome, Safariは CPUをほとんど食わないのです が、 Internet Explorerと Operaはともに CPU使用率が高く、動作 も遅かったです。(実装の違いですかね? )
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
<html> <head> <style type="text/css"> .C_0 { background-color : #ffffff; height : 3px; width : 3px; } .C_1 { background-color : #000000; height : 3px; width : 3px; } </style> <script type="text/javascript"> Function.prototype.repeat = function (t, o) { var _ = this; return setInterval(function () { _.apply(o); }, t); }; var $ = function (i) { return document.getElementById(i); }; var USER_AGENT = navigator.userAgent.toLowerCase(); var CLASS_NAME = (USER_AGENT.indexOf('msie') > -1) ? 'className' : 'class'; var Colony = function (w, h) { this.w = w; this.h = h; this.generate = function () { var i, j; document.write('<table border="0" cellpadding="0" cellspacing="0">'); for (j = 0; j < this.h; j++) { document.write('<tr>'); for (i = 0; i < this.w; i++) document.write('<td id="' + i + '_' + j + '" class="C_0"></td>'); document.write('</tr>'); } document.write('</table>'); }; }; var Ant = function (x, y, w, h) { this.x = x; this.y = y; this.dx = -1; this.dy = 0; this.w = w; this.h = h; this.id = 0; this.move = function () { var C = $(this.x + '_' + this.y); var c; var t; if (this.x < 0 || this.x >= this.w || this.y < 0 || this.y >= this.h) { alert('DEAD END ...'); clearTimeout(this.id); return; } if (c = ((C.getAttribute(CLASS_NAME)).split('_')[1] ^ 1)) { // 反転 t = this.dx; this.dx = this.dy; this.dy = -t; } else { t = this.dx; this.dx = -this.dy; this.dy = t; } C.setAttribute(CLASS_NAME, 'C_' + c); this.x += this.dx; this.y += this.dy; if (!this.id) this.id = this.move.repeat(10, this); }; }; </script> </head> <body> <script type="text/javascript"> var W = 100, H = 100; new Colony(W, H).generate(); new Ant(50, 50, W, H).move(); </script> </body> </html>
Rating0/0=0.00-0+
[ reply ]
silverwire
#9382()
[
JavaScript
]
Rating0/0=0.00
Rating0/0=0.00-0+
[ reply ]