火曜日, 4月 06, 2010

子供が出来て考えたこと

出来たといっても、まだ生まれていないので、正直まだ実感が湧かない
エコー写真で1cmも満たない黒い影(既に心臓は動いているらしい)を見ても良く分からない。
そんな状態で思ったことをいくつか。

母子手帳。父はどこに?


妊娠すると母子手帳ってのがもらえます。正確には母子健康手帳です。市町村(区)から交付されます。
とりあえずツッコミどころとして「母子」なんですよね。「父」はどこに行ったんでしょう?ものすごい疎外感です。
これ、なんで「母子健康手帳」なのかっていうと、法律だからなんですね。母子保健法の第十六条にばっちり「母子健康手帳」と書いてあります。


(母子健康手帳)
第十六条  市町村は、妊娠の届出をした者に対して、母子健康手帳を交付しなければならない。
2  妊産婦は、医師、歯科医師、助産師又は保健師について、健康診査又は保健指導を受けたときは、その都度、母子健康手帳に必要な事項の記載を受けなければならない。乳児又は幼児の健康診査又は保健指導を受けた当該乳児又は幼児の保護者についても、同様とする。
3  母子健康手帳の様式は、厚生労働省令で定める。
4  前項の厚生労働省令は、健康診査等指針と調和が保たれたものでなければならない。


ちょっとひどいよね。一応、自治体によっては名称を親子手帳に変えているところもあるみたいですが(豊田市の事例、岡山市の事例ぐぐって見つけた順)。
それと母子手帳とは別に父子手帳を用意している自治体もあります。例えば東京都は父親ハンドブックというものを配布しています(紙は180円で売っているそうな)。
とはいえ、法律でそのような名称を規程しているのはどうなんだろう。
まさか親子手帳ってのは男女共同参画(内閣府)でやるべきで、育児(厚生労働省)ではやるべきでない、みたいな典型的縦割行政ってことはないよね。

まあ、妊娠出産する上で、父親には何のリスクも無いというのも事実なわけですが。

産むより育てる(育つ)方が大変らしい


当たり前かもしれませんが、母子手帳で出産に関する部分って前の方のほんのちょっとです。あとは全部生まれてからのこと。
時間的にも生まれてからの方がはるかに長い(少なくともそれを期待する)わけですしね。
ただ産むのが楽かというとそうでもない。母体への負担はもちろんだけど、分娩可能な病院は妊娠確認後にすぐ予約しないと駄目らしい。今、Wikipediaの出産難民の項を見たけど、『「分娩予約が予定日の6ヶ月前」などという事態がみられ』と書いてある。6ヶ月前ならまだマシな方です。誰か書き換えておいて下さい。
ともかく、産科の医師不足ってのは深刻らしい。
とりあえずうちは予約できたので一安心しておく。

妊娠を伝える時期


当然ながら、妊娠した事を親戚知人に伝えねばなら無いわけで(内緒にしないといけない人もいるかもしれませんが)。うちは割とすぐ話しましたが。世の中には安定期になるまで話さないという人もいるらしい。
回りのサポートを得るには早い方がいいとは思うものの、初期流産の率は10~15%と結構高いので、ある程度待つというのも分かる気がする。
初期流産というのは防ぎようがない確率の問題らしいし。といっても妊婦はショックが大きいらしいし、場合によっては身体が危険になる場合もあるらしい。例によって父親には少なくとも身体的リスクは無いのだけど。精神的にはどうだろう。
なんだかんだで産むのも大変なような。

妊婦の様子


どうやら、ものすごく眠くなるらしい(寝つわり)。そして口に何か入れていないと気持ち悪くなるそうな(食べつわり)。なので少しの量を分散させて食べている。そうなのだが、明らかに量が増えているような気がしないでもない。それはともかく食べ過ぎは良くないらしい。赤ちゃんはまだ2cmぐらいなので、栄養が行っても処理し切れないのだろうな。赤ちゃんを育てるだけでなく母体も中をガードするために壁を作らなければならないだろうから、少しぐらいはいいのだろうか。食べられなくなるつわりは、もう少したったらなるみたいだし、そうなったら量も取れなくなるだろうし。
一応、ノートにその日何を食べたか記録しているけど、続くかしら。
嫁様は偏頭痛持ちなので、妊娠後に発生するかと思ったけど、どうやらなっていないらしい。人によっては症状がひどくなるらしいので、これはよかった。今気づいたけど、カフェインの摂取を減らしているのに頭痛になってないもよう。
コーヒーが切れると頭痛が起きる身としては羨ましい。



もうすこしエコー画像が人型になれば実感がわくようになるかなあ。

水曜日, 3月 03, 2010

道を聞かれた

おばあさんに駅までの道を聞かれる。
駅は見えている場所なのだが、道が分からなかったらしい。
世の中の駅は難しい場所にあるものなのか。

土曜日, 2月 13, 2010

道を聞かれた2010年初

道をあるいていたら、おばちゃんから公共施設の場所を聞かれた。
知っている場所だったので普通に教えた。
どうやら私の前の人の説明が適当過ぎだったらしい。

火曜日, 2月 02, 2010

gstreamerでWebCamを使うときにひっかかった罠

gstreamerという、ライブラリ(ライブラリ群?)があります。
Linuxな人には馴染み深いですね。マルチメディア処理では定番のライブラリです。
このライブラリは、様々なマルチメディア要素をパイプラインを通すように処理出来ます。
詳しいことは、ちゃんとしたチュートリアルを見てください。

さて、それらのチュートリアルに、もしかしらWebCamから映像を取り込む内容が含まれているかもしれません。ここに罠が潜んでいます。
WebCamソースを表すgstreamerの識別子は「v4l2src」です。「412」ではなく「4l2」です。
「Video for Linux 2 のソース」 = 「v4l2src」=「ぶい よん える に えす あーる しー」です。

世界的に引っかかる人が多く、おそらくこれからもひっかかる人が多数出るはずなので、メモを残しておきます。

木曜日, 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()