<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
   <title>polog</title>
   <link rel="alternate" type="text/html" href="http://polog.org/" />
   <link rel="self" type="application/atom+xml" href="http://polog.org/atom.xml" />
   <id>tag:polog.org,2008://1</id>
   <updated>2008-09-29T12:28:06Z</updated>
   
   <generator uri="http://www.sixapart.com/movabletype/">Movable Type 3.34</generator>

<entry>
   <title>Railsのライトニングトーク開催します！</title>
   <link rel="alternate" type="text/html" href="http://polog.org/archives/2008/09/29184518.php" />
   <id>tag:polog.org,2008://1.1681</id>
   
   <published>2008-09-29T09:45:18Z</published>
   <updated>2008-09-29T12:28:06Z</updated>
   
   <summary>直近の情報の上に他のブログと重複してる告知で恐縮ですが、今週末にRails系のラ...</summary>
   <author>
      <name></name>
      
   </author>
   
   <category term="43" label="event" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="45" label="rails" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="ja" xml:base="http://polog.org/">
      <![CDATA[直近の情報の上に他のブログと重複してる告知で恐縮ですが、今週末にRails系のライトニングトークを弊社で開催します

<a href="http://cookpad.typepad.jp/lt/2008/09/award-on-rails-.html">第四回Award on Railsライトニングトーク 参加者募集!</a>
<a href="http://webtama.jp/events/8">登録ページ</a>
10/3(金) <del>16:00</del>20:00より、白金台駅近くのクックパッド株式会社にて開催です]]>
      <![CDATA[なんか↓こんなOppaiエントリの次に書いちゃって企業イメージ的によいのかどうか聞いたら、いいよー^^とのことだったので書いちゃいます。エンジニア的には知らない方多いと思いますが、<a href="http://cookpad.com/">クックパッド</a>はレシピ系のCGMサイトで、現在国内でRailsを利用しているサイトとしては最大です。社内にも特大のキッチンがあったりして、当日にはシェフが来ておもてなし料理が振る舞われる予定になってます
また基本的に敷居はかなり低くて、作ったもの、作ろうとしてるものの構想、便利な運用など、Rails絡んでて誰かに伝えたい、聞きたいってネタがある方はanyone anything発表歓迎です

ちなみに僕の前回の発表は<a href="http://polog.org/archives/2008/01/06180347.php">誤字ェネレータ</a>がらみでこんな感じでした
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/ARFphxszuqY&hl=ja&fs=1"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/ARFphxszuqY&hl=ja&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object>
雰囲気つかみたい人は見てみて下さい


それでは、ご参加お待ちしております


(ついでに追記)
<a href="http://techlife.cookpad.com/">クックパッド開発者ブログ</a>はじめましたー
クックパッドは社員的には4人しかエンジニアがいなかったりして割と大変なんですが、その大変っぷりをオープンにして行けたらなと思います
よろしくお願いします！]]>
   </content>
</entry>
<entry>
   <title>Oppai-Detect 2でコンテンツフィルタリング </title>
   <link rel="alternate" type="text/html" href="http://polog.org/archives/2008/07/27162844.php" />
   <id>tag:polog.org,2008://1.1680</id>
   
   <published>2008-07-27T07:28:44Z</published>
   <updated>2008-07-27T07:55:14Z</updated>
   
   <summary>ずいぶん前にOppai-Detectの精度向上っぷりをtwitterで見せてもら...</summary>
   <author>
      <name></name>
      
   </author>
   
   <category term="5" label="development" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="7" label="funny" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="19" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="ja" xml:base="http://polog.org/">
      <![CDATA[ずいぶん前にOppai-Detectの精度向上っぷりをtwitterで見せてもらって、やべー使いてーなどと思っていたんですが、<a href="http://yusukebe.com/archives/08/07/25/083750.html">いつの間にか公開されてた</a>ので、クライアント側でプロキシ動作するフィルタを書いてみました。おっぱい見れません＞＜

画面的にはこんな感じ。
<a href="http://polog.org/files/porn.png"><img src="http://polog.org/files/porn_thumb.jpg" width="200px"></a>
]]>
      <![CDATA[<pre class="prettyprint">#!/usr/bin/perl
use strict;
use warnings;
use HTTP::Proxy;
use HTTP::Proxy::BodyFilter::lines;
use Image::ObjectDetect;
use LWP::Simple;

our $cascade = "cascade_oppai.xml";
our $detector = Image::ObjectDetect->new($cascade);
our $alt = get('http://media.tumblr.com/MEM3qlmGxbwrympfg4uJRRKA_400.jpg');

my $proxy = HTTP::Proxy->new(port => 8088);
$proxy->push_filter(
    response => HTTP::Proxy::BodyFilter::lines->new("EOF"),
    response => Oppaifilter->new,
    mime     => 'image/jpeg'
    );
$proxy->start;

{
    package Oppaifilter;
    use File::Temp qw(tempfile);
    use base qw(HTTP::Proxy::BodyFilter);
    
    sub filter{
	my ($self, $dataref, $message, $protocol, $buffer) = @_;
	return unless defined($$dataref) && $$dataref ne '';

	eval {
	    my ($fh, $filename) = tempfile();
	    print $fh $$dataref;
	    close($fh);
	    
	    my @oppais = $detector->detect($filename);
	    if(@oppais){
		$$dataref = $alt;
	    }
	};
	if($@){
	    warn $@;
	}
    }
}   

</pre>

HTTP::Proxy使ってfilterで検出されたら適当な画像に置換です。'transfer-encoding' => 'chunked'にドはまりしました。HTTPぜんぜんわかってない。クライアント側で動作させるのは'おっぱいみれません＞＜'で楽しいけど、false positive多くてちょっとギャグに近い感じ。年齢認証のない画像投稿サービスとかで一次フィルタリングさせる用途などには有用ではないでしょうか。
おっぱいみれなくなるのはヤですが、こういう学習データとか公開しちゃうのはすごく有意義だと思います。yusukebe++


参考:
<a href="http://yusukebe.com/archives/08/07/25/083750.html">Oppai-Detect 2 @ CodereposCon#1Comments</a>
<a href="http://www.naney.org/diki/dk/HTTP::Proxy.html">nDiki: HTTP::Proxy - Twitter ベイジアンフィルタプロキシ (2007-12-29)</a>
<a href="http://blog.nomadscafe.jp/archives/000076.html">HTTP::Proxyの使い方 : blog.nomadscafe.jp</a>
]]>
   </content>
</entry>
<entry>
   <title>あのユーザを1クリックではてブから消せるRemoveHatebuUser</title>
   <link rel="alternate" type="text/html" href="http://polog.org/archives/2008/06/07035232.php" />
   <id>tag:polog.org,2008://1.1679</id>
   
   <published>2008-06-06T18:52:32Z</published>
   <updated>2008-06-07T18:10:01Z</updated>
   
   <summary>(20080608 01:50追記) プライベートの設定になっているアカウントで...</summary>
   <author>
      <name></name>
      
   </author>
   
   <category term="50" label="greasemonkey" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="ja" xml:base="http://polog.org/">
      <![CDATA[(20080608 01:50追記)
<span style="color:red"><a href="http://anond.hatelabo.jp/20080608012821">プライベートの設定になっているアカウントでこのスクリプトを使用すると、勝手にパブリック設定になってしまうと言う不具合が報告されました。</a>
大変申し訳ありませんが、既にインストール済みの方は自分のアカウントの設定をご確認の上、使用を中止してください。</span>

(20080608 02:08追記)
こちらで再度詳細に確認したところ、このスクリプトを使用すると拒否ユーザ以外の設定が全てリセットされてしまうようです。
テスト不足で多大なご迷惑をおかけしました。誠に申し訳ありません。
--

<img src="http://polog.org/files/remove_hb_user.png">

へんなはてブユーザは設定で非表示にすればいいとおもうよというつぶやきに対し、"<a href="http://tomisima.tumblr.com/post/37293565/id">コメント一覧ページで１クリックでこれを設定できるようにすりゃ、いろいろな問題が解決しそうだな。</a>"と発言してる人がいたので、書いてみた。

<del>RemoveHatebuUser</del>
]]>
      <![CDATA[<pre class="prettyprint">
// ==UserScript==
// @name           RemoveHatebuUser
// @namespace      http://polog.org
// @description    remove hatebu user on each individual entry page
// @include        http://b.hatena.ne.jp/entry/*
// ==/UserScript==

var w = unsafeWindow;

// $X() coded by cho45
var $X = function (exp, context) {
    if (!context) context = document;
    var resolver = function (prefix) {
        var o = document.createNSResolver(context)(prefix);
        return o ? o : (document.contentType == "text/html") ? "" : "http://www.w3.org/1999/xhtml";
    }
    var exp = document.createExpression(exp, resolver);

    var result = exp.evaluate(context, XPathResult.ANY_TYPE, null);
    switch (result.resultType) {
    case XPathResult.STRING_TYPE : return result.stringValue;
    case XPathResult.NUMBER_TYPE : return result.numberValue;
    case XPathResult.BOOLEAN_TYPE: return result.booleanValue;
    case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: {
        result = exp.evaluate(context, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
        var ret = [];
        for (var i = 0, len = result.snapshotLength; i < len ; i++) {
            ret.push(result.snapshotItem(i));
        }
        return ret;
    }
    }
    return null;
}


var user_name = w.Hatena.id;
var rkm = w.Hatena.rkm;
var config_url = 'http://b.hatena.ne.jp/' + user_name + '/config';
var ignore_users = '';
function init(){
    user_name = $X('//a[@class="username"]/text()')[0];
    GM_xmlhttpRequest({
        method : "GET",
        url : config_url,
        onload : function(res) {
            ignore_users = res.responseText.match(/<input value="(.*?)" name="ignore_users" type="text" size="30">/)[1];
            links_init();
        }
    });
}

function links_init(){
    $X('id("bookmarked_user")/li').forEach(append_remove_link);
}


function append_remove_link(e){
    var id = e.id.replace('bookmark-user-', '');
    var link = document.createElement('a');
    link.innerHTML = '[このユーザを非表示]';
    link.href = 'javascript:void(0);';
    link.rel = id; // いいのかなこれ
    link.addEventListener('click', remove_him, id);
    e.appendChild(link);
}

function remove_him(e){
    ignore_users += '|' + this.rel;
    var data = 'mode=enter&ignore_users=' + encodeURIComponent(ignore_users) + '&rkm=' + encodeURIComponent(rkm);
    var self = this;
    GM_xmlhttpRequest({
        method : "POST",
        url : config_url,
        headers : {
            'Content-type': 'application/x-www-form-urlencoded'
        },
        data: data,
        onload : function() {
            self.parentNode.style.display = 'none';
        }
    });
}

if(user_name)
    init();


</pre>

自分のブログが炎上したりしたら連打すれば良いと思う。当然ログインしてないと使えない。]]>
   </content>
</entry>
<entry>
   <title>「だるい」「疲れた」そんな人のためのSequentialGlitchMonkey</title>
   <link rel="alternate" type="text/html" href="http://polog.org/archives/2008/05/31155818.php" />
   <id>tag:polog.org,2008://1.1678</id>
   
   <published>2008-05-31T06:58:18Z</published>
   <updated>2008-05-31T07:13:50Z</updated>
   
   <summary>タイトルは釣り SequentialGlitchMonkey...</summary>
   <author>
      <name></name>
      
   </author>
   
   <category term="50" label="greasemonkey" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="4" label="javascript" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="ja" xml:base="http://polog.org/">
      <![CDATA[<a href="http://pha22.net/hotentry/title/s/SequentialGlitchMonkey/24/">タイトルは釣り</a>

<a href="http://userscripts.org/scripts/show/27567">SequentialGlitchMonkey</a>]]>
      <![CDATA[<object width="425" height="350"> <param name="movie" value="http://www.youtube.com/v/OW0Euo9M4Gw"> </param> <embed src="http://www.youtube.com/v/OW0Euo9M4Gw" type="application/x-shockwave-flash" width="425" height="350"> </embed> </object>

インスパイヤ元のフラッシュを見て、これJSで違うアプローチでできそうと思ってGlitchMonkeyを参考に書いてみた
dataスキームなmp3埋め込んだのはいいけど再生できなくてLDR - Signal引いた。結局position:fixedが必要だったんだけど、本気かね。画像とテキストでLR分けてたりして、ヘッドホンするとページによって聞こえ方が違って楽しいかも。
これもうほぼブラクラなんで注意してね。ニコニコ動画のランキングページとか開いたらMBPでも死にかけた
あと全然セキュアじゃないですたぶん


インスパイヤ元
<a href="http://www.horaciosalinas.net/">Horacio Salinas</a>
<a href="http://userscripts.org/scripts/show/9653 ">GlitchMonkey</a>
コードベース
<a href="http://userscripts.org/scripts/show/12781">LDR - Signal</a>]]>
   </content>
</entry>
<entry>
   <title>会社周辺のレストラン情報をGoogle Earth上でだら見する</title>
   <link rel="alternate" type="text/html" href="http://polog.org/archives/2008/05/03211626.php" />
   <id>tag:polog.org,2008://1.1677</id>
   
   <published>2008-05-03T12:16:26Z</published>
   <updated>2008-05-04T06:26:46Z</updated>
   
   <summary>会社が白金台に引っ越しました。外苑前と比べると人がすごく少なかったり、オフィスの...</summary>
   <author>
      <name></name>
      
   </author>
   
   <category term="5" label="development" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="25" label="life" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="36" label="ruby" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="ja" xml:base="http://polog.org/">
      会社が白金台に引っ越しました。外苑前と比べると人がすごく少なかったり、オフィスの隣には都内有数の森があったり、窓からその森が見えたり、僕がその窓際に座っていたり、座って作業していると半径10mに人が1人もいなかったり(前のオフィスは30人くらいいた)して、かなりいい感じです。
そんなカッチョいいオフィスで社会と会社と己のマニーのために働いている僕ですが、先日社長が&quot;カッチョいいディスプレイを会社のフロントに置くから、そこでなんかやってよ&quot;などとおっしゃってまして、ちょっとしたデモを作ることにしました。
      <![CDATA[
<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/Mf5YKWhesaM&hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/Mf5YKWhesaM&hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>


何を書いたかというと、<a href="http://tabelog.com/">食べログ</a>の駅名検索で取得できるレストランをランダムでGoogle Earth上に表示するRuby scriptです。Windowsだと<a href="http://earth.google.com/comapi/">COM API</a>とか言うのがあっていろいろやんちゃできるみたいなんですが、うちの社長は最近Macにこってるので無理です。apple script経由でGoogle Earth.appに動的にkmlをロードさせる感じで書きます。

earth.scpt:
<pre class="prettyprint">
# osascript ./earth.scpt 'Macintosh HD:Users:po:Desktop:doc.kml'
on run argv
	set kml_path to item 1 of argv
	tell application "/Applications/Google Earth.app"
		#tell application "/Applications/Safari.app"
		activate
		open file kml_path
	end tell
end run
</pre>

で、rubyではtabelog apiを駅名で叩いて取得した情報をkmlに変換し、10秒ごとにランダムピックアップ後保存してearth.scptを叩いています
<pre class="prettyprint">
#!/usr/bin/ruby -Ku
require 'open-uri'
require 'cgi'
require 'rexml/document'
require 'rubygems'
require 'active_support'
require 'mechanize'


station = '白金台'
kml_path = '/Users/po/test/earth/tabelog.kml'
kml_input_path = "Macintosh HD#{kml_path.gsub(/\//, ':')}"
default_placemark_path = './placemarkDefault.yml'

# kmlのdefault値読み込み
default_placemark = YAML.load_file(default_placemark_path)


class Hash
  # kml化
  def to_kml
    self.to_xml(:root =&gt; 'Placemark').sub(/\n/, %!\n&lt;kml xmlns="http://earth.google.com/kml/2.0"&gt;\n!).sub(/&lt;\/Placemark&gt;\n/, %!&lt;/Placemark&gt;\n&lt;/kml&gt;\n!)
  end

  # うーんなんかまずそう まいっか
  def dmerge(other)
    me = self.dup
    other.each do |k, v|
      if v.is_a?(Hash)
        me[k] = me[k].dmerge(v)
      else
        me[k] = v
      end
    end
    me
  end
end


def hash_by_item(e)
  _r = {}
  trans = {
    :name =&gt; 'RestaurantName',
    :category =&gt; 'Category',
    :score =&gt; 'TotalScore',
    :latitude =&gt; 'Latitude',
    :longitude =&gt; 'Longitude',
    :url =&gt; 'TabelogUrl'
  }

  trans.each do |to, from|
    _r[to] = e.elements[from].text
  end

  r = {
    :name =&gt; _r[:name],
    :description =&gt; %|&lt;a href="#{_r[:url]}"&gt;#{_r[:name]}&lt;/a&gt; : #{_r[:category]}, (#{_r[:score]})|,
    :LookAt =&gt; {
      :latitude =&gt; _r[:latitude],
      :longitude =&gt; _r[:longitude],
    },
    :Point =&gt; {
      :coordinates =&gt; "#{_r[:longitude]},#{_r[:latitude]},20"
    }
  }
end


kmls = []
page = 1
items_per_page = 20
max_page = 1
while(page &lt;= max_page) do
  puts url = "http://api.tabelog.com/Ver1.1/RestaurantSearch/?ResultSet=large&Station=#{CGI.escape(station)}&PageNum=#{page}"
  xml = REXML::Document.new open(url).read
  max_page = (xml.elements['//NumOfResult'].text.to_f / items_per_page).ceil

  REXML::XPath.match(xml, '//Item').each do |e|
    kmls &lt;&lt; default_placemark.dmerge(hash_by_item(e)).to_kml
  end

  page += 1
  sleep 5
end

while(true) do
  File.open(kml_path, "wb"){|f| f.write kmls[rand(kmls.size)]}
  `osascript ./earth.scpt '#{kml_input_path}'`
  sleep 10
end
</pre>
ActiveSupportのHash.to_xmlがいい感じだったので使いました。あとkmlのデフォルト値を外部にymlで持ってます。
placemarkDefault.yml
<pre class="prettyprint">
--- 
:Point: 
  :extrude: "1"
  :altitudeMode: relativeToGround
  :coordinates: 0.0,0.0,0
:visibility: "1"
:name: ""
:Style: 
  :IconStyle: 
    :Icon: 
      :h: "32"
      :w: "32"
      :y: "160"
      :x: "96"
      :href: root://icons/palette-3.png
:description: ""
:LookAt: 
  :latitude: "0.0"
  :tilt: "60.0"
  :longitude: "0.0"
  :range: "300.0"

</pre>
これと取得した情報をdeep_merge?する感じ。

可視化としてはお店/料理の画像が表示されてなかったりしてかなりダメですけれど、やっときたかったのはkmlの生成とそのロードなので、ま良いかなと。あとあんまり<a href="http://earth.google.com/kml/kml_tags_21.pdf">kml仕様書</a>真面目に読んでない。]]>
   </content>
</entry>
<entry>
   <title>LDR上ではてブ数を可聴化するgreasemonkey、LDRHatebuCountListenableを書いた</title>
   <link rel="alternate" type="text/html" href="http://polog.org/archives/2008/04/13133212.php" />
   <id>tag:polog.org,2008://1.1676</id>
   
   <published>2008-04-13T04:32:12Z</published>
   <updated>2008-04-13T04:37:11Z</updated>
   
   <summary>音の高低で、スクロールされたエントリがどの程度はてブされているかがわかるgrea...</summary>
   <author>
      <name></name>
      
   </author>
   
   <category term="50" label="greasemonkey" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="4" label="javascript" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="ja" xml:base="http://polog.org/">
      <![CDATA[音の高低で、スクロールされたエントリがどの程度はてブされているかがわかるgreasemonkeyを書きました。
<a href="http://userscripts.org/scripts/show/25096" target="blank_">LDRHatebuCountListenable</a>


<object type="application/x-shockwave-flash" width="400" height="300" data="http://www.vimeo.com/moogaloop.swf?clip_id=891903&amp;server=www.vimeo.com&amp;fullscreen=1&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=">	<param name="quality" value="best" />	<param name="allowfullscreen" value="true" />	<param name="scale" value="showAll" />	<param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id=891903&amp;server=www.vimeo.com&amp;fullscreen=1&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=" /></object><br /><a href="http://www.vimeo.com/891903/l:embed_891903">LDRHatebuCountListenable</a> from <a href="http://www.vimeo.com/user429809/l:embed_891903">negipo</a> on <a href="http://vimeo.com/l:embed_891903">Vimeo</a>.
]]>
      例えばDiablo2とかやってた人は分かると思うんですが、大量の情報を扱う場合、インターフェース上聴覚情報って言うのはすごく重要なんです。8人パーティで、Lv.28ぐらいのマルチ使ってフルbetter chance of magic item装備で牛追いかけ回してるときに、秒間数十回するアイテムのドロップ音/攻撃の発動音/ヒット音に混じって、「チンッ」って言うring/amulet系の音がするとすげー勢いでほかの奴ら集まってきますもん。
RSS readerによる情報収集もD2Cのレアアイテム収集も本質的にはほとんど同じで、何らかの指標を聴覚情報で示すのは有意義なはずです。で、ちょっと作ってみました。

そんで今のところあまり実用的ではなくて。
・sとかでfeedを選択した際にすべてのエントリをまとめてはてなのXML-RPCサーバに投げてはてブ数を取得しています。エントリ各個でリクエストしない分まだマシだと思いますが、多分このgreasemonkeyをちょっと試してみようかなって人の平均フィード登録数って1000ぐらいだと思うので、ちょっとしたアタックになるかならないかぐらいのスケール感かと思います。継続的に使用したいと思う場合にはフィルターかけて特定のフィードに限定してリクエストを送る様な仕組みが必要かもしれません。特にニュースサイトとかだとfeed burner使ってたり?rss=1とか付いてたりで無意味。
・音はJSによって動的生成されたmidiです。今コード的にはCなんですがCmとかにしたい場合はCHORDの値を[0,3,7]とかにしてみてください。って感じなんですがタブ移動すると音が出なくなったり、LDRだとかなり不安定だったりしてかなり気色悪い。Fastladderだとなぜかまあまあ安定します。
て感じです。もし常用したいなーって人がいたら実装のアイデアとかヒントとかください。

このgreasemonkeyを書くにあたってbrazilさんとkusigahamaさんのコードを参考にしました。kuさんには的確なアドバイスをいただきました。ありがとうございます:D
   </content>
</entry>
<entry>
   <title>muxtapeをサンプラーパッドにする</title>
   <link rel="alternate" type="text/html" href="http://polog.org/archives/2008/04/03010016.php" />
   <id>tag:polog.org,2008://1.1675</id>
   
   <published>2008-04-02T16:00:16Z</published>
   <updated>2008-04-02T16:16:00Z</updated>
   
   <summary>shikakunさんのmuxtape見てたら思いついた。 MuxtapeSamp...</summary>
   <author>
      <name></name>
      
   </author>
   
   <category term="50" label="greasemonkey" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="ja" xml:base="http://polog.org/">
      <![CDATA[<a href="http://shikakun.muxtape.com/">shikakunさんのmuxtape</a>見てたら思いついた。
<a href="http://userscripts.org/scripts/show/24683">MuxtapeSamplerPad.user.js</a>
<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/mc_Pbgj1eWY&hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/mc_Pbgj1eWY&hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>

サンプラーパッドでいいのかな？hifanaのイメージ。
とりあえず僕にリズム感がないことだけはわかった。
5,6,7,8,t,y,u,i,g,h,j,kでそれぞれ切り替えです。]]>
      
   </content>
</entry>
<entry>
   <title>muxtape + InFullVolume</title>
   <link rel="alternate" type="text/html" href="http://polog.org/archives/2008/04/02002256.php" />
   <id>tag:polog.org,2008://1.1674</id>
   
   <published>2008-04-01T15:22:56Z</published>
   <updated>2008-04-01T15:31:46Z</updated>
   
   <summary>InFullVolume.user.jsのmuxtape siteinfoを書く...</summary>
   <author>
      <name></name>
      
   </author>
   
   <category term="50" label="greasemonkey" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="ja" xml:base="http://polog.org/">
      <![CDATA[<a href="http://polog.org/archives/2008/02/24020525.php">InFullVolume.user.js</a>のmuxtape siteinfoを書くなどした。普段magnetosphereつけっぱな人間なので、結構良い。


<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/Mi2QV58Iiw4&hl=en"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/Mi2QV58Iiw4&hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>


カオス。]]>
      
   </content>
</entry>
<entry>
   <title>muxtapeに音声botを作った</title>
   <link rel="alternate" type="text/html" href="http://polog.org/archives/2008/03/31041946.php" />
   <id>tag:polog.org,2008://1.1673</id>
   
   <published>2008-03-30T19:19:46Z</published>
   <updated>2008-03-30T19:37:10Z</updated>
   
   <summary>http://kyoujin.muxtape.com/ 全く何言ってんのかわかり...</summary>
   <author>
      <name></name>
      
   </author>
   
   <category term="5" label="development" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="19" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="ja" xml:base="http://polog.org/">
      <![CDATA[<a href="http://kyoujin.muxtape.com/">http://kyoujin.muxtape.com/</a>

全く何言ってんのかわかりませんがたまに'きほーんーてーきー'とか'そウCてーもぅUだーCta-'とか言い出して吹きます。
ソースは以下。]]>
      <![CDATA[<pre class="prettyprint">#!/usr/bin/perl

use strict;
use LWP::Simple;
use XML::RSS;
use Lingua::JA::Romanize::Japanese;
use Data::Dumper;
use Date::Simple;
use WWW::Mechanize;


sub reduce_candidate{
    my $str = shift;
    my @words = split / /, $str;
    my @_words;
    for my $word (@words){
	if($word =~ /^(.+?)\//){
	    push(@_words, $1);
	}else{
	    push(@_words, $word);
	}
    }
    return join ' ', @_words;
}

# get kyoujin speech from rss
my $xml = new XML::RSS;
my $conv = Lingua::JA::Romanize::Japanese->new();
my @results;
$xml->parse(get('http://twitter.com/statuses/user_timeline/5932892.rss'));
for my $item ( @{$xml->{'items'}}){
    my $content = $item->{'title'};
    $content =~ s/^kyoujin: //g;
    $content = $conv->chars($content);
    $content = reduce_candidate($content);
    $content =~ s/[^\w ]//g;
    push(@results, $content);
}
my $result = join '. ', @results;

# make mp3
my $path = '/Users/po/test/kyoujin-muxtape/';
my $aiff_file = $path . 'test.aiff';
my ($y, $m, $d) = Date::Simple->today->as_ymd;
my $mp3_file = $path . "$y-$m-$d.mp3";
`say -v Alex -o $aiff_file $result`;
`ffmpeg -i $aiff_file -title '$y-$m-$d' -author 'kyoujin' $mp3_file`;

# post to muxtape
my $agent = new WWW::Mechanize;
$agent->agent_alias('Windows Mozilla');
$agent->post('http://muxtape.com/login',
	     {
		 name => '',
		 pass => ''
	     }
    );
$agent->get('http://muxtape.com/upload');
$agent->submit_form(
    form_number => 1,
    fields => {
	file => $mp3_file
    }
    );

</pre>
<a href="http://twitter.com/kyoujin">@kyoujin</a>のRSSをLingua::JA::Romanize::Japaneseでローマ字にした後sayコマンドでaiff生成し、ffmpegでmp3に変換し、mechanizeでpostって感じです。このままだとマジ聞き取れないのでなんとかなんないかなー。
なんとなくuse encoding 'utf-8';とか書いてたらmechanize内のmp3 postの所で500 wide character in syswriteが出まくりました。]]>
   </content>
</entry>
<entry>
   <title>Googleには検索できない文が設定されている</title>
   <link rel="alternate" type="text/html" href="http://polog.org/archives/2008/03/09000440.php" />
   <id>tag:polog.org,2008://1.1672</id>
   
   <published>2008-03-08T15:04:40Z</published>
   <updated>2008-03-08T16:00:47Z</updated>
   
   <summary>有名な話だったらスイマセン。 はまちちゃんのついったー足あと帳を見て、何の気無し...</summary>
   <author>
      <name></name>
      
   </author>
   
   <category term="51" label="security" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="17" label="service" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="ja" xml:base="http://polog.org/">
      <![CDATA[有名な話だったらスイマセン。
はまちちゃんの<a href="http://hamachiya.com/junk/twlog/">ついったー足あと帳</a>を見て、何の気無しに


inurl:crossdomain.xml 'allow-access-from domain="*"' 


なんて検索をGoogleにかけたんだ。
そしたらこうなった。
<a href="http://polog.org/images/googledeny.png"><img src="http://polog.org/images/googledeny.png" width="430px"></a>
よく出来てるなあ。


(追記 0:21)
すみませんすみません！この件、"普通に検索できた。君のPCから実際DOSやっちゃってるんじゃ"ていう主旨のご指摘がありました。ちと調べます。
koyachiさん感謝です。


(追記2 0:53)
色々なパターンでみんなで検証したところ、youpyさんがminimumなパターンを発見してくれました。


<a href="http://twitter.com/youpy/statuses/768519501">@negipo 表示件数を100件にする + 任意のinurl を指定 + * で再現しました</a>


僕の環境だと+検索結果ページから上記の内容をリクエストする必要がありました。検索窓とかGoogle topとかだと普通に通る。
つまり例えば"inurl:polog.org *"とかを、検索結果ページから検索すると同じ現象が起きます。
Google検索におけるアスタリスクの扱いは<a href="http://www.google.co.jp/support/bin/answer.py?answer=3178">こんな感じ</a>。多分バグですね。
お騒がせしました。皆さん感謝です。]]>
      
   </content>
</entry>
<entry>
   <title>GoogleDenyHatena.user.js</title>
   <link rel="alternate" type="text/html" href="http://polog.org/archives/2008/02/29140558.php" />
   <id>tag:polog.org,2008://1.1671</id>
   
   <published>2008-02-29T05:05:58Z</published>
   <updated>2008-02-29T05:16:50Z</updated>
   
   <summary>この匿名ダイアリーを見て、そんなにはてな嫌いなら見なきゃいいのにと思い、ちょうど...</summary>
   <author>
      <name></name>
      
   </author>
   
   <category term="4" label="javascript" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="37" label="joke" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="ja" xml:base="http://polog.org/">
      <![CDATA[<a href="http://anond.hatelabo.jp/20080228225700">この匿名ダイアリー</a>を見て、そんなにはてな嫌いなら見なきゃいいのにと思い、ちょうどお昼休みだし俺はメシ食いながらはてな見てるしなのでgreasemonkey書いてみた


<a href="http://polog.org/files/googledenyhatena.user.js">GoogleDenyHatena.user.js</a>


googleで検索するとhatena.ne.jpな結果が全部見えなくなる。AutoPagerize対応
でソース見てもらうと分かると思うんだけど、denyのリストを正規表現で与えられるので、/./を渡して"そんなに世の中嫌いなら何も見なきゃいいのに"的なこともできる
<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/8Y3L4L-Sz6s"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/8Y3L4L-Sz6s" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>
もう誰か作ってるスクリプトかもだけど、意外と便利だなこれ。]]>
      
   </content>
</entry>
<entry>
   <title>どんなサイトでもミュージックビジュアライザにするInFullVolume.user.js</title>
   <link rel="alternate" type="text/html" href="http://polog.org/archives/2008/02/24020525.php" />
   <id>tag:polog.org,2008://1.1670</id>
   
   <published>2008-02-23T17:05:25Z</published>
   <updated>2008-02-24T18:02:43Z</updated>
   
   <summary>どんなサイトでもミュージックビジュアライザにしてしまうgreasemonkeyユ...</summary>
   <author>
      <name></name>
      
   </author>
   
   <category term="49" label="actionscript" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="50" label="greasemonkey" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="4" label="javascript" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="25" label="life" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="46" label="release" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="ja" xml:base="http://polog.org/">
      <![CDATA[どんなサイトでもミュージックビジュアライザにしてしまうgreasemonkeyユーザスクリプト、<a href="http://polog.org/lab/in-full-volume/infullvolume.user.js">InFullVolume.user.js</a>を作りました。


<a href="http://polog.org/lab/in-full-volume/">デモページ</a>


<object width="425" height="350"> <param name="movie" value="http://www.youtube.com/v/6Vhxy6KT9WY"> </param> <embed src="http://www.youtube.com/v/6Vhxy6KT9WY" type="application/x-shockwave-flash" width="425" height="350"> </embed> </object>
]]>
      <![CDATA[どんなスクリプトかは↑見ていただければわかるかと思うんですが、要するに超大音量で音楽を流しっぱなしにするか、延々と叫び続けない限り正常にWEBが閲覧できなくなるユーザスクリプトです。<a href="http://jottit.com/nspjq/">siteinfo</a>を用いているので、誰でもxpathやuriパターンの編集ができます。一応ソースからもsiteinfoを編集できるので(デモページのsiteinfoがハードコードしてありますので参考に。)、チェックしてから上げるようにしてください。またSiteInfoクラスはyoupyさんの<a href="http://userscripts.org/scripts/show/22404">Twitter Text Converter</a>がベースになってます。あと現在siteinfoに登録されているxpathの半分くらいはldrizeのsiteinfoのコピペです。最初ldrizeのsiteinfoを読みにいこうと思ったんですが、tr要素に対してついてたり目的に沿っていなかったりしたので新設しました。jottitすげえ便利。


技術的にはembedしたswfでマイクの音量を拾って、FSCommandでunsafeWindow.mic_DoFSCommandに渡ったものを受け取るようにしています。ペーパープロトタイプの時点ではスペクトラムのようなものが取れるかなと思ったのですが、残念ながら音量だけしか取れなかったのでこちょこちょしてます。引数をそのままevalな処理があるので正規表現でチェックしてますが、その他の点も含めてセキュリティ的に問題がありそうだったらご指摘お願いします。また、<b>取得された音量は対象ページ側でも参照できるようにしてあるので、ご利用の際にはマイク音量をいろんなページにまき散らしていることをご了承ください。</b>デモページではそれを利用してgoo地図のズームアップ/ダウンをやっています。あと当然ですがswfで取得している音声情報はどこにも飛ばしてないです。
as3のソースはこんな感じ。getActivityLevelはjs->asの値取得の際にドメイン指定がホワイトリスト方式なのを知らなかった頃の名残です。
<pre class="prettyprint">package {
   import flash.display.*;
   import flash.events.*;
   import flash.media.*;
   import flash.system.*;
   import flash.text.*;
   import flash.utils.Timer;
   import flash.geom.*;
   import flash.external.ExternalInterface;

   public class mic extends Sprite {
       public var myMic:Microphone;
       public var timer:Timer;
       function mic() {
           ExternalInterface.addCallback("callFlash", getActivityLevel);

           myMic = Microphone.getMicrophone();
           if (myMic != null) {
               myMic.setLoopBack(true);
               myMic.setUseEchoSuppression(true);
               myMic.setSilenceLevel(100,1000);

               timer = new Timer(50, 0);
               timer.addEventListener(TimerEvent.TIMER, onTick);
               timer.start();
           }
       }

       public function getActivityLevel():Number {
           return myMic.activityLevel;
       }

       public function onTick(event:TimerEvent):void {
           fscommand("setActivityLevel", "" + myMic.activityLevel);
       }
   }
}

</pre>


以下余談。
<a href="http://polog.org/archives/2008/01/06180347.php">誤字ェネレータのグリモン</a>とかもそうなんですが、僕はどうやらディスコミュニケーションソフトウェア(造語)が好きみたいです。<a href="http://twitter.com/kyoujin">きょうじん</a>だっておかしいですよ。人口無脳のくせに返信しないし。ワードサラダだし。もちろんここで徹底的に世の中を不便にする何かを作ったりすると、googleのえらいひとが怒ったり、もっと悪ければ僕の周囲の検索とかなんだとかの生活インフラが一切壊れてしまったりするかもしれないので、あくまで整然と並ぶインデックス群に対するちょっとしたゆらぎのようなソフトウェアをいっぱい作っていきたいなあと思います。でもクビにはなりたくないなー。


(追記)
環境によってはブラウザのキャッシュサイズをゼロにしないとダメかもです。

(追記2)
戀塚さんにブックマークされちゃったのでニコニコにも上げました


<iframe width="312" height="176" src="http://www.nicovideo.jp/thumb/sm2429018" scrolling="no" style="border:solid 1px #CCC;" frameborder="0"><a href="http://www.nicovideo.jp/watch/sm2429018">【ニコニコ動画】どんなサイトでもミュージックビジュアライザにするInFullVolume.user.js</a></iframe>


画質ひどいw　コツがあるのかなあ]]>
   </content>
</entry>
<entry>
   <title>人工無能オフというのに行ってきた</title>
   <link rel="alternate" type="text/html" href="http://polog.org/archives/2008/02/17123702.php" />
   <id>tag:polog.org,2008://1.1669</id>
   
   <published>2008-02-17T03:37:02Z</published>
   <updated>2008-02-17T03:41:34Z</updated>
   
   <summary>人工無能オフというのに行ってきた  人工無能と言うのは要するにchat botで...</summary>
   <author>
      <name></name>
      
   </author>
   
   <category term="5" label="development" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="43" label="event" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="ja" xml:base="http://polog.org/">
      人工無能オフというのに行ってきた 
人工無能と言うのは要するにchat botで、チャットソフトやマイクロブログ上で動作して勝手に喋ったり返信したりするもの 
僕が作った奴 
http://twitter.com/kyoujin 
http://twitter.com/yumeno 
人工無能オフだと言うから前日に1時間で作った↓ 
http://twitter.com/DaDaDaJunji 
他参加者 
http://twitter.com/ha_ma 
http://twitter.com/dabesa 
http://twitter.com/medachon 
http://twitter.com/meitanteikun 
http://twitter.com/koc 
予想はしてたけど自己紹介時に&quot;どーも、きょうじんです&quot;&quot;あ、ha_maなのよ&quot;みたいなかなりカオスな感じ。嘘です。普通に名刺交換しました。 

      僕も含めみんなかなりおかしかなひとたちだったけど、話してる内容は意外とマトモで、要は人工知能的アプローチがつまってる袋小路的な所から、いかに哲学的な部分を抜いて、キャッチーかつわたくしごのみな人工無能に落とすか、と言うような主旨だったような。 
僕が話した内容は、単純マルコフとかウンコだからちゃんと文法解析いれろとか、フィルタリング無しで応答するためにはtwitter上で行われてるつぶやきではなくやりとりの方を解析対象にすべきとか、アルゴリズムのアレな所はデータ量で補おうとか、ぬいぐるみにスピーカー入れて読み上げさせろとか、そんなことばっかり。 
ha_maのソース見せてもらったり(他の参加者が誰もpython読めなくて笑った)暗号屋さんの話を聞かせてもらったり、めだちょん人形触ったりも楽しかったけど、一番アがったのはファミレスに隠しマイクつけて、録音した内容をgoogleに解析させればチャットボットになるんじゃね?ってアイデア。google入社してえええ。 
と言う訳で楽しかった。また行きたい。
   </content>
</entry>
<entry>
   <title>javascriptでミュージックビジュライザ作ってる</title>
   <link rel="alternate" type="text/html" href="http://polog.org/archives/2008/02/14005949.php" />
   <id>tag:polog.org,2008://1.1668</id>
   
   <published>2008-02-13T15:59:49Z</published>
   <updated>2008-02-13T16:08:11Z</updated>
   
   <summary>今んとここんな感じ。 ・actionscriptでマイクのactivityLev...</summary>
   <author>
      <name></name>
      
   </author>
   
   <category term="49" label="actionscript" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="4" label="javascript" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="ja" xml:base="http://polog.org/">
      <![CDATA[今んとここんな感じ。
<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/WiZ1QQxyw0U&rel=1"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/WiZ1QQxyw0U&rel=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>

・actionscriptでマイクのactivityLevelを返す関数書く
・javascriptで取得してEffect.Scaleでごちゃごちゃする

動作重過ぎる。こんなシンプルなdiv10個ごにょごにょするだけでコマ落ちしまくった上にFireFox落ちそうになった。どうしようこれ絶対無理。
なんでjavascriptなのかはまた今度。]]>
      
   </content>
</entry>
<entry>
   <title>ライフゲームでグリッチ</title>
   <link rel="alternate" type="text/html" href="http://polog.org/archives/2008/01/30032718.php" />
   <id>tag:polog.org,2008://1.1667</id>
   
   <published>2008-01-29T18:27:18Z</published>
   <updated>2008-01-30T02:11:45Z</updated>
   
   <summary>昨日の続き。 なんで昨日いきなりライフゲームなんぞ実装したかと言うと、なんかgl...</summary>
   <author>
      <name></name>
      
   </author>
   
   <category term="5" label="development" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="48" label="proce55ing" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="ja" xml:base="http://polog.org/">
      昨日の続き。
なんで昨日いきなりライフゲームなんぞ実装したかと言うと、なんかglitchに使えそうだったからです。寝る前にふと思いついちゃいました。てなわけで今日ぐっちゃぐちゃになりましたけど、割と構造化を意識した感じのコードにしてたんです。コードグリッチ！
以下詳細。
      <![CDATA[<img src="http://polog.org/images/lifegame_glitching.png">
<object width="425" height="350"> <param name="movie" value="http://www.youtube.com/v/r9e5B-7s4tg"> </param> <embed src="http://www.youtube.com/v/r9e5B-7s4tg" type="application/x-shockwave-flash" width="425" height="350"> </embed> </object>
やべー超楽しい(俺が)。


機能・フロー：
1) <a href="http://mao.s151.xrea.com/tumbrowser/">たんぶらうざ</a>のフィードを取得し、画像を全件取得。
2) ライフゲームを回す
3) ライフゲーム下、各ノードが特定の条件下で周囲のノードが持つピクセルを自分にコピーするようにする。＞自分が生きている場合、周囲の生きているノードから適当にコピー
4) クリックで画像変更


ダウンロード：
<a href="http://polog.org/files/processing/lifegame_glitching/lifegame_glitching.app.zip">lifegame_glitching.app.zip(mac)</a>
<a href="http://polog.org/files/processing/lifegame_glitching/lifegame_glitching.exe.zip">lifegame_glitching.exe.zip(win)</a>未動作確認
# ビデオ見てもらうとわかるけどめっちゃ重いソフトウェアなので、しばらく待って変化が無ければクリックしてみたり終了してみたり。ネットワークにも影響されます。


ソース：
<pre class="prettyprint">import processing.xml.*;
import java.util.regex.*;

String feed_url = "http://mao.s151.xrea.com/tumbrowser/index.xml";
int width = 400;
int height = 600;
int px_size = 1;

XMLElement feed;
String[] image_urls;
int image_idx = 0;
int image_idx_max = 0;
PImage image_src;

Bug[] buf_bugs;
Bug[][] bugs;

void setup()
{
  size(width, height);

  init_image_url();
  init_image_src();

  fill(255);
  bugs = new Bug[width / px_size][height / px_size];
  buf_bugs = new Bug[8]; 

  for(int x = 0; x < width / px_size; x++){
    for(int y = 0; y < height / px_size; y++){
      bugs[x][y] = new Bug(x * px_size, y * px_size);
    }
  }
  frameRate(2);
}

void init_image_src(){
  println(image_idx);
  image_src = loadImage(image_urls[image_idx]);
  image_src.loadPixels();
  if(image_idx == image_idx_max){
    image_idx = 0;
  }
  else{
    image_idx++;
  }
  float w = width;
  float h = height;
  float iw = image_src.width;
  float ih = image_src.height;
  float scale;
  int x1, y1, x2, y2;
  if(w / iw > h / ih){
    scale = w / iw;
    float rest = scale * ih - h;
    x1 = 0;
    x2 = width;
    y1 = floor(-rest / 2);
    y2 = floor(rest / 2) + height;
  }
  else{
    scale = h / ih;
    float rest = scale * iw - w;
    x1 = floor(-rest / 2);
    x2 = floor(rest / 2) + width;
    y1 = 0;
    y2 = height;
  }
  imageMode(CORNERS);
  image(image_src, x1, y1, x2, y2);
}

void init_image_url(){
  XMLElement feed = new XMLElement(this, feed_url);
  XMLElement[] contents = feed.getChildren("channel/item/content:encoded");
  image_urls = new String[contents.length];
  Pattern pattern_url = Pattern.compile("http://data.tumblr.com/[^¥.]+...."); // cannot escape quotes

  image_idx_max = contents.length - 1;

  for(int i = 0 ; i < contents.length ; i++){
    String content = contents[i].getContent();
    Matcher matcher_url = pattern_url.matcher(content);
    if(matcher_url.find()){
      image_urls[i] = matcher_url.group(0);
    }
    println(image_urls[i]);
  }
}

void draw()
{
  int[] idx_buf;
  int x_m, x_p, y_m, y_p;
  for(int x = 0; x < width / px_size; x++){
    for(int y = 0; y < height / px_size; y++){
      x_m = v(x - 1, width / px_size); 
      x_p = v(x + 1, width / px_size); 
      y_m = v(y - 1, height / px_size); 
      y_p = v(y + 1, height / px_size);
      buf_bugs[0] = bugs[x_m][y_m];
      buf_bugs[1] = bugs[x][y_m];
      buf_bugs[2] = bugs[x_p][y_m];
      buf_bugs[3] = bugs[x_m][y];
      buf_bugs[4] = bugs[x_p][y];
      buf_bugs[5] = bugs[x_m][y_p];
      buf_bugs[6] = bugs[x][y_p];
      buf_bugs[7] = bugs[x_p][y_p];

      bugs[x][y].update(buf_bugs);
    }
  }
  for(int x = 0; x < width / px_size; x++){
    for(int y = 0; y < height / px_size; y++){
      bugs[x][y].draw();
    }
  }
}

void mouseReleased(){
  background(0);
  init_image_src();
}

int v(int i, int max){
  if(i >= 0){
    if(i < max){
      return i;
    }
    else{
      return 0;
    }
  }
  else{
    return max - 1; 
  }
}

class Bug {
  public int idx, idy;
  int live_flag, buf_live_flag;
  int bug_color = 0;
  Bug living_bug = this;
  Bug(int x, int y){
    idx = x;
    idy = y;
    buf_live_flag = live_flag = (random(0, 3) < 1) ? 1 : 0;
  }
  public int living(){
    return buf_live_flag;
  }
  public void update(Bug[] bugs){
    int count_living = 0;
    for(int i = 0 ; i < 8 ; i++){
      if(bugs[i].living() == 1){
        count_living++;
        living_bug = bugs[i];
      }
    }
    if(live_flag == 1 && (count_living < 2 || count_living > 3)){
      live_flag = 0;  
    }
    else if(live_flag == 0 && count_living == 3){
      live_flag = 1;
    }
  }
  public void draw(){
    if(live_flag == 1){
      int cidx = living_bug.idx;
      int cidy = living_bug.idy;
      imageMode(CORNER);
      copy(cidx, cidy, px_size, px_size, idx, idy, px_size, px_size);
    }
    buf_live_flag = live_flag;    
  }
}
</pre>]]>
   </content>
</entry>

</feed>
