20110719
RMagickをbundlerでロードする
gem 'rmagick', :require => 'RMagick'
:require => 'RMagick'がなくてもcase insensitiveなファイル名の扱いをするOS X上だとエラーにならないし、そうでないOSでもbundle自体は成功して、定数Magickの参照時に初めてエラーになるので少しわかりづらかった。
20110717
20110617
contextfree.jsを書いた
Context Freeというフラクタルを記述するのに便利な言語をJavaScriptに移植した。
Aza Raskinさんがすでに同様のものを作っている(ContextFree.js & Algorithm Ink: Making Art with Javascript « Aza on Design)のだけど、これはContext Freeの最低限の要素を実装したもので本家のギャラリー(CFDG Gallery - CFDG Gallery)にあるものなどはほとんど動作せず、描画のアルゴリズムも異なるため動作してもレンダリング結果が違うということが多い(当時の主要ブラウザのJavaScriptの実行速度を考えるとそれが"ベストプラクティス"だったのだろうけど)。
そこで、本家のものとほぼ同等のレンダリングを行えるものを書いた。ただし、フラクタルの展開時に数万、数十万のオブジェクトを生成する場合があるため実行にそれなりの時間を要し、各ブラウザ間でも顕著なパフォーマンスの違いが見られた。上のサンプルだと手元のMacBook Late 2009においてChromeで10秒、FirefoxとSafariで30秒程度、Operaだと50秒かかった。もっとも、上のものはかなり多くのシェイプを生成しているので、もっと単純なものならどのブラウザでもせいぜい2、3秒で完了する。
実装にあたってはContext Freeの構文解析にJisonというパーサジェネレーターを、描画には普通にCanvas 2D APIを使っている。Context Free 2.xの文法をだいたい網羅しているが、今のところtile directive / path directiveがなく追々実装する予定。
20110606
グリッチ、量子化テーブル
JPEG画像の量子化テーブル定義部のみをグリッチするスクリプトを書いた。
これを用いることで、普通の照英画像をかっこいいかんじにできる。
JPEGヘッダのパース仕方はここが参考になった。
20110517
audio要素が対応しているコーデック
['mpeg', 'mp4', 'wav', 'ogg'].filter(function(type) { return new Audio().canPlayType('audio/' + type) })
で調べられる。
| mp3 | aac | wave | ogg | |
|---|---|---|---|---|
| Chrome 12 | maybe | maybe | maybe | maybe |
| Safari 5 | maybe | maybe | maybe | - |
| Firefox 4 | - | - | maybe | maybe |
| Opera 11 | - | - | maybe | maybe |
| IE 9 | maybe | maybe | - | - |
| iPhone 4 | maybe | maybe | maybe | - |
| Android 2.2 | - | - | - | - |
IEがなぜかwaveに対応してない。Androidはaudio要素はあるがどのコーデックにも対応してない、という感じでおもしろかった。
どの環境でもちゃんと鳴らせるコーデックは存在しないので、使わない方がいい。
20110513
wtfjs
とりあえず試す。
> [,] [] > [,].length 1 > Object.getOwnPropertyDescriptor([,], 0) undefined
'length'だけが設定され、'0'は設定されていない。
対して[undefined]だと'0'もProperty Descriptorがある。
> Object.getOwnPropertyDescriptor([undefined], 0) Object configurable : true, enumerable : true, value : undefined, writable : true, __proto__: Object
Array Literalについて仕様書を見る。(11.1.4 Array Initialiser)
The production ArrayLiteral : [ Elisionopt ] is evaluated as follows:
http://people.mozilla.org/~jorendorff/es5.html#sec-11.1.4
- Let array be the result of creating a new object as if by the expression new Array() where Array is the standard built-in constructor with that name.
- Let pad be the result of evaluating Elision; if not present, use the numeric value zero.
- Call the Put? internal method of array with arguments "length", pad, and false.
- Return array.
Elision: , | Elision , なので、カンマのみ連なってる場合の動作は配列を作成して'length'をカンマの数だけ設定するということになる。
で、console.logとArray.prototype.toStringで出力結果が異なることについて。
> [,,] [] > [,,].toString() ","
console.logについては仕様があるわけではないのでよく分からないけど、少なくともプラパティが存在するかどうかに基づいて列挙しているようだ。一方Array.prorotype.toStringはArray.prototype.joinを行っていて(15.4.4.2 Array.prototype.toString ( ))、Array.prototype.joinはfor (var i = 0; i < length; i++)型の走査を行う(15.4.4.5 Array.prototype.join (separator))ため、このような違いが出る。
気持ちのいい動作ではないけどとりあえず理解はできた。
ちなみにnew Array(n)でも同じ現象は起きる。
> new Array(5) [] > new Array(5).toString() ",,,,"






