木曜日, 1月 21, 2010

ClutterのチュートリアルをPyClutterに翻訳 その2

ClutterのチュートリアルをPyClutterに翻訳するその2

Scoreを使って複数のタイムラインを流すところの前半まで。後半のところはPyClutterの問題なのか、うまく出来ないので、原因を調査中。
追記:原因解明。何が問題だったのかは後で書く。

複数タイムラインの次は画像の読み込みのチュートリアルだけど、画像を用意するのが面倒なのでやらない。

大きさの変更やオブジェクトの選択


まわして、かくだい
#!/usr/bin/python
# -*- coding: utf-8 -*-

import clutter
import mathhacks

global rotation
global scale
rotation = 0
scale = 0


def on_timeline_new_frame(timeline, frame_num, rect_list):
global rotation
global scale

rotation += 0.3
rect_list[0].set_rotation(clutter.Z_AXIS, rotation * 5, 0, 0, 0)
rect_list[1].set_rotation(clutter.Z_AXIS, rotation * 4, 0, 0, 0)
rect_list[2].set_rotation(clutter.Z_AXIS, rotation * 3, 0, 0, 0)
rect_list[3].set_rotation(clutter.Z_AXIS, rotation * 2, 0, 0, 0)
rect_list[4].set_rotation(clutter.Z_AXIS, rotation * 1, 0, 0, 0)
rect_list[5].set_rotation(clutter.Z_AXIS, rotation * 0.5, 0, 0, 0)

scale += 0.01
if scale > 1.0:
scale = 0

scale_amount = mathhacks.smooth_step2(1.0, 2.0, scale)
for rect in rect_list:
rect.set_scale(scale_amount, scale_amount)


def quit(actor, *args):
clutter.main_quit()


def create_rect(color):
rect = clutter.Rectangle(color)
rect.set_size(256, 128)
rect.set_position(128, 128)
rect.set_anchor_point(128, 64)

return rect


clutter.init()
stage_color = clutter.Color(0, 0, 0, 255)
stage = clutter.Stage()
stage.set_size(512, 512)
stage.set_color(stage_color)

red = clutter.Color(255, 0, 0, 128)
green = clutter.Color(0, 255, 0, 128)
blue = clutter.Color(0, 0, 255, 128)
yellow = clutter.Color(255, 255, 0, 128)
cyan = clutter.Color(0, 255, 255, 128)
purple = clutter.Color(255, 0, 255, 128)

rect_list = []
rect_list.append(create_rect(red))
rect_list.append(create_rect(green))
rect_list.append(create_rect(blue))
rect_list.append(create_rect(yellow))
rect_list.append(create_rect(cyan))
rect_list.append(create_rect(purple))

stage.connect('hide', quit)
stage.show()

for r in rect_list:
stage.add(r)

timeline = clutter.Timeline(60)
timeline.connect('new-frame', on_timeline_new_frame, rect_list)
timeline.set_loop(True)
timeline.start()

clutter.main()


まわして、かくだいして、おしたらきえる
#!/usr/bin/python
# -*- coding: utf-8 -*-

import clutter
import mathhacks

global rotation
global scale
rotation = 0
scale = 0


def on_timeline_rotation_new_frame(timeline, frame_num, rect_list):
global rotation

rotation += 0.3
rect_list[0].set_rotation(clutter.Z_AXIS, rotation * 5, 0, 0, 0)
rect_list[1].set_rotation(clutter.Z_AXIS, rotation * 4, 0, 0, 0)
rect_list[2].set_rotation(clutter.Z_AXIS, rotation * 3, 0, 0, 0)
rect_list[3].set_rotation(clutter.Z_AXIS, rotation * 2, 0, 0, 0)
rect_list[4].set_rotation(clutter.Z_AXIS, rotation * 1, 0, 0, 0)
rect_list[5].set_rotation(clutter.Z_AXIS, rotation * 0.5, 0, 0, 0)

def on_timeline_scale_new_frame(timeline, frame_num, rect_list):
global scale
scale += 0.01
if scale > 1.0:
scale = 0

scale_amount = mathhacks.smooth_step2(1.0, 2.0, scale)
for rect in rect_list:
rect.set_scale(scale_amount, scale_amount)

def on_stage_button_press(stage, event, *arg):
x = 0
y = 0
x, y = event.x, event.y
clicked = stage.get_actor_at_pos(clutter.PICK_ALL, x, y)
if clicked == stage:
return
clicked.hide()

def quit(actor, *args):
clutter.main_quit()


def create_rect(color):
rect = clutter.Rectangle(color)
rect.set_size(256, 128)
rect.set_position(128, 128)
rect.set_anchor_point(128, 64)

return rect


clutter.init()
stage_color = clutter.Color(0, 0, 0, 255)
stage = clutter.Stage()
stage.set_size(512, 512)
stage.set_color(stage_color)

red = clutter.Color(255, 0, 0, 128)
green = clutter.Color(0, 255, 0, 128)
blue = clutter.Color(0, 0, 255, 128)
yellow = clutter.Color(255, 255, 0, 128)
cyan = clutter.Color(0, 255, 255, 128)
purple = clutter.Color(255, 0, 255, 128)

rect_list = []
rect_list.append(create_rect(red))
rect_list.append(create_rect(green))
rect_list.append(create_rect(blue))
rect_list.append(create_rect(yellow))
rect_list.append(create_rect(cyan))
rect_list.append(create_rect(purple))

stage.connect("button-press-event", on_stage_button_press)
stage.connect('hide', quit)
stage.show()

for r in rect_list:
stage.add(r)

timeline = clutter.Timeline(60)
timeline.connect('new-frame', on_timeline_new_frame, rect_list)
timeline.set_loop(True)
timeline.start()

clutter.main()

スコアを記録する


#!/usr/bin/python
# -*- coding: utf-8 -*-

import clutter
import mathhacks

global rotation
global scale
rotation = 0
scale = 0


def on_timeline_rotation_new_frame(timeline, frame_num, rect_list):
global rotation

rotation += 0.3
rect_list[0].set_rotation(clutter.Z_AXIS, rotation * 5, 0, 0, 0)
rect_list[1].set_rotation(clutter.Z_AXIS, rotation * 4, 0, 0, 0)
rect_list[2].set_rotation(clutter.Z_AXIS, rotation * 3, 0, 0, 0)
rect_list[3].set_rotation(clutter.Z_AXIS, rotation * 2, 0, 0, 0)
rect_list[4].set_rotation(clutter.Z_AXIS, rotation * 1, 0, 0, 0)
rect_list[5].set_rotation(clutter.Z_AXIS, rotation * 0.5, 0, 0, 0)


def on_timeline_scale_new_frame(timeline, frame_num, rect_list):
global scale
scale += 0.01
if scale > 1.0:
scale = 0

scale_amount = mathhacks.smooth_step2(1.0, 2.0, scale)
for rect in rect_list:
rect.set_scale(scale_amount, scale_amount)


def on_stage_button_press(stage, event, *arg):
x = 0
y = 0
(x, y) = (event.x, event.y)
clicked = stage.get_actor_at_pos(clutter.PICK_ALL, x, y)
if clicked == stage:
return
clicked.hide()


def quit(actor, *args):
clutter.main_quit()


def create_rect(color):
rect = clutter.Rectangle(color)
rect.set_size(256, 128)
rect.set_position(128, 128)
rect.set_anchor_point(128, 64)

return rect


clutter.init()
stage_color = clutter.Color(0, 0, 0, 255)
stage = clutter.Stage()
stage.set_size(512, 512)
stage.set_color(stage_color)

red = clutter.Color(255, 0, 0, 128)
green = clutter.Color(0, 255, 0, 128)
blue = clutter.Color(0, 0, 255, 128)
yellow = clutter.Color(255, 255, 0, 128)
cyan = clutter.Color(0, 255, 255, 128)
purple = clutter.Color(255, 0, 255, 128)

rect_list = []
rect_list.append(create_rect(red))
rect_list.append(create_rect(green))
rect_list.append(create_rect(blue))
rect_list.append(create_rect(yellow))
rect_list.append(create_rect(cyan))
rect_list.append(create_rect(purple))

stage.connect('button-press-event', on_stage_button_press)
stage.connect('hide', quit)

for r in rect_list:
stage.add(r)

score = clutter.Score()
score.set_loop(True)

timeline_rotation = clutter.Timeline(500)
timeline_rotation.connect('new-frame', on_timeline_rotation_new_frame,
rect_list)
score.append(timeline_rotation)

timeline_scale = clutter.Timeline(500)
timeline_scale.connect('new-frame', on_timeline_scale_new_frame,
rect_list)
score.append(timeline_scale)
score.start()

stage.show()
clutter.main()


2つのTimelineを接続する


pyclutterのREADMEを読むと書いてあるが、Score#appendの引数の順番は、CのAPIと違っている。昨日はこれに気づかなかった。ちゃんとREADMEは読めという話ですね。
これはよりPythonicな書き方をするためらしい。こういうのは今後もあると思われ。
#!/usr/bin/python
# -*- coding: utf-8 -*-

import clutter
import mathhacks

# 回転情報
global rotation
global scale
rotation = 0
scale = 0


def on_timeline_rotation_new_frame(timeline, frame_num, rect_list):
global rotation

rotation += 0.3
rect_list[0].set_rotation(clutter.Z_AXIS, rotation * 5, 0, 0, 0)
rect_list[1].set_rotation(clutter.Z_AXIS, rotation * 4, 0, 0, 0)
rect_list[2].set_rotation(clutter.Z_AXIS, rotation * 3, 0, 0, 0)
rect_list[3].set_rotation(clutter.Z_AXIS, rotation * 2, 0, 0, 0)
rect_list[4].set_rotation(clutter.Z_AXIS, rotation * 1, 0, 0, 0)
rect_list[5].set_rotation(clutter.Z_AXIS, rotation * 0.5, 0, 0, 0)


def on_timeline_scale_new_frame(timeline, frame_num, rect_list):
global scale
scale += 0.01
if scale > 1.0:
scale = 0

scale_amount = mathhacks.smooth_step2(1.0, 2.0, scale)
for rect in rect_list:
rect.set_scale(scale_amount, scale_amount)


def on_stage_button_press(stage, event, *arg):
x = 0
y = 0
(x, y) = (event.x, event.y)
clicked = stage.get_actor_at_pos(clutter.PICK_ALL, x, y)
if clicked == stage:
return
clicked.hide()


def quit(actor, *args):
clutter.main_quit()


def create_rect(color):
rect = clutter.Rectangle(color)
rect.set_size(256, 128)
rect.set_position(128, 128)
rect.set_anchor_point(128, 64)

return rect


clutter.init()
stage_color = clutter.Color(0, 0, 0, 255)
stage = clutter.Stage()
stage.set_size(512, 512)
stage.set_color(stage_color)

red = clutter.Color(255, 0, 0, 128)
green = clutter.Color(0, 255, 0, 128)
blue = clutter.Color(0, 0, 255, 128)
yellow = clutter.Color(255, 255, 0, 128)
cyan = clutter.Color(0, 255, 255, 128)
purple = clutter.Color(255, 0, 255, 128)

rect_list = []
rect_list.append(create_rect(red))
rect_list.append(create_rect(green))
rect_list.append(create_rect(blue))
rect_list.append(create_rect(yellow))
rect_list.append(create_rect(cyan))
rect_list.append(create_rect(purple))

stage.connect('button-press-event', on_stage_button_press)
stage.connect('hide', quit)

for r in rect_list:
stage.add(r)

score = clutter.Score()
score.set_loop(True)

timeline_rotation = clutter.Timeline(500)
timeline_rotation.connect('new-frame', on_timeline_rotation_new_frame,
rect_list)
score.append(timeline_rotation)

timeline_scale = clutter.Timeline(500)
timeline_scale.connect('new-frame', on_timeline_scale_new_frame,
rect_list)
score.append(timeline_scale, timeline_rotation)
score.start()

stage.show()
clutter.main()

火曜日, 1月 19, 2010

ClutterのチュートリアルをPyClutterに翻訳 その1

Mikeforce::HomePageのClutterチュートリアルの和訳をPyClutterでやってみる。

覚えておいてほしいこととして、あくまでのこの記事は Clutter のドキュメントで今現在不足している箇所を補うための「臨時措置」みたいなものだということです。私たちは、もっと広い視野でみた Python を中心とする Clutter のチュートリアルを作成中ですが、それを完成するには2,3ヶ月必要であるとみています。その間は、ここで紹介するチュートリアルで我慢していただき、 Clutter を使ったプログラミングを楽しんで欲しいと考えています。

と書いてあるので、そのうち本気措置が取られる事を期待しつつ、とりあえず前半戦。

初めの一歩


黒い枠が出来るだけ。
import clutter

clutter.init()
color = clutter.Color(0, 0, 0, 255)
stage = clutter.Stage()
stage.set_size(512, 512)
stage.set_color(color)
stage.show()

clutter.main()


四角を追加
import clutter

clutter.init()
stage_color = clutter.Color(0, 0, 0, 255)
stage = clutter.Stage()
stage.set_size(512, 512)
stage.set_color(stage_color)

actor_color = clutter.Color(0, 255, 0, 128)
rect = clutter.Rectangle(actor_color)
rect.set_size(100, 100)
rect.set_position(100, 100)

stage.add(rect)
stage.show()
clutter.main()


必要に応じて長方形を描画する


元ネタでは、長方形の描画とstageへの登録を同じ関数内でやっているのだけど、個人的にそれが嫌なので、四角を作るだけにした。
あと、PyClutterの場合、メインのウィンドウを閉じてもプロセスが生き続けてしまうので、それを避けるために、stageのhideシグナルに終了処理をくっつけた。
import clutter

"""ウィンドウを閉じたときに終了するためのclosure"""
def quit(actor, *args):
clutter.main_quit()

"""関数内でaddするのが嫌だったのでrectを作るだけ"
def create_rect(color):
rect = clutter.Rectangle(color)
rect.set_size(256, 128)
rect.set_position(128, 128)

return rect


stage_color = clutter.Color(0, 0, 0, 255)
stage = clutter.Stage()
stage.set_size(512, 512)
stage.set_color(stage_color)

actor_color = clutter.Color(0, 255, 0, 128)
rect = create_rect(actor_color)
stage.add(rect)
# 終了関数を設定
stage.connect('hide', quit)
stage.show()
clutter.main()


アニメーション一歩手前


#!/usr/bin/python
# -*- coding: utf-8 -*-

import clutter


def quit(actor, *args):
clutter.main_quit()


def create_rect(color):
rect = clutter.Rectangle(color)
rect.set_size(256, 128)
rect.set_position(128, 128)

return rect


clutter.init()
stage_color = clutter.Color(0, 0, 0, 255)
stage = clutter.Stage()
stage.set_size(512, 512)
stage.set_color(stage_color)

red = clutter.Color(255, 0, 0, 128)
green = clutter.Color(0, 255, 0, 128)
blue = clutter.Color(0, 0, 255, 128)
yellow = clutter.Color(255, 255, 0, 128)
cyan = clutter.Color(0, 255, 255, 128)
purple = clutter.Color(255, 0, 255, 128)

rect1 = create_rect(red)
rect2 = create_rect(green)
rect3 = create_rect(blue)
rect4 = create_rect(yellow)
rect5 = create_rect(cyan)
rect6 = create_rect(purple)

stage.add(rect1)
stage.add(rect2)
stage.add(rect3)
stage.add(rect4)
stage.add(rect5)
stage.add(rect6)

stage.connect('hide', quit)
stage.show()
clutter.main()


アニメーション


処理をシンプルにするために、四角形をリストに入れて運ぶようにしている。
on_timeline_new_frameの中がかっこ悪いのが気になる。
#!/usr/bin/python
# -*- coding: utf-8 -*-

import clutter

# 回転情報
global rotation
rotation = 0


def on_timeline_new_frame(timeline, frame_num, rect_list):
global rotation
rotation += 0.3
rect_list[0].set_rotation(clutter.Z_AXIS, rotation * 5, 0, 0, 0)
rect_list[1].set_rotation(clutter.Z_AXIS, rotation * 4, 0, 0, 0)
rect_list[2].set_rotation(clutter.Z_AXIS, rotation * 3, 0, 0, 0)
rect_list[3].set_rotation(clutter.Z_AXIS, rotation * 2, 0, 0, 0)
rect_list[4].set_rotation(clutter.Z_AXIS, rotation * 1, 0, 0, 0)
rect_list[5].set_rotation(clutter.Z_AXIS, rotation * 0.5, 0, 0, 0)


def quit(actor, *args):
clutter.main_quit()


def create_rect(color):
rect = clutter.Rectangle(color)
rect.set_size(256, 128)
rect.set_position(128, 128)

return rect


clutter.init()
stage_color = clutter.Color(0, 0, 0, 255)
stage = clutter.Stage()
stage.set_size(512, 512)
stage.set_color(stage_color)

red = clutter.Color(255, 0, 0, 128)
green = clutter.Color(0, 255, 0, 128)
blue = clutter.Color(0, 0, 255, 128)
yellow = clutter.Color(255, 255, 0, 128)
cyan = clutter.Color(0, 255, 255, 128)
purple = clutter.Color(255, 0, 255, 128)

rect_list = []
rect_list.append(create_rect(red))
rect_list.append(create_rect(green))
rect_list.append(create_rect(blue))
rect_list.append(create_rect(yellow))
rect_list.append(create_rect(cyan))
rect_list.append(create_rect(purple))

stage.connect('hide', quit)
stage.show()

for r in rect_list:
stage.add(r)

timeline = clutter.Timeline(60)
timeline.connect('new-frame', on_timeline_new_frame, rect_list)
timeline.set_loop(True)
timeline.start()

clutter.main()


アニメーション アンカーポイントを変更


#!/usr/bin/python
# -*- coding: utf-8 -*-

import clutter

# 回転情報
global rotation
rotation = 0


def on_timeline_new_frame(timeline, frame_num, rect_list):
global rotation
rotation += 0.3
rect_list[0].set_rotation(clutter.Z_AXIS, rotation * 5, 0, 0, 0)
rect_list[1].set_rotation(clutter.Z_AXIS, rotation * 4, 0, 0, 0)
rect_list[2].set_rotation(clutter.Z_AXIS, rotation * 3, 0, 0, 0)
rect_list[3].set_rotation(clutter.Z_AXIS, rotation * 2, 0, 0, 0)
rect_list[4].set_rotation(clutter.Z_AXIS, rotation * 1, 0, 0, 0)
rect_list[5].set_rotation(clutter.Z_AXIS, rotation * 0.5, 0, 0, 0)


def quit(actor, *args):
clutter.main_quit()


def create_rect(color):
rect = clutter.Rectangle(color)
rect.set_size(256, 128)
rect.set_position(128, 128)
rect.set_anchor_point(128, 64)

return rect


clutter.init()
stage_color = clutter.Color(0, 0, 0, 255)
stage = clutter.Stage()
stage.set_size(512, 512)
stage.set_color(stage_color)

red = clutter.Color(255, 0, 0, 128)
green = clutter.Color(0, 255, 0, 128)
blue = clutter.Color(0, 0, 255, 128)
yellow = clutter.Color(255, 255, 0, 128)
cyan = clutter.Color(0, 255, 255, 128)
purple = clutter.Color(255, 0, 255, 128)

rect_list = []
rect_list.append(create_rect(red))
rect_list.append(create_rect(green))
rect_list.append(create_rect(blue))
rect_list.append(create_rect(yellow))
rect_list.append(create_rect(cyan))
rect_list.append(create_rect(purple))

stage.connect('hide', quit)
stage.show()

for r in rect_list:
stage.add(r)

timeline = clutter.Timeline(60)
timeline.connect('new-frame', on_timeline_new_frame, rect_list)
timeline.set_loop(True)
timeline.start()

clutter.main()


続きはまた今度。

日曜日, 1月 17, 2010

PyClutter 33行のHello, World的なコード

PyClutterはClutterのPythonバインド。
基本的な使い方はベースとなっているGtkとあまり変わらない。
import clutter

def main():
stage = clutter.Stage()
stage.set_color(clutter.Color(0xaa, 0xbb, 0xcc, 0xff))
stage.set_size(200, 200)

label = clutter.Text()
label.set_text('clutter')

button = clutter.Rectangle()
button.set_color(clutter.Color(0xcc, 0xbb, 0xaa, 0xff))
button.set_width(100)
button.set_height(100)
button.set_x(50)
button.set_y(50)
button.set_reactive(True)

stage.add(label)
stage.add(button)
stage.connect('button-press-event', change, label)
stage.connect('hide', quit)
stage.show_all()

def change(actor, event, label):
label.set_text('press button')

def quit(actor):
clutter.main_quit()

if __name__ == '__main__':
main()
clutter.main()

日曜日, 1月 03, 2010

スクリプト書き初め2010

「年末年始はスクリプト書く!」という人に触発されて、スクリプト書き初めをやってみました。
実行結果はこのようになります。



以下コード。
pygameでも出来ただろうけど、あえてPyClutterを使っています。
下敷きにしたのは、PyClutterサンプルのflower.py。
先に言い訳を書いておくと、コメントとか一切無いのは書き初めなので一気に書いたから、改行に見苦しい点があるのはpythontidyのせいです。

#!/usr/bin/python
# -*- coding: utf-8 -*-

import clutter
from clutter import CairoTexture
import cairo
import gobject

import sys
import random

BACKGROUND_COLOR = (0xee, 0xee, 0xee, 0xff)


class Snow(CairoTexture):

colors = (
(0.6, 0.7, 0.9, 0.5),
(0.6, 0.7, 1.0, 0.5),
(0.7, 0.9, 0.9, 0.5),
(0.7, 0.7, 1.0, 0.5),
(0.8, 0.7, 0.9, 0.5),
(0.8, 0.9, 1.0, 0.5),
)

def __init__(
self,
x,
y,
translation_velocity,
rotation_velocity,
ground,
):

self.x = x
self.y = y
self.rot = 0
self.v = translation_velocity
self.rv = rotation_velocity
self.ground = ground

CairoTexture.__init__(self, 20, 20)
cr = self.cairo_create()
cr.move_to(0, 0)
cr.rectangle(2, 2, 16, 16)
random_color = Snow.colors[random.randint(0, 5)]
cr.set_source_rgba(*random_color)
cr.paint()

def tick(self, max_width, max_height):
if self.ground - 10 < self.get_y():
return
self.y += self.v
self.rot += self.rv

if self.y > max_height:
self.y = -self.get_height()

self.set_position(self.x, self.y)
self.set_rotation(clutter.Z_AXIS, self.rot, self.get_width()
/ 2, self.get_height() / 2, 0)


class Kakizome(CairoTexture):

def __init__(self):
self.stage = clutter.Stage()
self.stage.set_color(clutter.Color(*BACKGROUND_COLOR))
self.stage.set_size(640, 480)
self.stage.set_title('Kakizome 2010')
self.started = False
self.ground = self.stage.get_height()

self.label = self.create_label('Hello, New Year.')
self.label.set_depth(1.0)
self.stage.add(self.label)

self.snows = list()

self.timeline = clutter.Timeline(500)
self.timeline.set_loop(True)
self.stage.connect('key-press-event', self.on_key_press)

gobject.timeout_add(50, self.tick, self.snows,
self.get_width(), self.stage.get_height())

def create_label(self, message):
label_color = clutter.Color(*BACKGROUND_COLOR)
label = clutter.Text()
label.set_text(message)
label.set_font_name('Mono 32')
label.set_color(label_color)
label_x = (self.stage.get_width() - label.get_width()) - 50
label.set_position(label_x, (self.stage.get_height() / 3) * 2)
return label

def tick(self, snows, height, width):
for snow in snows:
snow.tick(height, width)
if self.ground < 0:
return True

if random.randint(0, 1000) % 125 == 0:
self.ground -= 5

self.fall_snow()

return True

def fall_snow(self):
snow = Snow(random.randint(-10, self.stage.get_width()), -20,
random.randint(1, 5), random.randint(3, 5),
self.ground)
self.stage.add(snow)
snow.set_position(snow.x, snow.y)
self.snows.append(snow)

def run(self):
self.stage.show_all()
self.timeline.start()
clutter.main()

def on_key_press(self, actor, event):
key = event.get_key_symbol()
if key == clutter.keysyms.q:
clutter.main_quit()


if __name__ == '__main__':
app = Kakizome()
app.run()
sys.exit(0)

月曜日, 12月 28, 2009

wii-tagとりあえずのまとめ

夏ぐらいからCREAMとかGRLとかlaser-tagとかに関わって、考えた事のまとめ。

wii-tagを作り始めた動機はlaser-tagを見て、以下のようなことを考え始めたのがきっかけでした。
  • レーザー光線は危険
  • 原理上複数人で遊べないのはつまらない
  • laser-tagの面白さはどこにあるか気になる
もっとも、最初からwii-tagを作ろうとしたわけではなく、これらの事、特に一番下の事柄を考えることから始めました。

laser-tagの仕組みは大掛かりだけど単純で、レーザーポインタの軌跡をカメラでとらえてポイントされた位置をプロットして、その位置にブラシを描いた画像を、ポインタを当てた壁にプロジェクターで投影する、というものです。
laser-tagについて、レーザーポインタで絵を描くという宣伝文句が使われますが、実際にはレーザ光線で直接描いているわけではなく、カメラ、コンピュータ、プロジェクターがレーザー光線と描かれた絵の間に存在するわけです。
仕組み上、レーザーポインタは派手ではあるけど、座標を指定する役割しか持っていません。またカメラも結局のところ座標指定に必要なセンサーでしかなく、レーザーとカメラはセットとなります。座標の指定をしたいなら、レーザーポインタである必然性は実はなく、x,yの組さえ作り出せれば、他の道具でも構わないわけです。
この事からlaser-tagの核は、コンピュータ、プロジェクター、壁の3つではないかと考えました。
ではレーザーポインタの代わりに使えるものは何かという事で考えたのがWiiリモコンです。割と安直ですが、Wiiリモコンは以下のようなものです。
  • レーザーポインタとほぼ同じ操作感
  • レーザーポインタほど危険ではなく
  • 複数人による操作も可能
ここまでくるとWiiリモコンによるlaser-tagみたいなものがどのようなものか気になるわけです。誰かやっていないかと調べたのですが、誰もやっていないようで、自力でどうにかしないと手に入らない事が分かりました(実際にはGRLオーストラリアの人たちがWiiリモコンを使っていたのですが、その時は調べ切れませんでした)。

実際に作り始めると、Wiiリモコンをパソコンで使う方法がなかなか分からず、またセンサーバーも自作したりと、結構大変な作業でした。
その間にCREAMでの活動の中で、本家laser-tagについても触ったり、設定をいじったり、外でやったりする中で、レーザーポインタは必須では無いにしろ、派手さや遠距離到達性については無視できない特性であることに気付かされ、また危険性については回避しえない事の確認もしました。

今現在、wii-tagはプロトタイプとしては、ほぼ完成状態にあり、一度どこかの壁にプロジェクションして、動作を確かめたいと考えています。
ほぼ完成した今、気になっているのは、この5ヶ月ほどwii-tagを作りつづけた行為は何なのかという事です。
現時点での答えは、wii-tagは鑑賞行為であり、批評行為であるというものです。
ベルナール・スティグレールが紹介しているのですが、19世紀において美術館は作品を鑑賞するだけの場ではなく、模写をする場だったそうです。眼だけではなく、模写という手の運動によって、作品を自分の中に取り込む事が、作品を鑑賞するという行為であり、批評行為だったわけです。
wii-tagはまさにlaser-tagの模写と言えます。5ヶ月がかりでwii-tagを作ると言うことは、5ヶ月がかりでlaser-tagを鑑賞してきた事と同じであり、ここまでやらないとlaser-tagについて最初に考えた事を解決する事は不可能でした。
またこのことは、デジタル・テクノロジーが安価になる事で、デジタル・テクノロジーを利用した作品も模写出来るようになったという事を表しています。
wii-tagについては、鑑賞、批評行為であったと一応結論づけるとして、模写による鑑賞が、デジタル・テクノロジーによる作品についても可能になったという事がどういう事なのかについては、もう少し考える必要があるようです。

今年読んだ小説

何を読んだか記録しておくために、とりあえず記憶の中からリストアップ。
本当は小説に限らず全部記録すべきで、そのためには都度記録した方がいいんだろうけど。
小説というよりSFばかり。そして特に意識していなかったけど女流作家とイギリスの作品が多い。
これは最近のハヤカワの傾向なのでしょうか?
順番は基本的に挙げてある最後の本を読んだ作家順です。
訳者は調べ直したけど、間違いがあるかも。

プロバビリティ・ムーン
プロバビリティ・サン
プロバビリティ・スペース

ナンシー・クレス/著 金子司/訳


複数の異星文明との接触とその戦争を描いたシリーズ。
古代の銀河系超文明が残したらしいゲートを使った跳躍航法によって光速を突破出来る設定。
タイトル通り、だんだんスケールが大きくなっていく。
が、一番の見どころは、登場する異星文明の描写だと思う。
そういう意味で、一番面白いのはムーンかと。サンとスペースはどちらかというと人類の描写が中心なので。





エイリアン・テイスト
ティンカー
ようこそ女たちの王国へ

ウェン・スペンサー/著 赤尾秀子/訳


キャラ重視で作品を作っているらしい作家。でもティンカーや、ようこそ女たちの王国へで描かれる異文化の描写も面白いと思う。
エイリアン・テイストも異文化とまではいかないけど、特異なコミュニティの文化の描写に力をいれているように見える。
表紙のノリは軽いけど、人物描写が丁寧なので
内容とは直接関係ないけど各作品の表紙の絵と「A Brother's Price」を「ようこそ女たちの王国へ」というタイトルにしたのは最高だと思う。






アイオーン
ラー

高野史緒


アイオーンは短篇の集合のような構成。架空のヨーロッパを中心にした大河物語といえばよいか。
スケールがでかいし、SF的ウソもでかいので、テンポ良く読める。
ラーはそれに比して、ウソがちっちゃい。実際の研究とかけ離れすぎないようにしているのかもしれないけど、どうせならでかいウソの方がいい。





啓示空間
カズムシティ
量子真空
火星の長城
銀河北極

アレステア・レナルズ/著 中原尚哉/訳


同じ世界、歴史設定によるシリーズ。火星の長城と銀河北極は短編集で、それ以外は長編。
どっかで聞いたような設定やガジェットがポコポコ出てくるので、ニヤニヤしながら読むのがお勧め。
エイリアンvsプレデターみたいなお遊びを許せない人は読まない方がいい。
シリーズ物なので、あっちの話の主役がこっちで脇役という事はあるものの、個々の話は独立しているので、好きな順序で読めばいい。
ただし、啓示空間と量子真空だけはこの順序で読むのがお勧め。基本的には出版順で読むと良いかと

特徴としては超光速やワープを禁じ手としているので、銀河系レベルで見ると結構狭い範囲のお話。
遺伝子改造、身体機械化、精神のアップロードは出来るけど、シリーズ中の出来事によって万能過ぎる技術は極限定的にしか存在しなくなる。
ほぼ登場人物が見聞きした事を通してしか情景が描かれないので、登場人物が観測できないことは描写が薄くなる傾向がある。
つまり登場人物が冷凍睡眠に入ると、起きるまで時間が飛んで、その間の出来事は読者も登場人物も分からないという現象が発生する。
登場人物は寝ていた時間に何があったかを、ネットと自分の足とで探りだそうとするので、なんとなくRPG的雰囲気がする。

もう一つの特徴は、長編が物理的に分厚いこと。3冊とも1000ページを超えるので読み応えがある。
厚くても中だるみしないのは、軽い謎解き要素のおかげかと。
今年一番はまったシリーズ。







シンギュラリティ・スカイ

チャールズ・ストロス/著 金子浩/訳


シンギュラリティが起きた後の物語なのに、いまいちそんな感じがしない。
事件は確かに起きているのに、いまいち緊迫感がないというか、登場人物たちは一応行動は起こすのだけど、どうしようもなさすぎる事態すぎて結局何も出来ないまま。
逆に言うと、作品世界内の人間の順応性がやたら高くて、解決できない場合、適応してしまうのだよね。
道具立ては好みなのに、なぜかしっくりこなかった。世界設定がもっと詳しく描かれれていれば、入り込めたかも。




トランスフォーマーリベンジ
アラン・ディーン・フォスター/著 中原尚哉/訳


映画第二作のノベライズ。フォスターさんは映画のノベライズを多く手がけていて、トランスフォーマーに関しても映画第一作のノベライズと映画の前日譚にあたる小説も書いている。
映画とどこまで設定が同じなのか分からないけど、映画では映像で語っていることを、文字で語ってくれるので、映画を補完する設定資料集として読むのが良いのかも。
映画では軽く流されていたところが、実は伏線だったりとか。発見も多い。
結構細かく描写されているとはいえ、サイバトロンにしろデストロイにしろ、造型が頭に浮かばないと読んでいて楽しくないので、映画を見てから読むのが正解。




戦いの子
艦長の子
海賊の子

カリン・ロワチー/著 嶋田 洋一/訳


三部作だけど、海賊の子は他二冊からだいぶ離れていて、外伝的印象がある。
一番面白いと思ったのは、戦いの子。異星文明と人類文明の差、その中で成長していく主人公の描写は、成長物語として悪く言えばありきたりだけど、王道でもある。
艦長の子と海賊の子は、人類文明も一つではない事と、その中での成長を描いていて面白いのだけど、第一作の主人公の王道さにどうしても負けてしまうように思える。
出来れば三人の子供たちがもっと絡んで欲しかったなあ。周辺人物も魅力的だし、続ければ続けられると思うのだけど、このシリーズは一旦お終いらしい。
読むなら、きちんと順番に読んだ方がいい。
ところで、巻を追うごとに腐女子向け要素が増えていくのは何故だろう。






機動戦士ガンダムUC1~10

福井晴敏


CCAの後、マフティー動乱の前の話。
ニュータイプというか、人類の可能性についての話しでもある。
ただオーバーセンス的な元気の良さはあまり無い。
アニメ版が楽しみ。









木曜日, 12月 24, 2009

pythontidyをvimで使うためのスクリプト

Pythonのコードフォーマッタといえば、pythontidy。
普通にコマンドとしても使えるわけですが、今書いているものに対して使用したいわけです。
で、私のメインエディタはvimなので、vimで使うにはどうすればいいか。

ただ使うだけならpythontidyにパスを通して:%! pythontidyでよい。普通はこれを適当なキーにマッピングしてやることになるはず。

ただpythontidyはsyntax errorのあるコードを受け付けないらしく、この方法ではsyntax errorが含まれているときに実行すると、エラーメッセージというかtracebackがバッファに書き込まれてしまう。uすれば戻るけど、うっかり:wqとかすると大変な事になる。

正常に動作した場合でもカーソルが一番上の行に移動してしまう。これはマークを設定してやれば回避できるけど面倒すぎる。

というわけで、pythontidyを使うためだけのvimスクリプトを書いてみた。
前提としてPYTHONPATHにpythontidyが入るようにしておくこと。
function! Pythontidy()
python << EOF
import tempfile
import vim
import pythontidy

cb = vim.current.buffer[:]
b = tempfile.TemporaryFile(mode="rb+")
out = tempfile.TemporaryFile(mode="rb+")
for l in cb[:]:
b.write(l + '\n')
b.seek(0)
pythontidy.tidy_up(b, out)
out.seek(0)
vim.current.buffer[:] = out.readlines()
EOF
endfunction

これをpython_tidy.vimという名前でもつけてあげて、ftpluginの下に置いてやる。
で、python.vimにmap <f5> :call Pythontidy()と書く。<f5>のところは任意のキーでいい。
これでsyntax errorを含むコードを食べさせても、インフォメーションメッセージにエラーが出てくる。ちゃんと動作したときも行の位置が変化しない。

これで安心してダラダラコーディングできる。