[from now] 2012/07/21 14:03:17

diff --git a/lib/stylet/base.rb b/lib/stylet/base.rb
index dbfa636..eede189 100644
--- a/lib/stylet/base.rb
+++ b/lib/stylet/base.rb
@@ -6,7 +6,7 @@ require "singleton"
 require "pp"
 require "pathname"

-require File.expand_path(File.join(File.dirname(__FILE__), "config"))
+require_relative "config"

 # 汎用ライブラリ
 require File.expand_path(File.join(File.dirname(__FILE__), "color"))
diff --git a/lib/stylet/fee.rb b/lib/stylet/fee.rb
index 5a27ebe..8f86d38 100644
--- a/lib/stylet/fee.rb
+++ b/lib/stylet/fee.rb
@@ -9,7 +9,7 @@ module Stylet
   module SinTableModule
     def initialize
       super
-      @sin_table = (0...ROUND).collect{|i|(Math.sin(2 * Math::PI * i / ROUND) * ONE).round}
+      @sin_table = ROUND.times.collect{|i|(Math.sin(2 * Math::PI * i / ROUND) * ONE).round}
     end

     def isin(a)
@@ -259,6 +259,6 @@ if $0 == __FILE__
   #   dir = Stylet::Fee.angle(0, 0, x, y)
   #   [i, r, dir, (r == dir)]
   # }
-  # pp (0...8).collect{|i|[i, Stylet::Fee.sin(1.0 / 8 * i)]}
+  # pp 8.times.collect{|i|[i, Stylet::Fee.sin(1.0 / 8 * i)]}
   # pp (0..12).collect{|i|[i, Stylet::Fee.clock(i)]}
 end
[from now] 2012/07/22 10:01:23

diff --git a/Gemfile b/Gemfile
index 8aafd51..611eb3e 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,7 +2,7 @@ source :rubygems

 gem "activesupport"
 gem "rsdl", ">= 0.1.4"
-gem "rubysdl", ">= 2.1.1"
+gem "rubysdl", ">= 2.1.2"
 gem "i18n"

 group :test do
diff --git a/Gemfile.lock b/Gemfile.lock
index b62558a..c06f325 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,21 +1,22 @@
 GEM
   remote: http://rubygems.org/
   specs:
-    activesupport (3.1.3)
+    activesupport (3.2.6)
+      i18n (~> 0.6)
       multi_json (~> 1.0)
     diff-lcs (1.1.3)
     i18n (0.6.0)
-    multi_json (1.0.4)
+    multi_json (1.3.6)
     rsdl (0.1.4)
-    rspec (2.8.0)
-      rspec-core (~> 2.8.0)
-      rspec-expectations (~> 2.8.0)
-      rspec-mocks (~> 2.8.0)
-    rspec-core (2.8.0)
-    rspec-expectations (2.8.0)
-      diff-lcs (~> 1.1.2)
-    rspec-mocks (2.8.0)
-    rubysdl (2.1.1)
+    rspec (2.11.0)
+      rspec-core (~> 2.11.0)
+      rspec-expectations (~> 2.11.0)
+      rspec-mocks (~> 2.11.0)
+    rspec-core (2.11.1)
+    rspec-expectations (2.11.1)
+      diff-lcs (~> 1.1.3)
+    rspec-mocks (2.11.1)
+    rubysdl (2.1.2)

 PLATFORMS
   ruby
@@ -25,4 +26,4 @@ DEPENDENCIES
   i18n
   rsdl (>= 0.1.4)
   rspec
-  rubysdl (>= 2.1.1)
+  rubysdl (>= 2.1.2)
diff --git a/README.md b/README.md
deleted file mode 100644
index 085e5d7..0000000
--- a/README.md
+++ /dev/null
@@ -1,188 +0,0 @@
-物理運動アルゴリズムのお勉強用Ruby/SDLラッパーライブラリ
-========================================================
-
-## Ruby/SDL環境の作り方とサンプルの実行方法(for Mac OS X)
-
-### 基本ライブラリのインストール
-
-    $ sudo port install libsdl libsdl_ttf libsdl_sound libsdl_pango libsdl_mixer libsdl_image rb-opengl
-
-### SGEのインストール(debianだと一発でインストールできたはず)
-
-* sge030809.tar.gz をダウンロードして ~/Downloads/sge030809 に展開。
-* http://coderepos.org/share/changeset/10163 から *.patch をダウンロードし ~/Downloads/sge030809 にコピー。
-
-    $ cd ~/Downloads/sge030809
-    $ patch -p1 < Makefile.conf.patch
-    $ patch -p1 < Makefile.patch
-    $ make
-    $ sudo make install
-
-### rubysdlのインストール(上のライブラリを更新、追加した場合は改めて↓を実行すること)
-
-    gem install rubysdl rsdl
-
-Macの場合 ruby からではなく rsdl から実行する
-
-### Hello, world の実行方法
-
-    $ cat hello.rb
-    require "stylet"
-    Stylet::Base.main_loop do |win|
-      win.vputs "Hello, world."
-    end
-
-    $ bundle exec rsdl hello.rb
-    [q]で終了
-
-### サンプルの一括動作テスト方法
-
-    $ cd examples
-    $ ruby test_all.rb
-
-TIPS
-====
-
-### 速度ベクトルの向きを取得するには？
-
-    speed.angle
-
-### 速度ベクトルを45度傾けるには？
-
-    speed + Stylet::Vector.angle_at(Stylet::Fee.r45) * speed.length
-
-    Stylet::Vector.angle_at(speed.angle + Stylet::Fee.r45) * speed.length
-
-    speed.rotate(Stylet::Fee.r45)
-
-    speed.rotate2(Stylet::Fee.r45)
-
-### p0の速度ベクトルをマウスの方向に設定するには？
-
-    speed = Stylet::Vector.angle_at(p0.angle_to(win.mouse_vector)) * speed.length
-
-### 円の速度制限をするには？(円が線から飛び出さないようにするときに使う)
-
-    if speed.length > radius
-      speed = speed.normalize.scale(radius)
-    end
-
-### 線分ABの中央の位置を取得するには？
-
-    half_ab = pA + Stylet::Vector.angle_at(pA.angle_to(pB)) * (pA.distance_to(pB) / 2)
-
-    Vector.pos_vector_rate(pA, pB, 0.5)
-
-### 円(c,r)が点(dot)にめりこんだとき、点(dot)から円を押し出すには？
-
-#### 悪い例
-
-    if c.distance_to(dot) < r
-      c = dot + Stylet::Vector.angle_at(dot.angle_to(c)) * r
-    end
-
-#### 良い例
-
-    diff = c - dot
-    rdiff = diff.length - r
-    if rdiff > 0
-      # c = dot + diff.normalize * r # ドットから押す場合(ドットが釘ならこれでもよい)
-      c += diff.normalize * rdiff
-    end
-
-### 円Aと円Bをお互い離すには？(跳ね返り処理は別)
-
-    diff = b - a
-    rdiff = r * 2 - diff.length
-    if rdiff > 0
-      a -= diff.normalize * rdiff / 2
-      b += diff.normalize * rdiff / 2
-    end
-
-###  固定点Aに円(p0,r)がめり込んでいたらAから跳ね返すには？
-
-    diff = p0 - pA
-    if diff.length > 0
-      if diff.length < r
-        p0 = pA + diff.normalize.scale(r)          # めりこみ解消
-        speed = diff.normalize.scale(speed.length) # 跳ね返す
-      end
-    end
-
-## 円Aと円Bが衝突してBからAを押したり引いたりするには？(Bは動かない。また両方跳ね返らない。Aは除けるだけ)
-
-    r2 = ar + br
-    if a != b
-      diff = b - a
-      rdiff = r2 - diff.length
-      # 押す場合
-      if rdiff > 0
-        # a = b + diff.normalize * r2  # Bを基点に押し出す(1)
-        b += diff.normalize * rdiff    # Aを基点に押し出す(2)
-      end
-      # 引く場合
-      if rdiff < 0
-        # (1) or (2) どちらでも
-      end
-    end
-
-### 正規化とは斜めの辺の長さを 1.0 にすること
-
-    v.normalize.length #=> 1.0
-
-### A B C D ボタンとカーソルで操作できるとき物体(pA)と速度(speed)をコントロールするときの定石は？
-
-    # AとBで速度ベクトルの反映
-    @pA += @speed.scale(@win.button.btA.repeat_0or1) + @speed.scale(-@win.button.btB.repeat_0or1)
-    # @pA += @speed.scale(@win.button.btA.repeat) + @speed.scale(-@win.button.btB.repeat) # 加速したいとき
-
-    # Cボタンおしっぱなし + マウスで自機位置移動
-    if @win.button.btC.press?
-      @pA = @win.cursor.clone
-    end
-
-    # Dボタンおしっぱなし + マウスで自機角度変更
-    if @win.button.btD.press?
-      if @win.cursor != @pA
-        # @speed = Stylet::Vector.angle_at(@pA.angle_to(@win.cursor)) * @speed.radius # ← よくある間違い
-        @speed = (@win.cursor - @pA).normalize * @speed.length # @speed.length の時点で桁溢れで削れるのが嫌なら length.round とする手もあり
-      end
-    end
-
-### 円が完全に重なっている場合、ランダムに引き離す定石
-
-    diff = a - b
-    if diff.length.zero?
-      arrow = Stylet::Vector.nonzero_random_new
-      a -= arrow * ar
-      b += arrow * br
-    end
-
-### 同時押しをシミューレートするには？
-
-    # A:←A S:←B D:→A F:→B
-    @axis.left  << (SDL::Key.press?(SDL::Key::A) | SDL::Key.press?(SDL::Key::S))
-    @axis.right << (SDL::Key.press?(SDL::Key::D) | SDL::Key.press?(SDL::Key::F))
-    @button.btA << (SDL::Key.press?(SDL::Key::A) | SDL::Key.press?(SDL::Key::D))
-    @button.btB << (SDL::Key.press?(SDL::Key::S) | SDL::Key.press?(SDL::Key::F))
-
-### 内積を取得するには？
-
-    v = Stylet::Vector.inner_product(a, b)
-    #  1. ←← or →→ 正 (0.0 < v)   お互いだいたい同じ方向を向いている
-    #  2. →←         負 (v   < 0.0) お互いだいたい逆の方向を向いている
-    #  3. →↓ →↑    零 (0.0)       お互いが直角の関係
-
-TODO
-====
-
-* x1, y1 = points[i % points.size] は cons に置き換えれる
-
-参考URL
-=======
-
-* [Flashゲーム講座&アクションスクリプトサンプル集](http://hakuhin.jp/as.html)
-* [基礎の基礎編その１ 内積と外積の使い方](http://marupeke296.com/COL_Basic_No1_InnerAndOuterProduct.html)
-* [内積が角度になる証明](http://marupeke296.com/COL_Basic_No1_DotProof.html)
-* [衝突判定編](http://marupeke296.com/COL_main.html)
-* [反射ベクトルと壁ずりベクトル](http://marupeke296.com/COL_Basic_No5_WallVector.html)
diff --git a/README.org b/README.org
new file mode 100644
index 0000000..0b1c609
--- /dev/null
+++ b/README.org
@@ -0,0 +1,210 @@
+* 物理運動アルゴリズムのお勉強用Ruby/SDLラッパーライブラリ
+
+** 簡単なRuby/SDL環境の作り方(for Mac OS X)
+
+   brew uninstall sdl sdl_image sdl_ttf sdl_mixer sge-manualcompile
+   gem uninstall -x rubysdl rsdl
+
+   brew install sdl sdl_image sdl_ttf sdl_mixer
+   brew install https://raw.github.com/gist/3115276/719f284d6e340487dba6ef3e5beb7b7a4098414f/sge-manualcompile.rb
+   brew link sge-manualcompile
+   gem install rubysdl rsdl
+
+   # 確認。すべて true になればOK
+   ruby -r sdl -e 'p [:sge, SDL.respond_to?(:autoLock)]'
+   ruby -r sdl -e 'p [:mixer, SDL.constants.include?(:Mixer)]'
+   ruby -r sdl -e 'p [:ttf, SDL.constants.include?(:TTF)]'
+
+   ※ Mac OS X Lionにsgeを入れる #Ruby #SDL - Qiita http://qiita.com/items/f52daed19fa0198121b5 参考
+
+** Macのportで入れる場合
+
+   sudo port install libsdl libsdl_ttf libsdl_sound libsdl_pango libsdl_mixer libsdl_image rb-opengl
+
+   # sge030809.tar.gz をダウンロードして ~/Downloads/sge030809 に展開。
+   # http://coderepos.org/share/changeset/10163 から *.patch をダウンロードし ~/Downloads/sge030809 にコピー。
+
+   $ cd ~/Downloads/sge030809
+   $ patch -p1 < Makefile.conf.patch
+   $ patch -p1 < Makefile.patch
+   $ make
+   $ sudo make install
+
+   gem install rubysdl rsdl
+
+   Macの場合 ruby からではなく rsdl から実行する
+
+** Hello, world の実行方法
+
+    $ cat hello.rb
+    require "stylet"
+    Stylet::Base.main_loop do |win|
+      win.vputs "Hello, world."
+    end
+
+    $ bundle exec rsdl hello.rb
+    [q]で終了
+
+** サンプルの一括動作テスト方法
+
+    $ cd examples
+    $ ruby test_all.rb
+
+* TIPS
+
+** 速度ベクトルの向きを取得するには？
+
+    speed.angle
+
+** 速度ベクトルを45度傾けるには？
+
+    speed + Stylet::Vector.angle_at(Stylet::Fee.r45) * speed.length
+
+    Stylet::Vector.angle_at(speed.angle + Stylet::Fee.r45) * speed.length
+
+    speed.rotate(Stylet::Fee.r45)
+
+    speed.rotate2(Stylet::Fee.r45)
+
+** p0の速度ベクトルをマウスの方向に設定するには？
+
+    speed = Stylet::Vector.angle_at(p0.angle_to(win.mouse_vector)) * speed.length
+
+** 円の速度制限をするには？(円が線から飛び出さないようにするときに使う)
+
+    if speed.length > radius
+      speed = speed.normalize.scale(radius)
+    end
+
+** 線分ABの中央の位置を取得するには？
+
+    half_ab = pA + Stylet::Vector.angle_at(pA.angle_to(pB)) * (pA.distance_to(pB) / 2)
+
+    Vector.pos_vector_rate(pA, pB, 0.5)
+
+** 円(c,r)が点(dot)にめりこんだとき、点(dot)から円を押し出すには？
+
+*** 悪い例
+
+    if c.distance_to(dot) < r
+      c = dot + Stylet::Vector.angle_at(dot.angle_to(c)) * r
+    end
+
+*** 良い例
+
+    diff = c - dot
+    rdiff = diff.length - r
+    if rdiff > 0
+      # c = dot + diff.normalize * r # ドットから押す場合(ドットが釘ならこれでもよい)
+      c += diff.normalize * rdiff
+    end
+
+** 円Aと円Bをお互い離すには？(跳ね返り処理は別)
+
+    diff = b - a
+    rdiff = r * 2 - diff.length
+    if rdiff > 0
+      a -= diff.normalize * rdiff / 2
+      b += diff.normalize * rdiff / 2
+    end
+
+**  固定点Aに円(p0,r)がめり込んでいたらAから跳ね返すには？
+
+    diff = p0 - pA
+    if diff.length > 0
+      if diff.length < r
+        p0 = pA + diff.normalize.scale(r)          # めりこみ解消
+        speed = diff.normalize.scale(speed.length) # 跳ね返す
+      end
+    end
+
+** 円Aと円Bが衝突してBからAを押したり引いたりするには？(Bは動かない。また両方跳ね返らない。Aは除けるだけ)
+
+    r2 = ar + br
+    if a != b
+      diff = b - a
+      rdiff = r2 - diff.length
+      # 押す場合
+      if rdiff > 0
+        # a = b + diff.normalize * r2  # Bを基点に押し出す(1)
+        b += diff.normalize * rdiff    # Aを基点に押し出す(2)
+      end
+      # 引く場合
+      if rdiff < 0
+        # (1) or (2) どちらでも
+      end
+    end
+
+** 正規化とは斜めの辺の長さを 1.0 にすること
+
+    v.normalize.length #=> 1.0
+
+** A B C D ボタンとカーソルで操作できるとき物体(pA)と速度(speed)をコントロールするときの定石は？
+
+    # AとBで速度ベクトルの反映
+    @pA += @speed.scale(@win.button.btA.repeat_0or1) + @speed.scale(-@win.button.btB.repeat_0or1)
+    # @pA += @speed.scale(@win.button.btA.repeat) + @speed.scale(-@win.button.btB.repeat) # 加速したいとき
+
+    # Cボタンおしっぱなし + マウスで自機位置移動
+    if @win.button.btC.press?
+      @pA = @win.cursor.clone
+    end
+
+    # Dボタンおしっぱなし + マウスで自機角度変更
+    if @win.button.btD.press?
+      if @win.cursor != @pA
+        # @speed = Stylet::Vector.angle_at(@pA.angle_to(@win.cursor)) * @speed.radius # ← よくある間違い
+        @speed = (@win.cursor - @pA).normalize * @speed.length # @speed.length の時点で桁溢れで削れるのが嫌なら length.round とする手もあり
+      end
+    end
+
+** 円が完全に重なっている場合、ランダムに引き離す定石
+
+    diff = a - b
+    if diff.length.zero?
+      arrow = Stylet::Vector.nonzero_random_new
+      a -= arrow * ar
+      b += arrow * br
+    end
+
+** 同時押しをシミューレートするには？
+
+    # A:←A S:←B D:→A F:→B
+    @axis.left  << (SDL::Key.press?(SDL::Key::A) | SDL::Key.press?(SDL::Key::S))
+    @axis.right << (SDL::Key.press?(SDL::Key::D) | SDL::Key.press?(SDL::Key::F))
+    @button.btA << (SDL::Key.press?(SDL::Key::A) | SDL::Key.press?(SDL::Key::D))
+    @button.btB << (SDL::Key.press?(SDL::Key::S) | SDL::Key.press?(SDL::Key::F))
+
+** 内積を取得するには？
+
+    v = Stylet::Vector.inner_product(a, b)
+    #  1. ←← or →→ 正 (0.0 < v)   お互いだいたい同じ方向を向いている
+    #  2. →←         負 (v   < 0.0) お互いだいたい逆の方向を向いている
+    #  3. →↓ →↑    零 (0.0)       お互いが直角の関係
+
+* TODO
+
+- x1, y1 = points[i % points.size] は cons に置き換えれる
+
+* 参考URL
+
+- Flashゲーム講座&アクションスクリプトサンプル集 http://hakuhin.jp/as.html
+- 基礎の基礎編その１ 内積と外積の使い方 http://marupeke296.com/COL_Basic_No1_InnerAndOuterProduct.html
+- 内積が角度になる証明 http://marupeke296.com/COL_Basic_No1_DotProof.html
+- 衝突判定編 http://marupeke296.com/COL_main.html
+- 反射ベクトルと壁ずりベクトル http://marupeke296.com/COL_Basic_No5_WallVector.html
+
+#+TITLE:     Stylet - Ruby/SDLラッパーライブラリ
+#+AUTHOR:    akicho8
+#+EMAIL:     akicho8@gmail.com
+#+DATE:      2012-07-21 土
+#+DESCRIPTION:
+#+KEYWORDS:
+#+LANGUAGE:  ja
+#+OPTIONS:   H:3 num:t toc:t \n:nil @:t ::nil |:t ^:nil -:nil f:t *:t <:t
+#+OPTIONS:   TeX:nil LaTeX:nil skip:nil d:nil todo:t pri:nil tags:not-in-toc
+#+INFOJS_OPT: view:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js
+#+EXPORT_SELECT_TAGS: export
+#+EXPORT_EXCLUDE_TAGS: noexport
+#+LINK_UP:
+#+LINK_HOME:
diff --git a/examples/0010_code_block_strategy.rb b/examples/0010_code_block_strategy.rb
index 89eb304..de8936a 100644
--- a/examples/0010_code_block_strategy.rb
+++ b/examples/0010_code_block_strategy.rb
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-require File.expand_path(File.join(File.dirname(__FILE__), "../lib/stylet"))
+require_relative "../lib/stylet"
 Stylet::Base.instance.title = "コードブロックを使ったストラテジー"
 Stylet::Base.main_loop do |win|
   win.vputs "Hello, world."
diff --git a/examples/0020_template_method.rb b/examples/0020_template_method.rb
index 25626f7..bbf405f 100644
--- a/examples/0020_template_method.rb
+++ b/examples/0020_template_method.rb
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-require File.expand_path(File.join(File.dirname(__FILE__), "../lib/stylet"))
+require_relative "../lib/stylet"

 class App < Stylet::Base
   def before_main_loop
diff --git a/examples/0030_input.rb b/examples/0030_input.rb
index 1337486..d25349e 100644
--- a/examples/0030_input.rb
+++ b/examples/0030_input.rb
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 # キーボードの入力チェック
-require File.expand_path(File.join(File.dirname(__FILE__), "../lib/stylet"))
+require_relative "../lib/stylet"

 class Player
   include Stylet::Input::Base
diff --git a/examples/0040_draw_circle.rb b/examples/0040_draw_circle.rb
index 0939352..6e9b33f 100644
--- a/examples/0040_draw_circle.rb
+++ b/examples/0040_draw_circle.rb
@@ -2,9 +2,9 @@
 #
 # 円の描画
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "../lib/stylet"))
+require_relative "../lib/stylet"

 Stylet::Base.instance.title = "円の描画"
 Stylet::Base.main_loop do |win|
-  win.draw_circle(win.rect.center, :vertex => 256)
+  win.draw_polygon(win.rect.center, :vertex => 256)
 end
diff --git a/examples/0050_circle_on_circle.rb b/examples/0050_circle_on_circle.rb
index ea8c675..db58f69 100644
--- a/examples/0050_circle_on_circle.rb
+++ b/examples/0050_circle_on_circle.rb
@@ -2,10 +2,10 @@
 #
 # 円上を動く円
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "../lib/stylet"))
+require_relative "../lib/stylet"

 Stylet::Base.instance.title = "円上を動く円"
 Stylet::Base.main_loop do |win|
   pos = Stylet::Vector.angle_at(1.0 / 256 * win.count) * win.rect.h * 0.3
-  win.draw_circle(win.rect.center + pos, :vertex => 128, :radius => 64, :angle => pos.angle)
+  win.draw_polygon(win.rect.center + pos, :vertex => 128, :radius => 64, :angle => pos.angle)
 end
diff --git a/examples/0060_rotate.rb b/examples/0060_rotate.rb
index 2045c60..53ab05f 100644
--- a/examples/0060_rotate.rb
+++ b/examples/0060_rotate.rb
@@ -2,7 +2,7 @@
 #
 # Vector#rotate の確認
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "../lib/stylet"))
+require_relative "../lib/stylet"

 Stylet::Base.instance.title = "Vector#rotate系の二つのメソッドの確認"

diff --git a/examples/0070_draw_triangle.rb b/examples/0070_draw_triangle.rb
index bcfd90c..7218934 100644
--- a/examples/0070_draw_triangle.rb
+++ b/examples/0070_draw_triangle.rb
@@ -2,7 +2,7 @@
 #
 # 回転する三角形
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "../lib/stylet"))
+require_relative "../lib/stylet"
 Stylet::Base.instance.title = "回転する三角形の描画"
 Stylet::Base.main_loop do |win|
   win.draw_triangle(win.rect.center, :radius => 128, :angle => 1.0 / 256 * win.count)
diff --git a/examples/0080_shooting.rb b/examples/0080_shooting.rb
index f562a92..7e23531 100644
--- a/examples/0080_shooting.rb
+++ b/examples/0080_shooting.rb
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-require File.expand_path(File.join(File.dirname(__FILE__), "../lib/stylet"))
+require_relative "../lib/stylet"

 class GunShip
   include Stylet::Input::Base
diff --git a/examples/0090_parabora_triangle.rb b/examples/0090_parabora_triangle.rb
index 1c5d660..2fadc4e 100644
--- a/examples/0090_parabora_triangle.rb
+++ b/examples/0090_parabora_triangle.rb
@@ -2,7 +2,7 @@
 #
 # マウスの位置からZボタンで放物線を描く三角を表示
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class Ball
   def initialize(win, p0, speed, friction)
diff --git a/examples/0100_ice_hockey.rb b/examples/0100_ice_hockey.rb
index d0e0b6f..cf23b6d 100644
--- a/examples/0100_ice_hockey.rb
+++ b/examples/0100_ice_hockey.rb
@@ -2,7 +2,7 @@
 #
 # マウスで円をアイスホッケーの球のように動かすアルゴリズム
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 #
 # 円の中心
@@ -76,7 +76,7 @@ class IccHockeyBall
       @pos = _p
     end

-    @win.draw_circle(@pos, :radius => @body_radius, :vertex => 32)
+    @win.draw_polygon(@pos, :radius => @body_radius, :vertex => 32)
     @win.vputs @power
     @win.vputs @pos.distance_to(@win.mouse_vector)
     @win.vputs @speed
diff --git a/examples/0110_collision_block_vs_block.rb b/examples/0110_collision_block_vs_block.rb
index 969048f..615ec3a 100644
--- a/examples/0110_collision_block_vs_block.rb
+++ b/examples/0110_collision_block_vs_block.rb
@@ -2,7 +2,7 @@
 #
 # ブロックとブロックの当たり判定
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class Scene
   def initialize(win)
diff --git a/examples/0120_simple_circle_controll.rb b/examples/0120_simple_circle_controll.rb
index 8dd2573..f61d332 100644
--- a/examples/0120_simple_circle_controll.rb
+++ b/examples/0120_simple_circle_controll.rb
@@ -2,7 +2,7 @@
 #
 # 円の移動の定石
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class Scene
   def initialize(win)
@@ -32,7 +32,7 @@ class Scene
       end
     end

-    @win.draw_circle(@pA, :vertex => @vertex, :radius => @radius)
+    @win.draw_polygon(@pA, :vertex => @vertex, :radius => @radius)
     @win.draw_vector(@sA.scale(@radius), :origin => @pA)
   end

diff --git a/examples/0130_same_speed.rb b/examples/0130_same_speed.rb
index 1d86de6..c46ba62 100644
--- a/examples/0130_same_speed.rb
+++ b/examples/0130_same_speed.rb
@@ -2,7 +2,7 @@
 #
 # 円の移動の定石
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class Scene
   def initialize(win)
diff --git a/examples/0140_等速移動_uniform_velocity_rain.rb b/examples/0140_等速移動_uniform_velocity_rain.rb
index 2aca5ae..b88fbd3 100644
--- a/examples/0140_等速移動_uniform_velocity_rain.rb
+++ b/examples/0140_等速移動_uniform_velocity_rain.rb
@@ -4,7 +4,7 @@
 #
 #   いろんな多角形が落ちてくるだけ
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class Ball
   def initialize(win)
@@ -31,7 +31,7 @@ class Ball
       @win.objects.delete(self)
     end

-    @win.draw_circle(@pos, :radius => @radius, :vertex => @vertex, :angle => 1.0 / 256 * (@speed.length + @win.count) * @arrow)
+    @win.draw_polygon(@pos, :radius => @radius, :vertex => @vertex, :angle => 1.0 / 256 * (@speed.length + @win.count) * @arrow)
   end
 end

diff --git a/examples/0150_加速放物線_parabora_volcano.rb b/examples/0150_加速放物線_parabora_volcano.rb
index 8540cee..5036002 100644
--- a/examples/0150_加速放物線_parabora_volcano.rb
+++ b/examples/0150_加速放物線_parabora_volcano.rb
@@ -7,7 +7,7 @@
 # ・Cでマウスの位置にセット
 # ・Vで速度ベクトルの向きをマウスの向きへ
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class Ball
   def initialize(win)
@@ -71,7 +71,7 @@ class Ball
       @win.objects.delete(self)
     end

-    @win.draw_circle(@pos, :radius => @radius, :vertex => @vertex, :angle => 1.0 / 256 * (@speed.length + @win.count) * @arrow)
+    @win.draw_polygon(@pos, :radius => @radius, :vertex => @vertex, :angle => 1.0 / 256 * (@speed.length + @win.count) * @arrow)
   end
 end

diff --git a/examples/0160_俊敏移動_play_station_torne_menu_like.rb b/examples/0160_俊敏移動_play_station_torne_menu_like.rb
index d8a862c..11b538b 100644
--- a/examples/0160_俊敏移動_play_station_torne_menu_like.rb
+++ b/examples/0160_俊敏移動_play_station_torne_menu_like.rb
@@ -2,7 +2,7 @@
 #
 # PSPやPS3やトルネのインターフェイスでありがちなメニューの動き
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class Ball
   def initialize(win, index)
@@ -66,7 +66,7 @@ class Ball

     @mode_count += 1

-    @win.draw_circle(@pos, :radius => @radius, :vertex => @vertex, :angle => 1.0 / 256 * @win.count)
+    @win.draw_polygon(@pos, :radius => @radius, :vertex => @vertex, :angle => 1.0 / 256 * @win.count)
     @win.vputs @name, :vector => @pos
   end
 end
diff --git a/examples/0170_弓形移動_bezier_2.rb b/examples/0170_弓形移動_bezier_2.rb
index bc879f0..1bb9b9c 100644
--- a/examples/0170_弓形移動_bezier_2.rb
+++ b/examples/0170_弓形移動_bezier_2.rb
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-require File.expand_path(File.join(File.dirname(__FILE__), "bezier"))
+require_relative "bezier"

 class BezierUnit
   include BezierUnitBase
diff --git a/examples/0180_S字移動_bezier_3.rb b/examples/0180_S字移動_bezier_3.rb
index b59be08..da58e20 100644
--- a/examples/0180_S字移動_bezier_3.rb
+++ b/examples/0180_S字移動_bezier_3.rb
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-require File.expand_path(File.join(File.dirname(__FILE__), "bezier"))
+require_relative "bezier"

 class BezierUnit
   include BezierUnitBase
diff --git a/examples/0190_ぐねぐね移動_bezier_n.rb b/examples/0190_ぐねぐね移動_bezier_n.rb
index cbe263e..e6c58b5 100644
--- a/examples/0190_ぐねぐね移動_bezier_n.rb
+++ b/examples/0190_ぐねぐね移動_bezier_n.rb
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-require File.expand_path(File.join(File.dirname(__FILE__), "bezier"))
+require_relative "bezier"

 class BezierUnit
   include BezierUnitBase
diff --git a/examples/0200_円運動_circle_jet_coaster.rb b/examples/0200_円運動_circle_jet_coaster.rb
index bf70d79..9cf7f1c 100644
--- a/examples/0200_円運動_circle_jet_coaster.rb
+++ b/examples/0200_円運動_circle_jet_coaster.rb
@@ -2,7 +2,7 @@
 #
 # ギャラガの敵の動き
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class Ball
   def initialize(win, index)
@@ -14,7 +14,7 @@ class Ball
     p0 = pos_new(@win.count)      # 現在の位置を取得
     p1 = pos_new(@win.count.next) # 次のフレームの位置を取得
     dir = p0.angle_to(p1)          # 現在の位置から見て未来の角度を取得
-    @win.draw_circle(p0, :radius => 20, :vertex => 3, :angle => dir) # 次に進む方向に向けて三角を表示
+    @win.draw_polygon(p0, :radius => 20, :vertex => 3, :angle => dir) # 次に進む方向に向けて三角を表示
   end

   #
diff --git a/examples/0210_円を押すひっぱる_collision_circle_vs_circle_push_or_pull.rb b/examples/0210_円を押すひっぱる_collision_circle_vs_circle_push_or_pull.rb
index a954f41..53c78e5 100644
--- a/examples/0210_円を押すひっぱる_collision_circle_vs_circle_push_or_pull.rb
+++ b/examples/0210_円を押すひっぱる_collision_circle_vs_circle_push_or_pull.rb
@@ -2,7 +2,7 @@
 #
 # 円同士の当り判定(ベクトルを使った方法)
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class Ball
   def initialize(win, pos)
@@ -43,7 +43,7 @@ class Ball
     @pos = b

     @win.draw_line(@pos, @win.cursor)
-    @win.draw_circle(@pos, :radius => @radius, :vertex => 32)
+    @win.draw_polygon(@pos, :radius => @radius, :vertex => 32)
   end
 end

diff --git a/examples/0220_芋虫ゴム紐デモ_collision_demo_circle_worm.rb b/examples/0220_芋虫ゴム紐デモ_collision_demo_circle_worm.rb
index 4bfb493..a000ec0 100644
--- a/examples/0220_芋虫ゴム紐デモ_collision_demo_circle_worm.rb
+++ b/examples/0220_芋虫ゴム紐デモ_collision_demo_circle_worm.rb
@@ -2,7 +2,7 @@
 #
 # 芋虫・多関節・ゴム・紐
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class Joint
   attr_accessor :p0
@@ -47,7 +47,7 @@ class Joint

     # 胴体の表示
     if @win.body_display
-      @win.draw_circle(@p0, :radius => @win.length / 2, :vertex => 16)
+      @win.draw_polygon(@p0, :radius => @win.length / 2, :vertex => 16)
     end
   end
 end
diff --git a/examples/0230_振り子_swing.rb b/examples/0230_振り子_swing.rb
index 559e807..d05c391 100644
--- a/examples/0230_振り子_swing.rb
+++ b/examples/0230_振り子_swing.rb
@@ -2,7 +2,7 @@
 #
 # 振り子のアルゴリズム
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 #
 # ブランコのアルゴリズム
@@ -97,7 +97,7 @@ class Swing
     @win.draw_line(@p0, @pA)

     # 鉄球
-    @win.draw_circle(@pA, :radius => @ball_radius, :vertex => 16)
+    @win.draw_polygon(@pA, :radius => @ball_radius, :vertex => 16)

     # デバッグモード
     if @debug_mode || @win.button.btD.press?
@@ -119,7 +119,7 @@ class Swing
       rad90_line

       # 軌道の円周
-      @win.draw_circle(@p0, :radius => @radius, :vertex => 32)
+      @win.draw_polygon(@p0, :radius => @radius, :vertex => 32)

       # @win.draw_line(@pB, @pB + (@pA - @pB).scale(2))
     end
diff --git a/examples/0240_内積_inner_product.rb b/examples/0240_内積_inner_product.rb
index b9b82d8..abefa68 100644
--- a/examples/0240_内積_inner_product.rb
+++ b/examples/0240_内積_inner_product.rb
@@ -2,7 +2,7 @@
 #
 # 内積
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class Scene
   def initialize(win)
diff --git a/examples/0250_円と円の反射_collision_reflect_circle_vs_circle.rb b/examples/0250_円と円の反射_collision_reflect_circle_vs_circle.rb
index 7155203..b456a3e 100644
--- a/examples/0250_円と円の反射_collision_reflect_circle_vs_circle.rb
+++ b/examples/0250_円と円の反射_collision_reflect_circle_vs_circle.rb
@@ -15,7 +15,7 @@
 #   運動量保存の法則
 #   質量A * 衝突A + 質量B * 衝突B = 質量A * 反射A + 質量B * 反射B
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class Scene
   def initialize(win)
@@ -129,11 +129,11 @@ class Scene
       end
     end

-    @win.draw_circle(@pA, :vertex => @vertex, :radius => @a_radius)
+    @win.draw_polygon(@pA, :vertex => @vertex, :radius => @a_radius)
     @win.vputs "A(#{@am})", :vector => @pA
     @win.draw_vector(@sA.scale(@s_radius), :origin => @pA, :label => @sA.length)

-    @win.draw_circle(@pB, :vertex => @vertex, :radius => @b_radius)
+    @win.draw_polygon(@pB, :vertex => @vertex, :radius => @b_radius)
     @win.vputs "B(#{@bm})", :vector => @pB
     @win.draw_vector(@sB.scale(@s_radius), :origin => @pB, :label => @sB.length)

@@ -147,10 +147,10 @@ class Scene

       if @resp
         @pA2 = @pA + @sA.normalize.scale(@resp[:f0])
-        @win.draw_circle(@pA2, :vertex => @vertex, :radius => @a_radius)
+        @win.draw_polygon(@pA2, :vertex => @vertex, :radius => @a_radius)

         @pB2 = @pB + @sB.normalize.scale(@resp[:f0])
-        @win.draw_circle(@pB2, :vertex => @vertex, :radius => @b_radius)
+        @win.draw_polygon(@pB2, :vertex => @vertex, :radius => @b_radius)
       end
     end
   end
diff --git a/examples/0260_点と線分の交差判定_collision_ray_circle_vs_line.rb b/examples/0260_点と線分の交差判定_collision_ray_circle_vs_line.rb
index 693fee8..c650859 100644
--- a/examples/0260_点と線分の交差判定_collision_ray_circle_vs_line.rb
+++ b/examples/0260_点と線分の交差判定_collision_ray_circle_vs_line.rb
@@ -2,7 +2,7 @@
 #
 # 点と線分の交差判定と反射
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class Ray
   def initialize(win, p0)
@@ -192,7 +192,7 @@ class Ray
         @win.draw_triangle(@p0, :radius => @dot_radius, :angle => @vS.angle)
       else
         # 自機(円)の表示
-        @win.draw_circle(@p0, :radius => @radius, :vertex => @vertex, :angle => @vS.angle)
+        @win.draw_polygon(@p0, :radius => @radius, :vertex => @vertex, :angle => @vS.angle)
       end
       @win.vputs "p0", :vector => @p0

diff --git a/examples/0270_円と点の反射_collision_circle_vs_dot.rb b/examples/0270_円と点の反射_collision_circle_vs_dot.rb
index 5023fa3..f459ccf 100644
--- a/examples/0270_円と点の反射_collision_circle_vs_dot.rb
+++ b/examples/0270_円と点の反射_collision_circle_vs_dot.rb
@@ -2,7 +2,7 @@
 #
 # 円と点の反射
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class Circle
   def initialize(win)
@@ -27,7 +27,7 @@ class Circle
       end
     end

-    @win.draw_circle(@pos, :radius => @radius, :vertex => 32)
+    @win.draw_polygon(@pos, :radius => @radius, :vertex => 32)
     @win.vputs "Z:x++ X:x--"
   end
 end
diff --git a/examples/0280_円と円と線分の反射デモ_collision_demo.rb b/examples/0280_円と円と線分の反射デモ_collision_demo.rb
index 2f35bac..1180b78 100644
--- a/examples/0280_円と円と線分の反射デモ_collision_demo.rb
+++ b/examples/0280_円と円と線分の反射デモ_collision_demo.rb
@@ -2,7 +2,7 @@
 #
 # デモ - かごの中で球が転がある
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class Ball
   REFLECT_RATIO = 1.0 # 反射係数
@@ -232,7 +232,7 @@ class Ball
     @pos += @speed

     # 自機(円)の表示
-    @win.draw_circle(@pos, :radius => @radius, :vertex => @vertex, :angle => @speed.angle)
+    @win.draw_polygon(@pos, :radius => @radius, :vertex => @vertex, :angle => @speed.angle)
   end
 end

diff --git a/examples/bezier.rb b/examples/bezier.rb
index 622c3aa..b5bcbbf 100644
--- a/examples/bezier.rb
+++ b/examples/bezier.rb
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-

-require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
+require_relative "helper"

 class MovablePoint
   attr_reader :pos
@@ -41,9 +41,9 @@ class MovablePoint
     end

     if self == @unit.dragging_current
-      @win.draw_circle(@pos, :radius => @radius, :vertex => 32)
+      @win.draw_polygon(@pos, :radius => @radius, :vertex => 32)
     else
-      @win.draw_circle(@pos, :radius => 2)
+      @win.draw_polygon(@pos, :radius => 2)
     end
   end
 end
@@ -99,7 +99,7 @@ module BezierUnitBase
         # ○の表示
         pos = 0.5 + (Stylet::Fee.sin(@win.count / 256.0) * 0.5)
         xy = __bezier_point(pos)
-        @win.draw_circle(xy, :radius => 64, :vertex => 32)
+        @win.draw_polygon(xy, :radius => 64, :vertex => 32)
         @win.vputs(pos)
       else
         # △の表示で進んでいる方向を頂点にする
@@ -136,7 +136,7 @@ module BezierUnitBase
   end

   def mpoints_all
-    (0...@line_count.next).collect{|i|
+    @line_count.next.times.collect{|i|
       __bezier_point(1.0 / @line_count * i)
     }
   end
diff --git a/examples/helper.rb b/examples/helper.rb
index a841100..d4315e6 100644
--- a/examples/helper.rb
+++ b/examples/helper.rb
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-require File.expand_path(File.join(File.dirname(__FILE__), "../lib/stylet"))
+require_relative "../lib/stylet"

 # Stylet::Conf.update({
 #     # :screen_size      => [640, 480],
@@ -84,7 +84,7 @@ module Helper
       @objects.reject!{|e| e.respond_to?(:screen_out?) && e.screen_out?}

       if @cursor_display
-        draw_circle(@cursor, :radius => @cursor_radius, :vertex => @cursor_vertex, :angle => 1.0 / 64 * @count)
+        draw_polygon(@cursor, :radius => @cursor_radius, :vertex => @cursor_vertex, :angle => 1.0 / 64 * @count)
       end
     end
   end
diff --git a/lib/stylet.rb b/lib/stylet.rb
index 63e3ce3..587401d 100644
--- a/lib/stylet.rb
+++ b/lib/stylet.rb
@@ -1,5 +1,5 @@
-require File.expand_path(File.join(File.dirname(__FILE__), "stylet/base"))
-require File.expand_path(File.join(File.dirname(__FILE__), "stylet/input"))
+require_relative "stylet/base"
+require_relative "stylet/input"

 module Stylet
   VERSION = "0.0.1"
diff --git a/lib/stylet/assets/README.md b/lib/stylet/assets/README.md
deleted file mode 100644
index fb164f2..0000000
--- a/lib/stylet/assets/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-* famania2.6.otf [http://chiphead.jp/]()
-* orangeki.ttf [Orange Kid](http://www.larabiefonts.com/)
-* flappy\_for_famicom.ttf [http://www.jttk.zaq.ne.jp/babwp701/hpfont/font.html]()
diff --git a/lib/stylet/assets/README.org b/lib/stylet/assets/README.org
new file mode 100644
index 0000000..19ec0f5
--- /dev/null
+++ b/lib/stylet/assets/README.org
@@ -0,0 +1,4 @@
+* assets
+- famania2.6.otf http://chiphead.jp/
+- orangeki.ttf [Orange Kid] http://www.larabiefonts.com/
+- flappy_for_famicom.ttf http://www.jttk.zaq.ne.jp/babwp701/hpfont/font.html
diff --git a/lib/stylet/audio.rb b/lib/stylet/audio.rb
index 76ac7f7..7621f11 100644
--- a/lib/stylet/audio.rb
+++ b/lib/stylet/audio.rb
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-

-require File.expand_path(File.join(File.dirname(__FILE__), "config"))
-require File.expand_path(File.join(File.dirname(__FILE__), "logger"))
+require_relative "config"
+require_relative "logger"

 require "singleton"

@@ -153,7 +153,7 @@ module Stylet
 end

 if $0 == __FILE__
-  require File.expand_path(File.join(File.dirname(__FILE__), "../stylet"))
+  require_relative "../stylet"

   filename = File.expand_path(File.join(File.dirname(__FILE__), "assets/bgm.wav"))
   Stylet::Audio.instance.play(filename)
diff --git a/lib/stylet/base.rb b/lib/stylet/base.rb
index eede189..495d3a1 100644
--- a/lib/stylet/base.rb
+++ b/lib/stylet/base.rb
@@ -1,6 +1,5 @@
 # -*- coding: utf-8 -*-

-require "rubygems"
 require "sdl"
 require "singleton"
 require "pp"
@@ -9,35 +8,35 @@ require "pathname"
 require_relative "config"

 # 汎用ライブラリ
-require File.expand_path(File.join(File.dirname(__FILE__), "color"))
-require File.expand_path(File.join(File.dirname(__FILE__), "vsync_wait"))
-require File.expand_path(File.join(File.dirname(__FILE__), "check_fps"))
-require File.expand_path(File.join(File.dirname(__FILE__), "logger"))
-require File.expand_path(File.join(File.dirname(__FILE__), "vector"))
-require File.expand_path(File.join(File.dirname(__FILE__), "rect"))
-require File.expand_path(File.join(File.dirname(__FILE__), "fee"))
-require File.expand_path(File.join(File.dirname(__FILE__), "collision_support"))
-require File.expand_path(File.join(File.dirname(__FILE__), "etc"))
+require_relative "color"
+require_relative "vsync_wait"
+require_relative "check_fps"
+require_relative "logger"
+require_relative "vector"
+require_relative "rect"
+require_relative "fee"
+require_relative "collision_support"
+require_relative "etc"

 # 描画系
-require File.expand_path(File.join(File.dirname(__FILE__), "core"))
-require File.expand_path(File.join(File.dirname(__FILE__), "system_pause"))
-require File.expand_path(File.join(File.dirname(__FILE__), "cl_options"))
-require File.expand_path(File.join(File.dirname(__FILE__), "draw"))
-require File.expand_path(File.join(File.dirname(__FILE__), "font"))
+require_relative "core"
+require_relative "system_pause"
+require_relative "cl_options"
+require_relative "draw"
+require_relative "font"

 # 描画サポート
-require File.expand_path(File.join(File.dirname(__FILE__), "draw_support/circle"))
-require File.expand_path(File.join(File.dirname(__FILE__), "draw_support/polygon"))
-require File.expand_path(File.join(File.dirname(__FILE__), "draw_support/arrow"))
+require_relative "draw_support/circle"
+require_relative "draw_support/polygon"
+require_relative "draw_support/arrow"

 # 入力系
-require File.expand_path(File.join(File.dirname(__FILE__), "joystick"))
-require File.expand_path(File.join(File.dirname(__FILE__), "keyboard"))
-require File.expand_path(File.join(File.dirname(__FILE__), "mouse"))
+require_relative "joystick"
+require_relative "keyboard"
+require_relative "mouse"

 # オーディオ系
-require File.expand_path(File.join(File.dirname(__FILE__), "audio"))
+require_relative "audio"

 module Stylet
   #
@@ -47,9 +46,10 @@ module Stylet
     return @spec if @spec
     @spec ||= []
     @spec << "SGE" if sge_support?
-    @spec << "MPEG" if SDL.constants.include?("MPEG")
-    @spec << "Mixer" if SDL.constants.include?("Mixer")
-    @spec << "GL" if SDL.constants.include?("GL")
+    @spec << "MPEG" if SDL.constants.include?(:MPEG)
+    @spec << "Mixer" if SDL.constants.include?(:Mixer)
+    @spec << "GL" if SDL.constants.include?(:GL)
+    @spec
   end

   #
diff --git a/lib/stylet/cl_options.rb b/lib/stylet/cl_options.rb
index 511b6c2..904e585 100644
--- a/lib/stylet/cl_options.rb
+++ b/lib/stylet/cl_options.rb
@@ -23,7 +23,7 @@ module Stylet
 end

 if $0 == __FILE__
-  require File.expand_path(File.join(File.dirname(__FILE__), "../stylet"))
+  require_relative "../stylet"
   ARGV << "--shutdown=60"
   Stylet::Base.main_loop
 end
diff --git a/lib/stylet/collision_support.rb b/lib/stylet/collision_support.rb
index 5defff1..0b89e91 100644
--- a/lib/stylet/collision_support.rb
+++ b/lib/stylet/collision_support.rb
@@ -58,7 +58,7 @@ module Stylet

     # 長方形aのなかにbが含まれているか？
     def rect_include?(a, b)
-      if true &&
+      if true &&
           a.min_xi <= b.min_xi &&
           b.max_xi <= a.max_xi &&
           a.min_yi <= b.min_yi &&
diff --git a/lib/stylet/config.rb b/lib/stylet/config.rb
index 0fdfee6..f473ce3 100644
--- a/lib/stylet/config.rb
+++ b/lib/stylet/config.rb
@@ -36,6 +36,6 @@ module Stylet
 end

 if $0 == __FILE__
-  require File.expand_path(File.join(File.dirname(__FILE__), "../stylet"))
+  require_relative "../stylet"
   Stylet::Base.main_loop
 end
diff --git a/lib/stylet/draw.rb b/lib/stylet/draw.rb
index 09d9b26..e7b4789 100644
--- a/lib/stylet/draw.rb
+++ b/lib/stylet/draw.rb
@@ -170,6 +170,6 @@ module Stylet
 end

 if $0 == __FILE__
-  require File.expand_path(File.join(File.dirname(__FILE__), "../stylet"))
+  require_relative "../stylet"
   Stylet::Base.main_loop
 end
diff --git a/lib/stylet/draw_support/arrow.rb b/lib/stylet/draw_support/arrow.rb
index d601d2b..79faa85 100644
--- a/lib/stylet/draw_support/arrow.rb
+++ b/lib/stylet/draw_support/arrow.rb
@@ -49,7 +49,7 @@ module Stylet
 end

 if $0 == __FILE__
-  require File.expand_path(File.join(File.dirname(__FILE__), "../../stylet"))
+  require_relative "../../stylet"
   Stylet::Base.main_loop do |win|
     win.draw_arrow(win.rect.center, win.rect.center + Stylet::Vector.new(50, 50))
     win.draw_vector(Stylet::Vector.new(100, -100), :origin => win.rect.center)
diff --git a/lib/stylet/draw_support/circle.rb b/lib/stylet/draw_support/circle.rb
index 74a6963..8a31377 100644
--- a/lib/stylet/draw_support/circle.rb
+++ b/lib/stylet/draw_support/circle.rb
@@ -2,20 +2,20 @@
 module Stylet
   module DrawSupport
     #
-    # draw_circle(rect.center)
+    # 多角形の描画
     #
-    def draw_circle(p0, options = {})
+    def draw_polygon(p0, options = {})
       options = {
-        :radius => 64,
-        :vertex => 8,
-        :angle => Fee.r270,      # 開始地点
+        :radius => 64,       # 半径
+        :vertex => 8,        # n角形
+        :angle  => Fee.r270, # 開始地点
       }.merge(options)

       raise "options[:vertex] is not Integer" unless options[:vertex].kind_of? Integer
       raise "options[:vertex] >= 1" if options[:vertex].to_i.zero?
-      raise if options[:vertex].zero?
+      raise "zero vector" if options[:vertex].zero?

-      points = (0...options[:vertex]).collect{|i|
+      points = options[:vertex].times.collect{|i|
         a = options[:angle] + 1.0 * i / options[:vertex]
         p0 + Vector.angle_at(a) * options[:radius]
       }
@@ -23,30 +23,26 @@ module Stylet
     end

     #
-    # 三角形の表示
+    # 三角形の描画
     #
     def draw_triangle(p0, options = {})
-      options = {
-        :vertex => 3,
-      }.merge(options)
-      draw_circle(p0, options)
+      draw_polygon(p0, {:vertex => 3}.merge(options))
     end

     #
-    # 正方形の表示
+    # 正方形の描画
     #
     def draw_square(p0, options = {})
-      options = {
-        :vertex => 4,
-      }.merge(options)
-      draw_circle(p0, options)
+      draw_polygon(p0, {:vertex => 4}.merge(options))
     end
   end
 end

 if $0 == __FILE__
-  require File.expand_path(File.join(File.dirname(__FILE__), "../../stylet"))
+  require_relative "../../stylet"
   Stylet::Base.main_loop do |win|
-    win.draw_circle(win.rect.center)
+    win.draw_polygon(win.rect.center)
+    # win.draw_triangle(win.rect.center)
+    # win.draw_square(win.rect.center)
   end
 end
diff --git a/lib/stylet/draw_support/polygon.rb b/lib/stylet/draw_support/polygon.rb
index 137763e..4578f29 100644
--- a/lib/stylet/draw_support/polygon.rb
+++ b/lib/stylet/draw_support/polygon.rb
@@ -17,7 +17,7 @@ module Stylet
 end

 if $0 == __FILE__
-  require File.expand_path(File.join(File.dirname(__FILE__), "../../stylet"))
+  require_relative "../../stylet"
   Stylet::Base.main_loop do |win|
     points = Array.new(3){Stylet::Vector.new(rand(win.rect.w), rand(win.rect.h))}
     win.draw_polygon(points)
diff --git a/lib/stylet/font.rb b/lib/stylet/font.rb
index d331193..24a977a 100644
--- a/lib/stylet/font.rb
+++ b/lib/stylet/font.rb
@@ -61,7 +61,7 @@ module Stylet
 end

 if $0 == __FILE__
-  require File.expand_path(File.join(File.dirname(__FILE__), "../stylet"))
+  require_relative "../stylet"
   Stylet::Conf.update(:font_name => "VeraMono.ttf", :font_size => 20)
   Stylet::Base.main_loop do |win|
     25.times{|i|win.vputs [i, ("A".."Z").to_a.join].join(" ")}
diff --git a/lib/stylet/input.rb b/lib/stylet/input.rb
index 9aef601..aec8ac6 100644
--- a/lib/stylet/input.rb
+++ b/lib/stylet/input.rb
@@ -4,7 +4,7 @@
 # ・入力=キーボードを連想しがちだが入力は思考ルーチンと考える
 # ・キーボード関連がでてくるのは思考ルーチンの省略するためものも
 #
-require File.expand_path(File.join(File.dirname(__FILE__), "input/support"))
-require File.expand_path(File.join(File.dirname(__FILE__), "input/key_one"))
-require File.expand_path(File.join(File.dirname(__FILE__), "input/base"))
-require File.expand_path(File.join(File.dirname(__FILE__), "input/hardware_bindings"))
+require_relative "input/support"
+require_relative "input/key_one"
+require_relative "input/base"
+require_relative "input/hardware_bindings"
diff --git a/lib/stylet/input/base.rb b/lib/stylet/input/base.rb
index df2f89d..da78a05 100644
--- a/lib/stylet/input/base.rb
+++ b/lib/stylet/input/base.rb
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-

-require File.expand_path(File.join(File.dirname(__FILE__), "../axis_support"))
+require_relative "../axis_support"

 module Stylet
   module Input
diff --git a/lib/stylet/joystick.rb b/lib/stylet/joystick.rb
index 5e5e5c3..a89bf99 100644
--- a/lib/stylet/joystick.rb
+++ b/lib/stylet/joystick.rb
@@ -1,4 +1,4 @@
-require File.expand_path(File.join(File.dirname(__FILE__), "joystick_adapter"))
+require_relative "joystick_adapter"

 module Stylet
   module Joystick
@@ -12,7 +12,7 @@ module Stylet
     def before_main_loop
       super if defined? super
       logger.debug "SDL::Joystick.num: #{SDL::Joystick.num}" if logger
-      @joys = (0...SDL::Joystick.num).collect{|i|JoystickAdapter.create(SDL::Joystick.open(i))}
+      @joys = SDL::Joystick.num.times.collect{|i|JoystickAdapter.create(SDL::Joystick.open(i))}
     end

     def polling
diff --git a/lib/stylet/joystick_adapter.rb b/lib/stylet/joystick_adapter.rb
index 864e5d0..a1d3947 100644
--- a/lib/stylet/joystick_adapter.rb
+++ b/lib/stylet/joystick_adapter.rb
@@ -12,7 +12,7 @@ module Stylet
       joystick_name = SDL::Joystick.index_name(object.index).strip
       p [object.index, joystick_name]
       driver_name = "#{adapters[joystick_name]}_adapter"
-      require File.expand_path(File.join(File.dirname(__FILE__), "joystick_adapters/#{driver_name}"))
+      require_relative "joystick_adapters/#{driver_name}"
       "Stylet::#{driver_name.classify}".constantize.new(object)
     end

@@ -90,7 +90,7 @@ module Stylet
     # end

     def button_str
-      (0...@object.num_buttons).collect{|index|
+      @object.num_buttons.times.collect{|index|
         if @object.button(index)
           "#{index}"
         end
@@ -116,6 +116,6 @@ module Stylet
 end

 if $0 == __FILE__
-  require File.expand_path(File.join(File.dirname(__FILE__), "../stylet"))
+  require_relative "../stylet"
   Stylet::Base.main_loop
 end
diff --git a/lib/stylet/mouse.rb b/lib/stylet/mouse.rb
index 432341d..44ed7bf 100644
--- a/lib/stylet/mouse.rb
+++ b/lib/stylet/mouse.rb
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-require File.expand_path(File.join(File.dirname(__FILE__), "vector"))
+require_relative "vector"

 module Stylet
   module Mouse
@@ -40,7 +40,7 @@ module Stylet
 end

 if $0 == __FILE__
-  require File.expand_path(File.join(File.dirname(__FILE__), "../stylet"))
+  require_relative "../stylet"
   Stylet::Base.main_loop do |win|
     win.vputs "start_mouse_vector: #{win.start_mouse_vector.to_a.inspect}"
     win.vputs "before_mouse_vector: #{win.before_mouse_vector.to_a.inspect}"
diff --git a/lib/stylet/rect.rb b/lib/stylet/rect.rb
index 31282d7..338bf83 100644
--- a/lib/stylet/rect.rb
+++ b/lib/stylet/rect.rb
@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-require File.expand_path(File.join(File.dirname(__FILE__), "vector"))
+require_relative "vector"

 module Stylet
   class Rect < Vector
diff --git a/lib/stylet/system_pause.rb b/lib/stylet/system_pause.rb
index 008714f..e944c04 100644
--- a/lib/stylet/system_pause.rb
+++ b/lib/stylet/system_pause.rb
@@ -22,6 +22,6 @@ module Stylet
 end

 if $0 == __FILE__
-  require File.expand_path(File.join(File.dirname(__FILE__), "../stylet"))
+  require_relative "../stylet"
   Stylet::Base.main_loop
 end
diff --git a/spec/vsync_wait_spec.rb b/spec/vsync_wait_spec.rb
index b3ee45c..db1a9af 100644
--- a/spec/vsync_wait_spec.rb
+++ b/spec/vsync_wait_spec.rb
@@ -10,7 +10,7 @@ describe Stylet::VSyncWait do
   it "一秒を二回待つ" do
     t = Time.now
     x = Stylet::VSyncWait.new(@frame_count)
-    resp = (0...@count).collect{|i|
+    resp = @count.times.collect{|i|
       [i, Time.now].tap{x.wait}
     }
     t = Time.now - t
[from now] 2013/01/06 16:38:19

diff --git a/.gitattributes b/.gitattributes
deleted file mode 100644
index ad169d3..0000000
--- a/.gitattributes
+++ /dev/null
@@ -1,5 +0,0 @@
-*.wav diff=exif
-*.png diff=exif
-*.gif diff=exif
-*.jpg diff=exif
-*.bmp diff=exif
diff --git a/.gitignore b/.gitignore
index 8da6b40..74ab2ae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,15 +1,2 @@
-ChangeLog
-*.db
-*.log
-/doc/app
-/_data
-.picasa.ini
-TAGS
-*.bmp
-*.mp3
-*.mp4
-*.mpg
-*.mpeg
-*.wav
-_*
 /README.html
+/Gemfile.lock
diff --git a/Gemfile b/Gemfile
index 611eb3e..cfcc06f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,4 +1,5 @@
 source :rubygems
+gemspec

 gem "activesupport"
 gem "rsdl", ">= 0.1.4"
@@ -8,3 +9,6 @@ gem "i18n"
 group :test do
   gem "rspec"
 end
+
+gem "tapp"
+gem "pry-debugger"
diff --git a/Gemfile.lock b/Gemfile.lock
deleted file mode 100644
index c06f325..0000000
--- a/Gemfile.lock
+++ /dev/null
@@ -1,29 +0,0 @@
-GEM
-  remote: http://rubygems.org/
-  specs:
-    activesupport (3.2.6)
-      i18n (~> 0.6)
-      multi_json (~> 1.0)
-    diff-lcs (1.1.3)
-    i18n (0.6.0)
-    multi_json (1.3.6)
-    rsdl (0.1.4)
-    rspec (2.11.0)
-      rspec-core (~> 2.11.0)
-      rspec-expectations (~> 2.11.0)
-      rspec-mocks (~> 2.11.0)
-    rspec-core (2.11.1)
-    rspec-expectations (2.11.1)
-      diff-lcs (~> 1.1.3)
-    rspec-mocks (2.11.1)
-    rubysdl (2.1.2)
-
-PLATFORMS
-  ruby
-
-DEPENDENCIES
-  activesupport
-  i18n
-  rsdl (>= 0.1.4)
-  rspec
-  rubysdl (>= 2.1.2)
diff --git a/README.org b/README.org
index 0b1c609..a58aac8 100644
--- a/README.org
+++ b/README.org
@@ -1,210 +1,185 @@
-* 物理運動アルゴリズムのお勉強用Ruby/SDLラッパーライブラリ
+#+OPTIONS: toc:nil num:nil author:nil creator:nil \n:nil |:t
+#+OPTIONS: @:t ::t ^:t -:t f:t *:t <:t

-** 簡単なRuby/SDL環境の作り方(for Mac OS X)
+* 物理シミュレーション覚書

-   brew uninstall sdl sdl_image sdl_ttf sdl_mixer sge-manualcompile
-   gem uninstall -x rubysdl rsdl
+** セットアップ手順

-   brew install sdl sdl_image sdl_ttf sdl_mixer
-   brew install https://raw.github.com/gist/3115276/719f284d6e340487dba6ef3e5beb7b7a4098414f/sge-manualcompile.rb
-   brew link sge-manualcompile
-   gem install rubysdl rsdl
+   Homebrew を最新に

-   # 確認。すべて true になればOK
-   ruby -r sdl -e 'p [:sge, SDL.respond_to?(:autoLock)]'
-   ruby -r sdl -e 'p [:mixer, SDL.constants.include?(:Mixer)]'
-   ruby -r sdl -e 'p [:ttf, SDL.constants.include?(:TTF)]'
+   : (cd /usr/local && git reset --hard origin/master && brew update)

-   ※ Mac OS X Lionにsgeを入れる #Ruby #SDL - Qiita http://qiita.com/items/f52daed19fa0198121b5 参考
+   各種ライブラリをいったんアンインストールしてからインストール

-** Macのportで入れる場合
+   : brew uninstall sdl sdl_gfx sdl_image sdl_mixer sdl_ttf
+   : brew install sdl sdl_gfx sdl_image sdl_mixer sdl_ttf
+   :
+   : brew uninstall sge-manualcompile
+   : brew install https://raw.github.com/gist/3115276/719f284d6e340487dba6ef3e5beb7b7a4098414f/sge-manualcompile.rb
+   : brew link --overwrite sge-manualcompile
+   :
+   : gem uninstall -axI rubysdl rsdl
+   : gem install rubysdl rsdl

-   sudo port install libsdl libsdl_ttf libsdl_sound libsdl_pango libsdl_mixer libsdl_image rb-opengl
+   ※ Mac OS X Lionにsgeを入れる http://qiita.com/items/f52daed19fa0198121b5 を参考にしました

-   # sge030809.tar.gz をダウンロードして ~/Downloads/sge030809 に展開。
-   # http://coderepos.org/share/changeset/10163 から *.patch をダウンロードし ~/Downloads/sge030809 にコピー。
+   すべて true になれば次へ

-   $ cd ~/Downloads/sge030809
-   $ patch -p1 < Makefile.conf.patch
-   $ patch -p1 < Makefile.patch
-   $ make
-   $ sudo make install
+   : ruby -r sdl -e 'p [:sge, SDL.respond_to?(:autoLock)]'
+   : ruby -r sdl -e 'p [:mixer, SDL.constants.include?(:Mixer)]'
+   : ruby -r sdl -e 'p [:ttf, SDL.constants.include?(:TTF)]'

-   gem install rubysdl rsdl
+   ウィンドウ表示確認

-   Macの場合 ruby からではなく rsdl から実行する
+   : rsdl -r sdl -e 'SDL.init(SDL::INIT_EVERYTHING); SDL.set_video_mode(640, 480, 16, SDL::SWSURFACE); sleep(1)'

-** Hello, world の実行方法
+   Hello, World. 確認([q]で終了)

-    $ cat hello.rb
-    require "stylet"
-    Stylet::Base.main_loop do |win|
-      win.vputs "Hello, world."
-    end
-
-    $ bundle exec rsdl hello.rb
-    [q]で終了
-
-** サンプルの一括動作テスト方法
-
-    $ cd examples
-    $ ruby test_all.rb
+   : rsdl -e 'require "stylet"; Stylet::Base.main_loop{|win|win.vputs "Hello, world."}'

 * TIPS

-** 速度ベクトルの向きを取得するには？
+** 速度ベクトルの向き取得

-    speed.angle
+   : speed.angle

-** 速度ベクトルを45度傾けるには？
+** 速度ベクトルを45度傾ける

-    speed + Stylet::Vector.angle_at(Stylet::Fee.r45) * speed.length
+   : speed + Stylet::Vector.angle_at(Stylet::Fee.r45) * speed.length
+   :
+   : Stylet::Vector.angle_at(speed.angle + Stylet::Fee.r45) * speed.length
+   :
+   : speed.rotate(Stylet::Fee.r45)
+   :
+   : speed.rotate2(Stylet::Fee.r45)

-    Stylet::Vector.angle_at(speed.angle + Stylet::Fee.r45) * speed.length
+** p0の速度ベクトルをマウスの方向に設定

-    speed.rotate(Stylet::Fee.r45)
+   : speed = Stylet::Vector.angle_at(p0.angle_to(win.mouse_vector)) * speed.length

-    speed.rotate2(Stylet::Fee.r45)
+** 円の速度制限

-** p0の速度ベクトルをマウスの方向に設定するには？
+   円が線から飛び出さないようにするときに使う

-    speed = Stylet::Vector.angle_at(p0.angle_to(win.mouse_vector)) * speed.length
+   : if speed.length > radius
+   :   speed = speed.normalize.scale(radius)
+   : end

-** 円の速度制限をするには？(円が線から飛び出さないようにするときに使う)
+** 線分ABの中央の位置を取得

-    if speed.length > radius
-      speed = speed.normalize.scale(radius)
-    end
+   : half_ab = pA + Stylet::Vector.angle_at(pA.angle_to(pB)) * (pA.distance_to(pB) / 2)

-** 線分ABの中央の位置を取得するには？
+   : Vector.pos_vector_rate(pA, pB, 0.5)

-    half_ab = pA + Stylet::Vector.angle_at(pA.angle_to(pB)) * (pA.distance_to(pB) / 2)
+** 円(c,r)が点(dot)にめりこんだとき、点(dot)から円を押し出す

-    Vector.pos_vector_rate(pA, pB, 0.5)
+   悪い例

-** 円(c,r)が点(dot)にめりこんだとき、点(dot)から円を押し出すには？
+   : if c.distance_to(dot) < r
+   :   c = dot + Stylet::Vector.angle_at(dot.angle_to(c)) * r
+   : end

-*** 悪い例
+   良い例

-    if c.distance_to(dot) < r
-      c = dot + Stylet::Vector.angle_at(dot.angle_to(c)) * r
-    end
+   : diff = c - dot
+   : rdiff = diff.length - r
+   : if rdiff > 0
+   :   # c = dot + diff.normalize * r # ドットから押す場合(ドットが釘ならこれでもよい)
+   :   c += diff.normalize * rdiff
+   : end

-*** 良い例
+** 円Aと円Bをお互い離す

-    diff = c - dot
-    rdiff = diff.length - r
-    if rdiff > 0
-      # c = dot + diff.normalize * r # ドットから押す場合(ドットが釘ならこれでもよい)
-      c += diff.normalize * rdiff
-    end
+   跳ね返り処理は別

-** 円Aと円Bをお互い離すには？(跳ね返り処理は別)
+   : diff = b - a
+   : rdiff = r * 2 - diff.length
+   : if rdiff > 0
+   :   a -= diff.normalize * rdiff / 2
+   :   b += diff.normalize * rdiff / 2
+   : end

-    diff = b - a
-    rdiff = r * 2 - diff.length
-    if rdiff > 0
-      a -= diff.normalize * rdiff / 2
-      b += diff.normalize * rdiff / 2
-    end
+** 固定点Aに円(p0,r)がめり込んでいたらAから跳ね返す

-**  固定点Aに円(p0,r)がめり込んでいたらAから跳ね返すには？
+   : diff = p0 - pA
+   : if diff.length > 0
+   :   if diff.length < r
+   :     p0 = pA + diff.normalize.scale(r)          # めりこみ解消
+   :     speed = diff.normalize.scale(speed.length) # 跳ね返す
+   :   end
+   : end

-    diff = p0 - pA
-    if diff.length > 0
-      if diff.length < r
-        p0 = pA + diff.normalize.scale(r)          # めりこみ解消
-        speed = diff.normalize.scale(speed.length) # 跳ね返す
-      end
-    end
+** 円Aと円Bが衝突してBからAを押したり引いたりする

-** 円Aと円Bが衝突してBからAを押したり引いたりするには？(Bは動かない。また両方跳ね返らない。Aは除けるだけ)
+   Bは動かない。また両方跳ね返らない。Aは除けるだけ

-    r2 = ar + br
-    if a != b
-      diff = b - a
-      rdiff = r2 - diff.length
-      # 押す場合
-      if rdiff > 0
-        # a = b + diff.normalize * r2  # Bを基点に押し出す(1)
-        b += diff.normalize * rdiff    # Aを基点に押し出す(2)
-      end
-      # 引く場合
-      if rdiff < 0
-        # (1) or (2) どちらでも
-      end
-    end
+   : r2 = ar + br
+   : if a != b
+   :   diff = b - a
+   :   rdiff = r2 - diff.length
+   :   # 押す場合
+   :   if rdiff > 0
+   :     # a = b + diff.normalize * r2  # Bを基点に押し出す(1)
+   :     b += diff.normalize * rdiff    # Aを基点に押し出す(2)
+   :   end
+   :   # 引く場合
+   :   if rdiff < 0
+   :     # (1) or (2) どちらでも
+   :   end
+   : end

 ** 正規化とは斜めの辺の長さを 1.0 にすること

-    v.normalize.length #=> 1.0
-
-** A B C D ボタンとカーソルで操作できるとき物体(pA)と速度(speed)をコントロールするときの定石は？
-
-    # AとBで速度ベクトルの反映
-    @pA += @speed.scale(@win.button.btA.repeat_0or1) + @speed.scale(-@win.button.btB.repeat_0or1)
-    # @pA += @speed.scale(@win.button.btA.repeat) + @speed.scale(-@win.button.btB.repeat) # 加速したいとき
-
-    # Cボタンおしっぱなし + マウスで自機位置移動
-    if @win.button.btC.press?
-      @pA = @win.cursor.clone
-    end
+   : v.normalize.length # => 1.0

-    # Dボタンおしっぱなし + マウスで自機角度変更
-    if @win.button.btD.press?
-      if @win.cursor != @pA
-        # @speed = Stylet::Vector.angle_at(@pA.angle_to(@win.cursor)) * @speed.radius # ← よくある間違い
-        @speed = (@win.cursor - @pA).normalize * @speed.length # @speed.length の時点で桁溢れで削れるのが嫌なら length.round とする手もあり
-      end
-    end
+** A B C D ボタンとカーソルで操作できるとき物体(pA)と速度(speed)をコントロールするときの定石

-** 円が完全に重なっている場合、ランダムに引き離す定石
+   : # AとBで速度ベクトルの反映
+   : @pA += @speed.scale(@win.button.btA.repeat_0or1) + @speed.scale(-@win.button.btB.repeat_0or1)
+   : # @pA += @speed.scale(@win.button.btA.repeat) + @speed.scale(-@win.button.btB.repeat) # 加速したいとき
+   :
+   : # Cボタンおしっぱなし + マウスで自機位置移動
+   : if @win.button.btC.press?
+   :   @pA = @win.cursor.clone
+   : end
+   :
+   : # Dボタンおしっぱなし + マウスで自機角度変更
+   : if @win.button.btD.press?
+   :   if @win.cursor != @pA
+   :     # @speed = Stylet::Vector.angle_at(@pA.angle_to(@win.cursor)) * @speed.radius # ← よくある間違い
+   :     @speed = (@win.cursor - @pA).normalize * @speed.length # @speed.length の時点で桁溢れで削れるのが嫌なら length.round とする手もあり
+   :   end
+   : end

-    diff = a - b
-    if diff.length.zero?
-      arrow = Stylet::Vector.nonzero_random_new
-      a -= arrow * ar
-      b += arrow * br
-    end
+** 円が完全に重なっている場合、ランダムに引き離す

-** 同時押しをシミューレートするには？
+   : diff = a - b
+   : if diff.length.zero?
+   :   arrow = Stylet::Vector.nonzero_random_new
+   :   a -= arrow * ar
+   :   b += arrow * br
+   : end

-    # A:←A S:←B D:→A F:→B
-    @axis.left  << (SDL::Key.press?(SDL::Key::A) | SDL::Key.press?(SDL::Key::S))
-    @axis.right << (SDL::Key.press?(SDL::Key::D) | SDL::Key.press?(SDL::Key::F))
-    @button.btA << (SDL::Key.press?(SDL::Key::A) | SDL::Key.press?(SDL::Key::D))
-    @button.btB << (SDL::Key.press?(SDL::Key::S) | SDL::Key.press?(SDL::Key::F))
+** 同時押しシミュレート

-** 内積を取得するには？
+   : # A:←A S:←B D:→A F:→B
+   : @axis.left  << (SDL::Key.press?(SDL::Key::A) | SDL::Key.press?(SDL::Key::S))
+   : @axis.right << (SDL::Key.press?(SDL::Key::D) | SDL::Key.press?(SDL::Key::F))
+   : @button.btA << (SDL::Key.press?(SDL::Key::A) | SDL::Key.press?(SDL::Key::D))
+   : @button.btB << (SDL::Key.press?(SDL::Key::S) | SDL::Key.press?(SDL::Key::F))

-    v = Stylet::Vector.inner_product(a, b)
-    #  1. ←← or →→ 正 (0.0 < v)   お互いだいたい同じ方向を向いている
-    #  2. →←         負 (v   < 0.0) お互いだいたい逆の方向を向いている
-    #  3. →↓ →↑    零 (0.0)       お互いが直角の関係
+** 内積の取得

-* TODO
+   : v = Stylet::Vector.inner_product(a, b)

-- x1, y1 = points[i % points.size] は cons に置き換えれる
+   1. ←← or →→ 正 (0.0 < v)   お互いだいたい同じ方向を向いている
+   2. →←         負 (v   < 0.0) お互いだいたい逆の方向を向いている
+   3. →↓ →↑    零 (0.0)       お互いが直角の関係

 * 参考URL

-- Flashゲーム講座&アクションスクリプトサンプル集 http://hakuhin.jp/as.html
-- 基礎の基礎編その１ 内積と外積の使い方 http://marupeke296.com/COL_Basic_No1_InnerAndOuterProduct.html
-- 内積が角度になる証明 http://marupeke296.com/COL_Basic_No1_DotProof.html
-- 衝突判定編 http://marupeke296.com/COL_main.html
-- 反射ベクトルと壁ずりベクトル http://marupeke296.com/COL_Basic_No5_WallVector.html
-
-#+TITLE:     Stylet - Ruby/SDLラッパーライブラリ
-#+AUTHOR:    akicho8
-#+EMAIL:     akicho8@gmail.com
-#+DATE:      2012-07-21 土
-#+DESCRIPTION:
-#+KEYWORDS:
-#+LANGUAGE:  ja
-#+OPTIONS:   H:3 num:t toc:t \n:nil @:t ::nil |:t ^:nil -:nil f:t *:t <:t
-#+OPTIONS:   TeX:nil LaTeX:nil skip:nil d:nil todo:t pri:nil tags:not-in-toc
-#+INFOJS_OPT: view:nil toc:nil ltoc:t mouse:underline buttons:0 path:http://orgmode.org/org-info.js
-#+EXPORT_SELECT_TAGS: export
-#+EXPORT_EXCLUDE_TAGS: noexport
-#+LINK_UP:
-#+LINK_HOME:
+  - Flashゲーム講座&アクションスクリプトサンプル集 http://hakuhin.jp/as.html
+  - 基礎の基礎編その１ 内積と外積の使い方 http://marupeke296.com/COL_Basic_No1_InnerAndOuterProduct.html
+  - 内積が角度になる証明 http://marupeke296.com/COL_Basic_No1_DotProof.html
+  - 衝突判定編 http://marupeke296.com/COL_main.html
+  - 反射ベクトルと壁ずりベクトル http://marupeke296.com/COL_Basic_No5_WallVector.html
diff --git a/examples/0040_draw_circle.rb b/examples/0040_draw_circle.rb
index 6e9b33f..b3e2c93 100644
--- a/examples/0040_draw_circle.rb
+++ b/examples/0040_draw_circle.rb
@@ -6,5 +6,5 @@ require_relative "../lib/stylet"

 Stylet::Base.instance.title = "円の描画"
 Stylet::Base.main_loop do |win|
-  win.draw_polygon(win.rect.center, :vertex => 256)
+  win.draw_circle(win.rect.center, :vertex => 256)
 end
diff --git a/examples/0050_circle_on_circle.rb b/examples/0050_circle_on_circle.rb
index db58f69..17154a8 100644
--- a/examples/0050_circle_on_circle.rb
+++ b/examples/0050_circle_on_circle.rb
@@ -7,5 +7,5 @@ require_relative "../lib/stylet"
 Stylet::Base.instance.title = "円上を動く円"
 Stylet::Base.main_loop do |win|
   pos = Stylet::Vector.angle_at(1.0 / 256 * win.count) * win.rect.h * 0.3
-  win.draw_polygon(win.rect.center + pos, :vertex => 128, :radius => 64, :angle => pos.angle)
+  win.draw_circle(win.rect.center + pos, :vertex => 128, :radius => 64, :angle => pos.angle)
 end
diff --git a/examples/0100_ice_hockey.rb b/examples/0100_ice_hockey.rb
index cf23b6d..2c0ed10 100644
--- a/examples/0100_ice_hockey.rb
+++ b/examples/0100_ice_hockey.rb
@@ -76,7 +76,7 @@ class IccHockeyBall
       @pos = _p
     end

-    @win.draw_polygon(@pos, :radius => @body_radius, :vertex => 32)
+    @win.draw_circle(@pos, :radius => @body_radius, :vertex => 32)
     @win.vputs @power
     @win.vputs @pos.distance_to(@win.mouse_vector)
     @win.vputs @speed
diff --git a/examples/0120_simple_circle_controll.rb b/examples/0120_simple_circle_controll.rb
index f61d332..05f57af 100644
--- a/examples/0120_simple_circle_controll.rb
+++ b/examples/0120_simple_circle_controll.rb
@@ -32,7 +32,7 @@ class Scene
       end
     end

-    @win.draw_polygon(@pA, :vertex => @vertex, :radius => @radius)
+    @win.draw_circle(@pA, :vertex => @vertex, :radius => @radius)
     @win.draw_vector(@sA.scale(@radius), :origin => @pA)
   end

diff --git a/examples/0140_等速移動_uniform_velocity_rain.rb b/examples/0140_等速移動_uniform_velocity_rain.rb
index b88fbd3..aa2065f 100644
--- a/examples/0140_等速移動_uniform_velocity_rain.rb
+++ b/examples/0140_等速移動_uniform_velocity_rain.rb
@@ -31,7 +31,7 @@ class Ball
       @win.objects.delete(self)
     end

-    @win.draw_polygon(@pos, :radius => @radius, :vertex => @vertex, :angle => 1.0 / 256 * (@speed.length + @win.count) * @arrow)
+    @win.draw_circle(@pos, :radius => @radius, :vertex => @vertex, :angle => 1.0 / 256 * (@speed.length + @win.count) * @arrow)
   end
 end

diff --git a/examples/0150_加速放物線_parabora_volcano.rb b/examples/0150_加速放物線_parabora_volcano.rb
index 5036002..c8ce01f 100644
--- a/examples/0150_加速放物線_parabora_volcano.rb
+++ b/examples/0150_加速放物線_parabora_volcano.rb
@@ -71,7 +71,7 @@ class Ball
       @win.objects.delete(self)
     end

-    @win.draw_polygon(@pos, :radius => @radius, :vertex => @vertex, :angle => 1.0 / 256 * (@speed.length + @win.count) * @arrow)
+    @win.draw_circle(@pos, :radius => @radius, :vertex => @vertex, :angle => 1.0 / 256 * (@speed.length + @win.count) * @arrow)
   end
 end

diff --git a/examples/0160_俊敏移動_play_station_torne_menu_like.rb b/examples/0160_俊敏移動_play_station_torne_menu_like.rb
index 11b538b..4ee5cdf 100644
--- a/examples/0160_俊敏移動_play_station_torne_menu_like.rb
+++ b/examples/0160_俊敏移動_play_station_torne_menu_like.rb
@@ -66,7 +66,7 @@ class Ball

     @mode_count += 1

-    @win.draw_polygon(@pos, :radius => @radius, :vertex => @vertex, :angle => 1.0 / 256 * @win.count)
+    @win.draw_circle(@pos, :radius => @radius, :vertex => @vertex, :angle => 1.0 / 256 * @win.count)
     @win.vputs @name, :vector => @pos
   end
 end
diff --git a/examples/0190_ぐねぐね移動_bezier_n.rb b/examples/0190_ぐねぐね移動_bezier_n.rb
new file mode 100644
index 0000000..e6c58b5
--- /dev/null
+++ b/examples/0190_ぐねぐね移動_bezier_n.rb
@@ -0,0 +1,70 @@
+# -*- coding: utf-8 -*-
+require_relative "bezier"
+
+class BezierUnit
+  include BezierUnitBase
+
+  def setup
+    case true
+    when true
+      # 横に配置
+      n = 2
+      @mpoints += Array.new(n + 1){|i|
+        x = (@win.rect.width * 0.1) + ((@win.rect.width * 0.8) / n * i)
+        y = @win.rect.hy
+        MovablePoint.new(self, Stylet::Vector.new(x, y))
+      }
+    when true
+      # 円状に配置
+      n = 5
+      r = hy * 0.9
+      @mpoints += Array.new(n){|i|
+        MovablePoint.new(self, @win.rect.center + Stylet::Vector.angle_at(1.0 / n * i).scale(r))
+      }
+    end
+  end
+
+  # N次ベジェ曲線
+  #
+  #         p1  p2  p3  p4
+  #   p0 ------------------- p5
+  #
+  #   用途
+  #   ・めちゃくちゃ激しく曲げたい
+  #   ・終了座標を必ず通る必要がある
+  #   ・どんだけ計算量がかかってもよい
+  #   ・クロスしまくりたい
+  #
+  def bezier_point(points, d)
+    o = Stylet::Vector.new(0, 0)
+
+    points.size.times{|i|
+      p = points[i]
+      v = 1.0
+      a = points.size - 1
+      b = i
+      c = a - b
+      loop do
+        if a > 1
+          v *= a
+          a -= 1
+        else
+          break
+        end
+        if b > 1
+          v /= b
+          b -= 1
+        end
+        if c > 1
+          v /= c
+          c -= 1
+        end
+      end
+      v *= (d ** i) * ((1 - d) ** ((points.size - 1) - i))
+      o += p.scale(v)
+    }
+    o
+  end
+end
+
+App.main_loop
diff --git a/examples/0200_円運動_circle_jet_coaster.rb b/examples/0200_円運動_circle_jet_coaster.rb
index 9cf7f1c..8521242 100644
--- a/examples/0200_円運動_circle_jet_coaster.rb
+++ b/examples/0200_円運動_circle_jet_coaster.rb
@@ -14,7 +14,7 @@ class Ball
     p0 = pos_new(@win.count)      # 現在の位置を取得
     p1 = pos_new(@win.count.next) # 次のフレームの位置を取得
     dir = p0.angle_to(p1)          # 現在の位置から見て未来の角度を取得
-    @win.draw_polygon(p0, :radius => 20, :vertex => 3, :angle => dir) # 次に進む方向に向けて三角を表示
+    @win.draw_circle(p0, :radius => 20, :vertex => 3, :angle => dir) # 次に進む方向に向けて三角を表示
   end

   #
diff --git a/examples/0210_円を押すひっぱる_collision_circle_vs_circle_push_or_pull.rb b/examples/0210_円を押すひっぱる_collision_circle_vs_circle_push_or_pull.rb
index 53c78e5..7b29b8a 100644
--- a/examples/0210_円を押すひっぱる_collision_circle_vs_circle_push_or_pull.rb
+++ b/examples/0210_円を押すひっぱる_collision_circle_vs_circle_push_or_pull.rb
@@ -43,7 +43,7 @@ class Ball
     @pos = b

     @win.draw_line(@pos, @win.cursor)
-    @win.draw_polygon(@pos, :radius => @radius, :vertex => 32)
+    @win.draw_circle(@pos, :radius => @radius, :vertex => 32)
   end
 end

diff --git a/examples/0210_円を押すひっぱる_collision_circle_vs_circle_push_or_pull.rb b/examples/0210_円を押すひっぱる_collision_circle_vs_circle_push_or_pull.rb
new file mode 100644
index 0000000..7b29b8a
--- /dev/null
+++ b/examples/0210_円を押すひっぱる_collision_circle_vs_circle_push_or_pull.rb
@@ -0,0 +1,62 @@
+# -*- coding: utf-8 -*-
+#
+# 円同士の当り判定(ベクトルを使った方法)
+#
+require_relative "helper"
+
+class Ball
+  def initialize(win, pos)
+    @win = win
+    @pos = pos
+    @radius = 100
+  end
+
+  def update
+    a = @win.cursor
+    ar = @win.cursor_radius
+
+    b = @pos
+    br = @radius
+
+    r2 = ar + br
+    if a != b
+      diff = b - a
+      rdiff = r2 - diff.length
+      if @win.button.btA.press?
+        @win.vputs "PUSH"
+        if rdiff > 0
+          # a = b + diff.normalize * r2 # Bを基点に押し出す
+          b += diff.normalize * rdiff    # Aを基点に押し出す
+        end
+      end
+      if @win.button.btB.press?
+        @win.vputs "PULL"
+        if rdiff < 0
+          # a = b + diff.normalize * r2 # Bを基点に戻す
+          b += diff.normalize * rdiff    # Aを基点に戻す
+        end
+      end
+      @win.vputs "DIFF=#{diff.length}"
+      @win.vputs "RDIFF=#{rdiff}"
+    end
+
+    @pos = b
+
+    @win.draw_line(@pos, @win.cursor)
+    @win.draw_circle(@pos, :radius => @radius, :vertex => 32)
+  end
+end
+
+class App < Stylet::Base
+  include Helper::TriangleCursor
+
+  def before_main_loop
+    super if defined? super
+    @objects << Ball.new(self, rect.center.clone)
+    @cursor_radius = 100
+    @cursor_vertex = 32
+    self.title = "円の押し引き"
+  end
+end
+
+App.main_loop
diff --git a/examples/0220_芋虫ゴム紐デモ_collision_demo_circle_worm.rb b/examples/0220_芋虫ゴム紐デモ_collision_demo_circle_worm.rb
index a000ec0..ad6d4ca 100644
--- a/examples/0220_芋虫ゴム紐デモ_collision_demo_circle_worm.rb
+++ b/examples/0220_芋虫ゴム紐デモ_collision_demo_circle_worm.rb
@@ -47,7 +47,7 @@ class Joint

     # 胴体の表示
     if @win.body_display
-      @win.draw_polygon(@p0, :radius => @win.length / 2, :vertex => 16)
+      @win.draw_circle(@p0, :radius => @win.length / 2, :vertex => 16)
     end
   end
 end
diff --git a/examples/0220_芋虫ゴム紐デモ_collision_demo_circle_worm.rb b/examples/0220_芋虫ゴム紐デモ_collision_demo_circle_worm.rb
new file mode 100644
index 0000000..ad6d4ca
--- /dev/null
+++ b/examples/0220_芋虫ゴム紐デモ_collision_demo_circle_worm.rb
@@ -0,0 +1,108 @@
+# -*- coding: utf-8 -*-
+#
+# 芋虫・多関節・ゴム・紐
+#
+require_relative "helper"
+
+class Joint
+  attr_accessor :p0
+
+  def initialize(win, index, p0)
+    @win = win
+    @index = index    # 自分の番号
+    @p0 = p0          # 間接の位置
+  end
+
+  def update
+    # 次の位置の間接を取得
+    @target = @win.objects[@index.next]
+
+    if @target
+      distance = @p0.distance_to(@target.p0)
+      gap = distance - @win.length
+      if gap > 0
+        # 相手の方から自分の方へ移動する
+        # そのときの移動量を @win.hard_level で調整する
+        # 1.0 なら相手との間隔をすべて埋めることになるので紐になる
+        # 0.1 ならゆっくりと自分に近付いてくる
+        len = gap * @win.hard_level
+        dir = @target.p0.angle_to(@p0)
+        @target.p0 += Stylet::Vector.angle_at(dir) * len
+
+        # 固さ 1.0 のときは次のように p0 の方から相手をひっぱる方法でもよいが前者の方が、ゆっくり移動させるなど応用が効く
+        # dir = @p0.angle_to(@target.p0)
+        # @target.p0 += Stylet::Vector.angle_at(dir) * @win.length
+      end
+    end
+
+    # 頭だけカーソルで動かす
+    if @index.zero?
+      @p0 = @win.cursor
+    end
+
+    # 次の間接まで線を引く
+    if @target
+      @win.draw_line(@p0, @target.p0)
+    end
+
+    # 胴体の表示
+    if @win.body_display
+      @win.draw_circle(@p0, :radius => @win.length / 2, :vertex => 16)
+    end
+  end
+end
+
+class App < Stylet::Base
+  include Helper::TriangleCursor
+
+  attr_reader :body_display
+  attr_reader :length
+  attr_reader :hard_level
+
+  def before_main_loop
+    super if defined? super
+    @objects = Array.new(42){|i|Joint.new(self, i, rect.center.clone)}
+    @cursor_display = false     # 三角カーソル非表示
+
+    @body_display = true # 胴体描画モード
+    @length = 32         # 線と線の間
+    @hard_level = 1.0    # 幼虫の間接の伸び(堅い1.0〜柔らか0.1)
+
+    self.title = "芋虫・多関節・ゴム・紐"
+  end
+
+  def update
+    super if defined? super
+
+    # 操作
+    begin
+      # 間接と間接の距離の調整
+      @length += (@button.btA.repeat - @button.btB.repeat)
+      @length = Stylet::Etc.range_limited(@length, (1..80))
+
+      # 固さ調整
+      @hard_level += (@button.btC.repeat - @button.btD.repeat) * 0.1
+      @hard_level = Stylet::Etc.range_limited(@hard_level)
+
+      # 円の表示トグル
+      if key_down?(SDL::Key::A)
+        @body_display = !@body_display
+      end
+    end
+
+    # 操作説明
+    vputs "A:body_display"
+    vputs "Z:len++ X:len-- C:hard_level++ V:hard_level--"
+    vputs "length=#{@length}"
+    vputs "hard_level=#{@hard_level}"
+
+    # 固さ1.0なら紐モード表示
+    if @hard_level == 1.0
+      vputs "string mode"
+    else
+      vputs "worm mode"
+    end
+  end
+end
+
+App.main_loop
diff --git a/examples/0230_振り子_swing.rb b/examples/0230_振り子_swing.rb
index d05c391..252acb5 100644
--- a/examples/0230_振り子_swing.rb
+++ b/examples/0230_振り子_swing.rb
@@ -97,7 +97,7 @@ class Swing
     @win.draw_line(@p0, @pA)

     # 鉄球
-    @win.draw_polygon(@pA, :radius => @ball_radius, :vertex => 16)
+    @win.draw_circle(@pA, :radius => @ball_radius, :vertex => 16)

     # デバッグモード
     if @debug_mode || @win.button.btD.press?
@@ -119,7 +119,7 @@ class Swing
       rad90_line

       # 軌道の円周
-      @win.draw_polygon(@p0, :radius => @radius, :vertex => 32)
+      @win.draw_circle(@p0, :radius => @radius, :vertex => 32)

       # @win.draw_line(@pB, @pB + (@pA - @pB).scale(2))
     end
diff --git a/examples/0250_円と円の反射_collision_reflect_circle_vs_circle.rb b/examples/0250_円と円の反射_collision_reflect_circle_vs_circle.rb
index b456a3e..f8adc84 100644
--- a/examples/0250_円と円の反射_collision_reflect_circle_vs_circle.rb
+++ b/examples/0250_円と円の反射_collision_reflect_circle_vs_circle.rb
@@ -129,11 +129,11 @@ class Scene
       end
     end

-    @win.draw_polygon(@pA, :vertex => @vertex, :radius => @a_radius)
+    @win.draw_circle(@pA, :vertex => @vertex, :radius => @a_radius)
     @win.vputs "A(#{@am})", :vector => @pA
     @win.draw_vector(@sA.scale(@s_radius), :origin => @pA, :label => @sA.length)

-    @win.draw_polygon(@pB, :vertex => @vertex, :radius => @b_radius)
+    @win.draw_circle(@pB, :vertex => @vertex, :radius => @b_radius)
     @win.vputs "B(#{@bm})", :vector => @pB
     @win.draw_vector(@sB.scale(@s_radius), :origin => @pB, :label => @sB.length)

@@ -147,10 +147,10 @@ class Scene

       if @resp
         @pA2 = @pA + @sA.normalize.scale(@resp[:f0])
-        @win.draw_polygon(@pA2, :vertex => @vertex, :radius => @a_radius)
+        @win.draw_circle(@pA2, :vertex => @vertex, :radius => @a_radius)

         @pB2 = @pB + @sB.normalize.scale(@resp[:f0])
-        @win.draw_polygon(@pB2, :vertex => @vertex, :radius => @b_radius)
+        @win.draw_circle(@pB2, :vertex => @vertex, :radius => @b_radius)
       end
     end
   end
diff --git a/examples/0260_点と線分の交差判定_collision_ray_circle_vs_line.rb b/examples/0260_点と線分の交差判定_collision_ray_circle_vs_line.rb
index c650859..616b7db 100644
--- a/examples/0260_点と線分の交差判定_collision_ray_circle_vs_line.rb
+++ b/examples/0260_点と線分の交差判定_collision_ray_circle_vs_line.rb
@@ -192,7 +192,7 @@ class Ray
         @win.draw_triangle(@p0, :radius => @dot_radius, :angle => @vS.angle)
       else
         # 自機(円)の表示
-        @win.draw_polygon(@p0, :radius => @radius, :vertex => @vertex, :angle => @vS.angle)
+        @win.draw_circle(@p0, :radius => @radius, :vertex => @vertex, :angle => @vS.angle)
       end
       @win.vputs "p0", :vector => @p0

diff --git a/examples/0270_円と点の反射_collision_circle_vs_dot.rb b/examples/0270_円と点の反射_collision_circle_vs_dot.rb
index f459ccf..6ab2b4b 100644
--- a/examples/0270_円と点の反射_collision_circle_vs_dot.rb
+++ b/examples/0270_円と点の反射_collision_circle_vs_dot.rb
@@ -27,7 +27,7 @@ class Circle
       end
     end

-    @win.draw_polygon(@pos, :radius => @radius, :vertex => 32)
+    @win.draw_circle(@pos, :radius => @radius, :vertex => 32)
     @win.vputs "Z:x++ X:x--"
   end
 end
diff --git a/examples/0280_円と円と線分の反射デモ_collision_demo.rb b/examples/0280_円と円と線分の反射デモ_collision_demo.rb
index 1180b78..d4ac890 100644
--- a/examples/0280_円と円と線分の反射デモ_collision_demo.rb
+++ b/examples/0280_円と円と線分の反射デモ_collision_demo.rb
@@ -232,7 +232,7 @@ class Ball
     @pos += @speed

     # 自機(円)の表示
-    @win.draw_polygon(@pos, :radius => @radius, :vertex => @vertex, :angle => @speed.angle)
+    @win.draw_circle(@pos, :radius => @radius, :vertex => @vertex, :angle => @speed.angle)
   end
 end

diff --git a/examples/0280_円と円と線分の反射デモ_collision_demo.rb b/examples/0280_円と円と線分の反射デモ_collision_demo.rb
new file mode 100644
index 0000000..d4ac890
--- /dev/null
+++ b/examples/0280_円と円と線分の反射デモ_collision_demo.rb
@@ -0,0 +1,327 @@
+# -*- coding: utf-8 -*-
+#
+# デモ - かごの中で球が転がある
+#
+require_relative "helper"
+
+class Ball
+  REFLECT_RATIO = 1.0 # 反射係数
+
+  attr_accessor :pos            # 中心点
+  attr_accessor :speed          # 速度
+  attr_reader :radius           # 円の半径
+  attr_reader :mass             # 質量
+
+  def initialize(win, scene, index)
+    @win = win
+    @scene = scene
+
+    @pos = @win.rect.center.clone                                                           # 中心点
+    @speed = Stylet::Vector.new(Stylet::Etc.wide_rand(2.0), Stylet::Etc.range_rand(-6, -8)) # 速度ベクトル
+    @gravity = Stylet::Vector.new(0, 0.20)                                                  # 重力
+    if index < 4
+      @radius = 8 + ((index + 2) ** 2)                                                      # 半径
+    else
+      @radius = Stylet::Etc.range_rand(8, 20)                                               # 半径
+    end
+    @mass = @radius ** 2                                                                    # 質量は面積と比例することにする(PI*r二乗)
+    @vertex = Stylet::Etc.range_rand(16, 16).to_i                                           # 何角形か？
+  end
+
+  #
+  # 線分 pA pB との当たり判定
+  #
+  def collide_circle_vs_line(pA, pB, options = {})
+    # 点Aと点Bに円がめり込んでいたら押す
+    [pA, pB].each do |pX|
+      diff = @pos - pX
+      if diff.length > 0
+        if diff.length < @radius
+          @pos = pX + diff.normalize.scale(@radius)
+          @speed = diff.normalize * @speed.length
+        end
+      end
+    end
+
+    # 法線(正規化済み)
+    normal = pA.normal(pB).normalize
+    # @win.draw_line(pA, pA + normal.scale(30))
+
+    # t と C の取得
+    begin
+      # 自機から面と垂直な線を出して面と交差するか調べる
+      @vP = Stylet::Vector.angle_at(normal.reverse.angle).scale(@radius)
+
+      # 自機の原点・速度ベクトル・法線の原点(pAでもpBでもよい)・法線ベクトルを渡すと求まる
+      @t = Stylet::Vector.collision_power_scale(@pos, @vP, pA, normal)
+
+      # 交差点の取得
+      @pC = @pos + @vP.scale(@t)
+
+      # 内積の取得
+      ac = @pC - pA
+      bc = @pC - pB
+      if ac.nonzero? && bc.nonzero?
+        @ip2 = Stylet::Vector.inner_product(ac, bc)
+      else
+        raise
+      end
+    end
+
+    # 線の表裏どちらにいるか。また衝突しているか？ (この時点では無限線)
+
+    f = false
+    if options[:ground]
+      f = @t <= 1.0 # めり込んでいる or 通り過ぎている
+    else
+      f = 0.0 < @t && @t <= 1.0 # めり込んでいる(これだと線を飛び越えてしまう)
+    end
+    if f
+      if @ip2 < 0 # 線の中で
+        # 円を押し戻す
+        @pos = @pC + normal * @radius
+        @speed += @speed.reflect(normal)
+      end
+    end
+
+    # 速度制限(円が線から飛び出さないようにする)
+    speed_limit!
+    # if @speed.length > @radius
+    #   @speed = @speed.normalize.scale(@radius)
+    # end
+  end
+
+  def self.collide_circle_vs_circle(oA, oB)
+    pA = oA.pos
+    pB = oB.pos
+    sA = oA.speed
+    sB = oB.speed
+    amass = oA.mass
+    bmass = oB.mass
+
+    diff = pB - pA
+    rdiff = (oA.radius + oB.radius) - diff.length
+    # Stylet::Base.instance.vputs rdiff
+
+    # ここは完全に重なっている。物理的にはこうならないので左右に移動させる
+    if diff.length.zero?
+      arrow = Stylet::Vector.nonzero_random_new
+      pA -= arrow * oA.radius
+      pB += arrow * oB.radius
+      oA.pos = pA
+      oB.pos = pB
+      return true
+    end
+
+    # @win.vputs "length=#{diff.length}"
+    # @win.vputs "rdiff=#{rdiff}"
+
+    # if diff.length.zero?
+    #   return
+    # end
+
+    # # AとBをお互い離す
+    # if @win.reflect_mode == "move"
+    #   if rdiff > 0
+    #     pA -= diff.normalize * rdiff / 2
+    #     pB += diff.normalize * rdiff / 2
+    #   end
+    # end
+
+    # 反射する
+    if rdiff > 0
+
+      # 反射するモードでもいったんお互いを引き離さないと絡まってしまう
+      pA -= diff.normalize * rdiff * 0.5
+      pB += diff.normalize * rdiff * 0.5
+
+      # (am) 円Ａから円Ｂへ移動運動を発生させるベクトル
+      # (ar) 円Ａから円Ｂへ回転運動を発生させるベクトル
+      # (bm) 円Ｂから円Ａへ移動運動を発生させるベクトル
+      # (br) 円Ｂから円Ａへ回転運動を発生させるベクトル
+
+      # 速度ベクトルを重心方向と垂直な方向に分離する
+      _denominator = (diff.x ** 2 + diff.y ** 2)
+
+      # A
+      # A→B 回転運動
+      t = -(diff.x * sA.x + diff.y * sA.y) / _denominator
+      ar = sA + diff.scale(t)
+
+      # A→B 移動運動
+      t = -(-diff.y * sA.x + diff.x * sA.y) / _denominator
+      am = Stylet::Vector.new
+      am.x = sA.x - diff.y * t
+      am.y = sA.y + diff.x * t
+
+      # B
+      # B→A 回転運動
+      t = -(diff.x * sB.x + diff.y * sB.y) / _denominator
+      br = sB + diff.scale(t)
+
+      # B→A 移動運動
+      t = -(-diff.y * sB.x + diff.x * sB.y) / _denominator
+      bm = Stylet::Vector.new
+      bm.x = sB.x - diff.y * t
+      bm.y = sB.y + diff.x * t
+
+      # x 方向と y 方向それぞれの衝突後の速度を計算する
+      ad = Stylet::Vector.new
+      bd = Stylet::Vector.new
+      ad.x = (amass * am.x + bmass * bm.x + bm.x * REFLECT_RATIO * bmass - am.x * REFLECT_RATIO * bmass) / (amass + bmass)
+      bd.x = - REFLECT_RATIO * (bm.x - am.x) + ad.x
+      ad.y = (amass * am.y + bmass * bm.y + bm.y * REFLECT_RATIO * bmass - am.y * REFLECT_RATIO * bmass) / (amass + bmass)
+      bd.y = - REFLECT_RATIO * (bm.y - am.y) + ad.y
+
+      # 回転運動を発生させるベクトルを加算して衝突後の速度を計算
+      sA.x = ad.x + ar.x
+      sA.y = ad.y + ar.y
+      sB.x = bd.x + br.x
+      sB.y = bd.y + br.y
+
+      oA.pos = pA
+      oB.pos = pB
+      oA.speed = sA
+      oB.speed = sB
+
+      oA.speed_limit!
+      oB.speed_limit!
+
+      # pA += sA
+      # pB += sB
+      true
+    else
+      false
+    end
+  end
+
+  def speed_limit!(r = 1.0)
+    # 速度制限(円が線から飛び出さないようにする)
+    if @speed.length > (@radius * r)
+      @speed = @speed.normalize.scale(@radius * r)
+    end
+  end
+
+  def speed_limit2!(v)
+    # 速度制限(円が線から飛び出さないようにする)
+    if @speed.length > v
+      @speed = @speed.normalize.scale(v)
+    end
+  end
+
+  def update
+    # 操作
+    begin
+      # AとBで速度ベクトルの反映
+      @pos += @speed.scale(@win.button.btA.repeat_0or1) + @speed.scale(-@win.button.btB.repeat_0or1)
+      # Cボタンおしっぱなし + マウスで自機位置移動
+      if @win.button.btC.press?
+        @pos = @win.cursor.clone
+      end
+      # Dボタンおしっぱなし + マウスで自機角度変更
+      if @win.button.btD.press?
+        if @win.cursor != @pos
+          @speed = (@win.cursor - @pos).normalize * @speed.length.round
+        end
+      end
+    end
+
+    @speed += @gravity
+    # speed_limit2!(10.0)
+
+    @pos += @speed
+
+    # 自機(円)の表示
+    @win.draw_circle(@pos, :radius => @radius, :vertex => @vertex, :angle => @speed.angle)
+  end
+end
+
+class Scene
+  def initialize(win)
+    @win = win
+    @balls = Array.new(5){|i|Ball.new(@win, self, i)}
+    @count = 0
+    @center = @win.rect.center
+  end
+
+  def update
+    # # Aボタンおしっぱなし + マウスで自機角度変更
+    # if @win.button.btA.press?
+    #   @center = @win.cursor.clone
+    #   # if @win.cursor != @center
+    #   #   @speed = (@win.cursor - @pos).normalize * @speed.length
+    #   # end
+    # end
+
+    _count = @count
+
+    # 線の準備
+    @lines = []
+    n = 5
+    n.times{|i|
+      @lines << @center + Stylet::Vector.angle_at((1.0 / 128 * _count) + 1.0 / n * i) * @win.rect.h * 0.45
+    }
+
+    # 線の準備
+    @lines2 = []
+    n = 3
+    n.times{|i|
+      @lines2 << @center + Stylet::Vector.angle_at((1.0 / 512 * _count) + 1.0 / n * i) * @win.rect.h * 0.1
+    }
+
+    # 円と円の当たり判定
+    @balls.each{|ball1|
+      (@balls - [ball1]).each{|ball2|
+        Ball.collide_circle_vs_circle(ball1, ball2)
+      }
+    }
+
+    # 円と線の当たり判定
+    @lines.each_index{|i|
+      a = @lines[i]
+      b = @lines[i.next.modulo(@lines.size)]
+      @balls.each{|ball|
+        ball.collide_circle_vs_line(a, b, :ground => true)
+      }
+    }
+
+    # 円と線の当たり判定(中央の物体)
+    @lines2.each_index{|i|
+      a = @lines2[i]
+      b = @lines2[i.next.modulo(@lines2.size)]
+      @balls.each{|ball|
+        ball.collide_circle_vs_line(b, a)
+      }
+    }
+
+    # 線の描画
+    @lines.each_index{|i|
+      a = @lines[i]
+      b = @lines[i.next.modulo(@lines.size)]
+      @win.draw_line(a, b)
+    }
+
+    # 線の描画
+    @lines2.each_index{|i|
+      a = @lines2[i]
+      b = @lines2[i.next.modulo(@lines2.size)]
+      @win.draw_line(a, b)
+    }
+
+    # 球の描画
+    @balls.each{|ball|ball.update}
+
+    @count += 1
+  end
+end
+
+class App < Stylet::Base
+  include Helper::TriangleCursor
+
+  def before_main_loop
+    super if defined? super
+    @objects << Scene.new(self)
+  end
+end
+
+App.main_loop
diff --git a/examples/__0100_spline.rb b/examples/__0100_spline.rb
new file mode 100644
index 0000000..f269528
--- /dev/null
+++ b/examples/__0100_spline.rb
@@ -0,0 +1,78 @@
+# -*- coding: utf-8 -*-
+require_relative "bezier"
+
+class App < Bezier
+  def before_main_loop
+    super if defined? super
+
+    case true
+    when true
+      # 横に配置
+      n = 2
+      @points = Array.new(n + 1){|i|
+        x = (width * 0.1) + ((width * 0.8) / n * i)
+        y = hy
+        MovablePoint.new(self, x, y)
+      }
+    when true
+      # 円状に配置
+      n = 5
+      r = hy * 0.9
+      @points = Array.new(n){|i|
+        x = hx + Stylet::Fee.cos(1.0 / n * i) * r
+        y = hy + Stylet::Fee.sin(1.0 / n * i) * r
+        MovablePoint.new(self, x, y)
+      }
+    end
+
+    update_title
+  end
+
+  def coefficent(t)
+    r = nil
+    d = nil
+    if t < 0.0
+      t = -t
+    end
+    if t < 1.0
+      r = (3.0 * t * t * t -6.0 * t * t + 4.0) / 6.0
+    elsif t < 2.0
+      d = t - 2.0
+      r = -d * d * d / 6.0
+    else
+      r = 0.0
+    end
+    r
+  end
+
+  # Bスプライン
+  # http://www1.u-netsurf.ne.jp/~future/HTML/bspline.html
+
+  # _step = @points.size * 0.01;
+  # -1.0.step(@points.size, _step){|t|
+  #   draw_spline(@points, t)
+  # }
+
+  def bezier_point(points, d)
+    interpolate = 20
+    o = Stylet::Vector.new(0, 0)
+
+    x = 0.0
+    y = 0.0
+    -2.step(points.size + 2){|j|
+      k = j
+      if j < 0
+        k = 0
+      end
+      if j >= points.size
+        k = points.size - 1
+      end
+      cn = coefficent(t - j)
+      x += points[k] * cn
+      y += points[k] * cn
+    }
+    Vector.new(x.to_i, y.to_i)
+  end
+end
+
+App.main_loop
diff --git a/examples/__0300_3d.rb b/examples/__0300_3d.rb
new file mode 100644
index 0000000..793a95e
--- /dev/null
+++ b/examples/__0300_3d.rb
@@ -0,0 +1,83 @@
+# -*- coding: utf-8 -*-
+#
+# 3D
+#
+require_relative "helper"
+
+class Scene
+  def initialize(win)
+    @win = win
+    @points = []
+
+    @points << Stylet::Vector3.new(-200, +200, 75)
+    @points << Stylet::Vector3.new(+200, +200, 75)
+    @points << Stylet::Vector3.new(+200, -200, 75)
+    @points << Stylet::Vector3.new(-200, -200, 75)
+
+    @points << Stylet::Vector3.new(-200, +200, 50)
+    @points << Stylet::Vector3.new(+200, +200, 50)
+    @points << Stylet::Vector3.new(+200, -200, 50)
+    @points << Stylet::Vector3.new(-200, -200, 50)
+
+    @ridges = [
+      [0, 1],
+      [1, 2],
+      [2, 3],
+      [3, 0],
+
+      [4, 5],
+      [5, 6],
+      [6, 7],
+      [7, 4],
+
+      [0, 4],
+      [1, 5],
+      [2, 6],
+      [3, 7],
+    ]
+    @hhh = 25
+    @ydir = 0
+  end
+
+  def update
+    @hhh += @win.axis.down.repeat - @win.axis.up.repeat
+
+    # @pointsA.collect{|p|
+    #   s = Stylet::Vector.new
+    #   s.x = p.x * Stylet::Fee.cos(@ydir) - p.z * Stylet::Fee.sin(@ydir)
+    #   s.x = p.x * Stylet::Fee.cos(@ydir) - p.z * Stylet::Fee.sin(@ydir)
+    #   ((long)box2z[i].vx * rsin8(r)) / 128 + ((long)box2z[i].vz * rcos8(r)) / 128;
+    #   box2y[i].vy = box2z[i].vy;
+    # }
+    #
+    # for (i=0; i<VERTEX_N; i++) {
+    #     }
+
+    @points2 = @points.collect{|p|
+      Stylet::Vector.new(p.x.to_f * @hhh / p.z, p.y.to_f * @hhh / p.z)
+    }
+    @points3 = @points2.collect{|p|
+      @win.rect.center + Stylet::Vector.new(p.x, -p.y)
+    }
+    @ridges.each{|a, b|
+      @win.draw_line(@points3[a], @points3[b])
+    }
+    @points3.each_with_index{|p0, index|
+      @win.vputs index, :vector => p0
+    }
+    @win.vputs "hhh=#{@hhh}"
+  end
+end
+
+class App < Stylet::Base
+  include Helper::TriangleCursor
+
+  def before_main_loop
+    super if defined? super
+    self.title = "3D"
+    # @cursor_display = false
+    @objects << Scene.new(self)
+  end
+end
+
+App.main_loop
diff --git a/examples/__bullet_algos.rb b/examples/__bullet_algos.rb
new file mode 100644
index 0000000..dc7a604
--- /dev/null
+++ b/examples/__bullet_algos.rb
@@ -0,0 +1,225 @@
+# -*- coding: utf-8 -*-
+$LOAD_PATH << ".." if $0 == __FILE__
+require "shooting"
+
+# 狙い撃ち弾
+# n-way弾
+# 円形弾
+# 分裂弾
+# 誘導弾
+# 誘導レーザー
+# ミサイル
+# 加速弾
+# 落下弾
+# 狙い撃ち弾+回転弾      # 回転弾が自機を狙う
+# 渦巻き弾
+# 停止する誘導弾
+# 直進するビーム
+
+module BulletDir
+  def compute
+    super
+    @target_dir = Fee.angle(@x, @y, @target.x, @target.y)
+  end
+end
+
+module BulletNeraiutidan
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K1) || (joy && joy.button(0))
+      if @count.modulo(60 / 10).zero?
+        @win.bullets << Bullet.new(@win, @x, @y, @target_dir, 5.00)
+      end
+    end
+  end
+end
+
+class Bullet2 < BulletBase
+  include CircleGrid
+
+  def initialize(target, *args)
+    @target = target
+    super(*args)
+  end
+
+  def compute
+    compute_sincos
+    unless @win.pause_mode
+      if @count.modulo(1).zero?
+        d = Fee.angle(@x, @y, @target.x, @target.y)
+        gap = (d - @dir) % 1.00
+        if gap >= 0.5
+          sign = -1
+        else
+          sign = +1
+        end
+        @dir = (@dir + (1.0 / 256) * sign) % 1.0
+        @cx = @x
+        @cy = @y
+        @radius = @speed
+        @speed += 0.1
+      end
+    end
+  end
+end
+
+module BulletTuibi
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K2) || (joy && joy.button(1))
+      div, mod = @count.divmod(60 / 10)
+      if mod.zero?
+        wide = 2
+        @win.bullets << Bullet2.new(@target, @win, @x, @y, @target_dir + rand * 1.0 / wide - 1.0 / (wide * 2), 1.0)
+      end
+    end
+  end
+end
+
+module Bullet3waydan
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K4) || (joy && joy.button(2))
+      if @count.modulo(60 / 5).zero?
+        gap = 1.0 / 64
+        n = 3
+        n.times{|i|
+          d = @target_dir - (n / 2 * gap) + gap * i
+          @win.bullets << Bullet.new(@win, @x, @y, d, 5.00)
+        }
+      end
+    end
+  end
+end
+
+module BulletRandom
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K3) || (joy && joy.button(3))
+      if @count.modulo(60 / 20).zero?
+        z = 1.0 / 24
+        d = @target_dir + (rand * z - z / 2) * 2
+        @win.bullets << Bullet.new(@win, @x, @y, d, 7)
+      end
+    end
+  end
+end
+
+module BulletUzumaki
+  def initialize(*)
+    super
+    @uzumaki_count = 0
+  end
+
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K5) || (joy && joy.button(4))
+      div, mod = @count.divmod(60 / 20)
+      if mod.zero?
+        n = 4
+        n.times{|i|
+          d = 1.0 / n * i + (Fee.sin(1.0 / 32 * div) * 0.1)
+          @win.bullets << Bullet.new(@win, @x, @y, d, 2)
+        }
+      end
+    end
+  end
+end
+
+module BulletUzumakix2
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K6) || (joy && joy.button(5))
+      div, mod = @count.divmod(60 / 10)
+      if mod.zero?
+        uzumaki2(div, +1)
+        uzumaki2(div, -1)
+      end
+    end
+  end
+
+  def uzumaki2(count, sign)
+    n = 5
+    gap = 1.0 / n
+    n.times{|i|
+      d = (n / 2 * gap) + gap * i + (count * 1.0 / 120 * sign) + (count * 0.001)
+      @win.bullets << Bullet.new(@win, @x, @y, d, 2.0)
+    }
+  end
+end
+
+module Bullet128waydan
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K7) || (joy && joy.button(6))
+      if @count.modulo(60 / 2).zero?
+        n = 64
+        gap = 1.0 / n
+        n.times{|i|
+          @win.bullets << Bullet.new(@win, @x, @y, gap * i, 4.00)
+        }
+      end
+    end
+  end
+end
+
+module BulletUzumakix2Fast
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K8) || (joy && joy.button(7))
+      div, mod = @count.divmod(60 / 20)
+      if mod.zero?
+        uzumaki2fast(div, +1)
+        uzumaki2fast(div, -1)
+      end
+    end
+  end
+
+  def uzumaki2fast(count, sign)
+    n = 3
+    gap = 1.0 / n
+    n.times{|i|
+      d = (n / 2 * gap) + gap * i + (count * 1.0 / 120 * sign) + (count * 0.001)
+      @win.bullets << Bullet.new(@win, @x, @y, d, 6.0)
+    }
+  end
+end
+
+class GunShipA < GunShip1
+  include BulletDir
+  include BulletNeraiutidan
+  include BulletTuibi
+  include Bullet3waydan
+  include BulletRandom
+  include BulletUzumaki
+  include BulletUzumakix2
+  include Bullet128waydan
+  include BulletUzumakix2Fast
+end
+
+class GunShipB < GunShip2
+  include BulletDir
+  include BulletNeraiutidan
+  include BulletTuibi
+  include Bullet3waydan
+  include BulletRandom
+  include BulletUzumaki
+  include BulletUzumakix2
+  include Bullet128waydan
+  include BulletUzumakix2Fast
+end
+
+class Application < WarSpace
+  def initialize
+    super
+    @draw_inst = Stylet::Sdl::Draw.instance
+    ship1 = GunShipA.new(self, @draw_inst.width / 2, @draw_inst.height / 8 * 1)
+    ship2 = GunShipB.new(self, @draw_inst.width / 2, @draw_inst.height / 8 * 7)
+    ship1.target = ship2
+    ship2.target = ship1
+    @ships << ship1
+    @ships << ship2
+  end
+end
+
+Application.new.run
diff --git a/examples/bezier.rb b/examples/bezier.rb
index b5bcbbf..c8973df 100644
--- a/examples/bezier.rb
+++ b/examples/bezier.rb
@@ -41,9 +41,9 @@ class MovablePoint
     end

     if self == @unit.dragging_current
-      @win.draw_polygon(@pos, :radius => @radius, :vertex => 32)
+      @win.draw_circle(@pos, :radius => @radius, :vertex => 32)
     else
-      @win.draw_polygon(@pos, :radius => 2)
+      @win.draw_circle(@pos, :radius => 2)
     end
   end
 end
@@ -99,7 +99,7 @@ module BezierUnitBase
         # ○の表示
         pos = 0.5 + (Stylet::Fee.sin(@win.count / 256.0) * 0.5)
         xy = __bezier_point(pos)
-        @win.draw_polygon(xy, :radius => 64, :vertex => 32)
+        @win.draw_circle(xy, :radius => 64, :vertex => 32)
         @win.vputs(pos)
       else
         # △の表示で進んでいる方向を頂点にする
diff --git a/examples/hello_world.rb b/examples/hello_world.rb
new file mode 100644
index 0000000..b571fb5
--- /dev/null
+++ b/examples/hello_world.rb
@@ -0,0 +1,2 @@
+require "stylet"
+Stylet::Base.main_loop{|win|win.vputs "Hello, world."}
diff --git a/examples/helper.rb b/examples/helper.rb
index d4315e6..b23153e 100644
--- a/examples/helper.rb
+++ b/examples/helper.rb
@@ -84,7 +84,7 @@ module Helper
       @objects.reject!{|e| e.respond_to?(:screen_out?) && e.screen_out?}

       if @cursor_display
-        draw_polygon(@cursor, :radius => @cursor_radius, :vertex => @cursor_vertex, :angle => 1.0 / 64 * @count)
+        draw_circle(@cursor, :radius => @cursor_radius, :vertex => @cursor_vertex, :angle => 1.0 / 64 * @count)
       end
     end
   end
diff --git a/examples/trash/__0060_shooting2.rb b/examples/trash/__0060_shooting2.rb
new file mode 100644
index 0000000..206c149
--- /dev/null
+++ b/examples/trash/__0060_shooting2.rb
@@ -0,0 +1,37 @@
+$LOAD_PATH << ".." if $0 == __FILE__
+require "shooting"
+
+module BulletTrigger
+  def compute
+    super
+    dir = Fee.angle(@x, @y, @target.x, @target.y)
+    if (joy && joy.button(0))
+      if @count.modulo(60 / 6).zero?
+        @win.bullets << Bullet.new(@win, @x, @y, dir, 3.00)
+      end
+    end
+  end
+end
+
+class GunShipA < GunShip1
+  include BulletTrigger
+end
+
+class GunShipB < GunShip2
+  include BulletTrigger
+end
+
+class Application < WarSpace
+  def initialize
+    super
+    @draw_inst = Stylet::Sdl::Draw.instance
+    ship1 = GunShipA.new(self, @draw_inst.width / 2, @draw_inst.height / 8 * 1)
+    ship2 = GunShipB.new(self, @draw_inst.width / 2, @draw_inst.height / 8 * 7)
+    ship1.target = ship2
+    ship2.target = ship1
+    @ships << ship1
+    @ships << ship2
+  end
+end
+
+Application.new.run
diff --git a/examples/trash/__0090_collision_circle1.rb b/examples/trash/__0090_collision_circle1.rb
new file mode 100644
index 0000000..f0a8b47
--- /dev/null
+++ b/examples/trash/__0090_collision_circle1.rb
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+#
+# 円同士の当り判定(従来の方法)
+#
+require_relative "helper"
+
+class Ball
+  def initialize(win, pos)
+    @win = win
+    @pos = pos
+    @radius = 64
+  end
+
+  def update
+    distance = @pos.distance_to(@win.cursor)
+    radius2 = @radius + @win.cursor_radius
+    if distance < radius2
+      @win.draw_line(@pos, @win.cursor)
+      @win.vputs "COLLISION"
+
+      if @win.button.btA.press?
+        # カーソルの方向から円の位置の方向に一方的に移動させる
+        dir = @win.cursor.angle_to(@pos)
+        @pos.x = @win.cursor.x + Stylet::Fee.cos(dir) * radius2
+        @pos.y = @win.cursor.y + Stylet::Fee.sin(dir) * radius2
+      end
+    end
+    @win.draw_polygon(@pos, :radius => @radius, :vertex => 32)
+    if @win.count.modulo(5) == 0
+      @win.draw_line(@pos, @win.cursor)
+    end
+    @win.vputs "radius2=#{radius2}"
+    @win.vputs "distance=#{distance}"
+  end
+
+  def screen_out?
+    false
+  end
+end
+
+class App < Stylet::Base
+  include Helper::TriangleCursor
+
+  def before_main_loop
+    super if defined? super
+    @objects << Ball.new(self, rect.center.clone)
+    @cursor_radius = 64
+    @cursor_vertex = 32
+  end
+end
+
+App.main_loop
diff --git a/examples/trash/__0125_circle_collision.rb b/examples/trash/__0125_circle_collision.rb
new file mode 100644
index 0000000..32cc789
--- /dev/null
+++ b/examples/trash/__0125_circle_collision.rb
@@ -0,0 +1,105 @@
+# -*- coding: utf-8 -*-
+#
+# 円同士の当り判定
+#
+require_relative "helper"
+
+class Ball
+  def initialize(win, cpos)
+    @win = win
+    @cpos = cpos
+    @pos = @cpos.clone
+    @radius = 64
+    @vr = 0
+    @r = 0
+    @dir = 0
+  end
+
+  def update
+    dx = (@pos.x - @win.mouse_vector.x).abs
+    dy = (@pos.y - @win.mouse_vector.y).abs
+    distance = Math.sqrt((dx ** 2) + (dy ** 2))
+    @win.vputs(distance)
+    radius_plus = @radius + @win.radius
+    gap = radius_plus - distance
+    if gap > 0
+      @dir = Stylet::Fee.angle(@win.mouse_vector.x, @win.mouse_vector.y, @pos.x, @pos.y)
+      @cpos = @pos.clone
+      @r = 0
+      @vr = gap
+    end
+    @vr -= 0.01
+    if @vr < 0
+      @vr = 0
+    end
+    @r += @vr
+    @pos.x = @cpos.x + Stylet::Fee.cos(@dir) * @r
+    @pos.y = @cpos.y + Stylet::Fee.sin(@dir) * @r
+    @win.draw_polygon(@pos, :radius => @radius, :vertex => 32)
+  end
+
+  def screen_out?
+    false
+  end
+end
+
+module Helper
+  module HandCursor
+    include Stylet::Input::Base
+    include Stylet::Input::StandardKeybord
+    include Stylet::Input::JoystickBinding
+    include Stylet::Input::MouseButtonAsCounter
+
+    def before_main_loop
+      super if defined? super
+      @cursor = @mouse_vector.clone
+      @cursor_speed = 5
+      @objects = []
+    end
+
+    def update
+      super if defined? super
+
+      if joy = joys.first
+        update_by_joy(joy)
+      end
+      key_counter_update_all
+
+      if mouse_moved?
+        @cursor = @mouse_vector.clone
+      end
+
+      if dir = axis_angle
+        @cursor.x += Stylet::Fee.cos(dir) * @cursor_speed
+        @cursor.y += Stylet::Fee.sin(dir) * @cursor_speed
+      end
+
+      vputs @mouse_vector.to_a
+      vputs mouse_moved?
+
+      vputs @objects.size
+      @objects.each{|e|e.update}
+      @objects.reject!{|e|e.screen_out?}
+      draw_polygon(@cursor, :radius => 16, :vertex => 3, :angle => 1.0 / 64 * @count)
+    end
+  end
+end
+
+class App < Stylet::Base
+  include Helper::TriangleCursor
+
+  attr_reader :radius
+
+  def before_main_loop
+    super if defined? super
+    @objects << Ball.new(self, rect.center)
+    @radius = 64
+  end
+
+  def update
+    super if defined? super
+    draw_polygon(@mouse_vector, :radius => @radius, :vertex => 32)
+  end
+end
+
+App.main_loop
diff --git a/examples/trash/__0130_circle_collision2.rb b/examples/trash/__0130_circle_collision2.rb
new file mode 100644
index 0000000..f089307
--- /dev/null
+++ b/examples/trash/__0130_circle_collision2.rb
@@ -0,0 +1,63 @@
+# -*- coding: utf-8 -*-
+#
+# 円同士の当り判定
+#
+require_relative "helper"
+
+class Ball
+  def initialize(win, cpos)
+    @win = win
+    @cpos = cpos
+    @radius = 64
+    @r = 0
+    @vr = 4.0
+    @ar = -0.01
+    @dir = 0.0
+  end
+
+  def update
+    @win.objects.each{|object|
+      next if object == self
+
+      dx = (@pos.x - object.pos.x).abs
+      dy = (@pos.y - object.pos.y).abs
+      distance = Math.sqrt((dx ** 2) + (dy ** 2))
+      @win.vputs(distance)
+      distance_min = @radius + @win.radius
+      if distance < distance_min
+        dir = Stylet::Fee.angle(object.pos.x, object.pos.y, @pos.x, @pos.y)
+        @pos.x = object.pos.x + Stylet::Fee.cos(dir) * distance_min
+        @pos.y = object.pos.y + Stylet::Fee.sin(dir) * distance_min
+      end
+    }
+    @pos.x += Stylet::Fee.cos(@dir) * @r
+    @pos.y += Stylet::Fee.sin(@dir) * @r
+    @win.draw_polygon(@pos, :radius => @radius, :vertex => 32)
+  end
+
+  def screen_out?
+    false
+  end
+end
+
+class App < Stylet::Base
+  include Helper::TriangleCursor
+
+  attr_reader :objects
+
+  def before_main_loop
+    super if defined? super
+    4.times{
+      @objects << Ball.new(self, rect.center)
+    }
+  end
+
+  def update
+    super if defined? super
+    if object = @objects.first
+      object.pos = @mouse_vector.clone
+    end
+  end
+end
+
+App.main_loop
diff --git a/examples/trash/__0270_circle_cycle_shift.rb b/examples/trash/__0270_circle_cycle_shift.rb
new file mode 100644
index 0000000..26a4bb9
--- /dev/null
+++ b/examples/trash/__0270_circle_cycle_shift.rb
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+#
+# 円の動き
+#
+require_relative "helper"
+
+class Ball
+  def initialize(win)
+    @win = win
+  end
+
+  def update
+    pos = Stylet::Vector.new(0, 0)
+    pos.x = Stylet::Fee.cos(1.0 / 512 * (@win.count * 3)) * @win.rect.w / 2
+    pos.y = Stylet::Fee.sin(1.0 / 512 * (@win.count * 4)) * @win.rect.h / 2
+    pos += @win.rect.center
+    @win.draw_polygon(pos, :radius => 64)
+  end
+end
+
+class App < Stylet::Base
+  include Helper::TriangleCursor
+
+  def before_main_loop
+    super if defined? super
+    @cursor_display = false
+    @objects << Ball.new(self)
+  end
+end
+
+App.main_loop
diff --git a/lib/stylet/assets/background.bmp b/lib/stylet/assets/background.bmp
new file mode 100644
index 0000000..02faec5
Binary files /dev/null and b/lib/stylet/assets/background.bmp differ
diff --git a/lib/stylet/assets/bgm.wav b/lib/stylet/assets/bgm.wav
new file mode 100644
index 0000000..5e1e2bd
Binary files /dev/null and b/lib/stylet/assets/bgm.wav differ
diff --git a/lib/stylet/assets/se.wav b/lib/stylet/assets/se.wav
new file mode 100644
index 0000000..84de5c6
Binary files /dev/null and b/lib/stylet/assets/se.wav differ
diff --git a/lib/stylet/axis_support.rb b/lib/stylet/axis_support.rb
index ee9e615..36aa2c7 100644
--- a/lib/stylet/axis_support.rb
+++ b/lib/stylet/axis_support.rb
@@ -7,6 +7,14 @@ module Stylet
     #
     # レバーの状態から8方向の番号インデックスに変換
     #
+    #        [U]
+    #         6
+    #       5   7
+    #  [L]4       0[R]
+    #       3   1
+    #         2
+    #        [D]
+    #
     def axis_angle_index(axis)
       dir = nil
       if axis.up.press?
@@ -36,6 +44,14 @@ module Stylet
     #
     # 8方向レバーの状態から一周を1.0としたときの方向を返す
     #
+    #           [U]
+    #          0.750
+    #       0.625 0.875
+    #   [L]0.500   0.000[R]
+    #       0.375 0.125
+    #          0.250
+    #           [D]
+    #
     def axis_angle(axis)
       if dir = axis_angle_index(axis)
         1.0 / 8 * dir
@@ -43,3 +59,8 @@ module Stylet
     end
   end
 end
+
+if $0 == __FILE__
+  require_relative "fee"
+  p Stylet::Fee.angle_at(dir)
+end
diff --git a/lib/stylet/draw_support/circle.rb b/lib/stylet/draw_support/circle.rb
index 8a31377..dcfd102 100644
--- a/lib/stylet/draw_support/circle.rb
+++ b/lib/stylet/draw_support/circle.rb
@@ -4,7 +4,7 @@ module Stylet
     #
     # 多角形の描画
     #
-    def draw_polygon(p0, options = {})
+    def draw_circle(p0, options = {})
       options = {
         :radius => 64,       # 半径
         :vertex => 8,        # n角形
@@ -26,14 +26,14 @@ module Stylet
     # 三角形の描画
     #
     def draw_triangle(p0, options = {})
-      draw_polygon(p0, {:vertex => 3}.merge(options))
+      draw_circle(p0, {:vertex => 3}.merge(options))
     end

     #
     # 正方形の描画
     #
     def draw_square(p0, options = {})
-      draw_polygon(p0, {:vertex => 4}.merge(options))
+      draw_circle(p0, {:vertex => 4}.merge(options))
     end
   end
 end
@@ -41,8 +41,8 @@ end
 if $0 == __FILE__
   require_relative "../../stylet"
   Stylet::Base.main_loop do |win|
-    win.draw_polygon(win.rect.center)
-    # win.draw_triangle(win.rect.center)
-    # win.draw_square(win.rect.center)
+    win.draw_circle(win.rect.center)
+    win.draw_triangle(win.rect.center)
+    win.draw_square(win.rect.center)
   end
 end
diff --git a/lib/stylet/draw_support/polygon.rb b/lib/stylet/draw_support/polygon.rb
index 4578f29..d835867 100644
--- a/lib/stylet/draw_support/polygon.rb
+++ b/lib/stylet/draw_support/polygon.rb
@@ -19,7 +19,8 @@ end
 if $0 == __FILE__
   require_relative "../../stylet"
   Stylet::Base.main_loop do |win|
-    points = Array.new(3){Stylet::Vector.new(rand(win.rect.w), rand(win.rect.h))}
+    points = Array.new(3 + rand(3)){Stylet::Vector.new(rand(win.rect.w), rand(win.rect.h))}
     win.draw_polygon(points)
+    sleep(0.25)
   end
 end
diff --git a/lib/stylet/input/base.rb b/lib/stylet/input/base.rb
index da78a05..90da359 100644
--- a/lib/stylet/input/base.rb
+++ b/lib/stylet/input/base.rb
@@ -15,7 +15,7 @@ module Stylet

       def initialize(*)
         super if defined? super
-        @axis = Axis.new(KeyOne.new("u"), KeyOne.new("d"), KeyOne.new("l"), KeyOne.new("r"))
+        @axis   = Axis.new(KeyOne.new("u"), KeyOne.new("d"), KeyOne.new("l"), KeyOne.new("r"))
         @button = Button.new(KeyOne.new("AL"), KeyOne.new("BR"), KeyOne.new("C"), KeyOne.new("D"))
       end

@@ -40,8 +40,10 @@ module Stylet
       #
       def to_s(stype=nil)
         case stype.to_s
-        when "axis"   then @axis.values.to_s
-        when "button" then @button.values.to_s
+        when "axis"
+          @axis.values.to_s
+        when "button"
+          @button.values.to_s
         else
           key_objects.to_s
         end
@@ -80,3 +82,17 @@ module Stylet
     end
   end
 end
+
+if $0 == __FILE__
+  require_relative "../base"
+
+  b = Stylet::Input::KeyOne.new
+  b.update(true)
+
+  p Stylet::Vector.angle_at(0.0)
+
+  Stylet::Input
+
+  # Stylet::Vector.angle_at(speed.angle + Stylet::Fee.r45) * speed.length
+  # p Stylet::Fee.angle_at(0.0)
+end
diff --git a/lib/stylet/input/key_one.rb b/lib/stylet/input/key_one.rb
index 6c04b4f..cb6f072 100644
--- a/lib/stylet/input/key_one.rb
+++ b/lib/stylet/input/key_one.rb
@@ -28,10 +28,9 @@ module Stylet
       end

       attr_reader :mark, :count, :free_count
-      # attr_accessor :state

       def initialize(mark = "?")
-        @mark = mark.to_s.scan(/./) # "AR" だったら A と R に対応
+        @mark = mark.to_s.scan(/./) # "AL" だったら A と L に対応
         @count = 0
         @free_count = 0
         @state = false              # 直近のフラグ
@@ -40,16 +39,19 @@ module Stylet
       #
       # 直近フラグを設定。falseにはできない。
       #
+      #   フラグが有効になる条件が複数ある場合に使うと便利
+      #
+      #   有効になるもの
+      #     obj << "A" # 同じマーク
+      #     obj << 1
+      #     obj << true
+      #
       def <<(arg)
         case arg
         when String
-          if false
-            arg = arg.include?(@mark)
-          else
-            arg = !!@mark.find{|m|arg.include?(m)}
-          end
+          arg = !!@mark.any?{|m|arg.include?(m)}
         when Fixnum
-          arg = (arg != 0)
+          arg = arg.nonzero?
         end
         @state |= arg
       end
@@ -134,6 +136,8 @@ module Stylet
       #
       # 優先度チェック用
       #
+      #   FIXME: もっと簡潔に書けるはず
+      #
       def <=>(other)                # sortで優先度の高い順に並べる為の比較処理
         if @count == 0 || other.count == 0
           other.count <=> @count    # 0はもっとも優先度が低い為逆にする
@@ -158,3 +162,14 @@ module Stylet
     end
   end
 end
+
+if $0 == __FILE__
+  key_one = Stylet::Input::KeyOne.new("A")
+  key_one.update("A")
+  p key_one.state_to_s
+  p key_one.press?
+  p key_one.trigger?
+  p key_one.free?
+  p key_one.free_trigger?
+  p key_one.to_s
+end
diff --git a/lib/stylet/joystick_adapter.rb b/lib/stylet/joystick_adapter.rb
index a1d3947..f2436db 100644
--- a/lib/stylet/joystick_adapter.rb
+++ b/lib/stylet/joystick_adapter.rb
@@ -82,7 +82,7 @@ module Stylet
     #   end
     #   dir
     # end
-    #
+    #
     # def axis_angle
     #   if dir = axis_angle_index
     #     1.0 / 8 * dir
diff --git a/lib/stylet/vector.rb b/lib/stylet/vector.rb
index a47a180..2481d7d 100644
--- a/lib/stylet/vector.rb
+++ b/lib/stylet/vector.rb
@@ -221,7 +221,7 @@ module Stylet
         Vector3.new(*(values + [0]).take(3))
       end

-      # ゼロベクトルか？
+      # 0ベクトルか？
       def zero?
         values.all?{|v|v.zero?}
       end
[from now] 2013/01/06 16:39:43

diff --git a/.gitignore b/.gitignore
index 74ab2ae..fce49d9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,4 @@
 /README.html
 /Gemfile.lock
+/*.gem
+
[from now] 2013/01/06 17:00:49

diff --git a/examples/__0100_spline.rb b/examples/__0100_spline.rb
deleted file mode 100644
index f269528..0000000
--- a/examples/__0100_spline.rb
+++ /dev/null
@@ -1,78 +0,0 @@
-# -*- coding: utf-8 -*-
-require_relative "bezier"
-
-class App < Bezier
-  def before_main_loop
-    super if defined? super
-
-    case true
-    when true
-      # 横に配置
-      n = 2
-      @points = Array.new(n + 1){|i|
-        x = (width * 0.1) + ((width * 0.8) / n * i)
-        y = hy
-        MovablePoint.new(self, x, y)
-      }
-    when true
-      # 円状に配置
-      n = 5
-      r = hy * 0.9
-      @points = Array.new(n){|i|
-        x = hx + Stylet::Fee.cos(1.0 / n * i) * r
-        y = hy + Stylet::Fee.sin(1.0 / n * i) * r
-        MovablePoint.new(self, x, y)
-      }
-    end
-
-    update_title
-  end
-
-  def coefficent(t)
-    r = nil
-    d = nil
-    if t < 0.0
-      t = -t
-    end
-    if t < 1.0
-      r = (3.0 * t * t * t -6.0 * t * t + 4.0) / 6.0
-    elsif t < 2.0
-      d = t - 2.0
-      r = -d * d * d / 6.0
-    else
-      r = 0.0
-    end
-    r
-  end
-
-  # Bスプライン
-  # http://www1.u-netsurf.ne.jp/~future/HTML/bspline.html
-
-  # _step = @points.size * 0.01;
-  # -1.0.step(@points.size, _step){|t|
-  #   draw_spline(@points, t)
-  # }
-
-  def bezier_point(points, d)
-    interpolate = 20
-    o = Stylet::Vector.new(0, 0)
-
-    x = 0.0
-    y = 0.0
-    -2.step(points.size + 2){|j|
-      k = j
-      if j < 0
-        k = 0
-      end
-      if j >= points.size
-        k = points.size - 1
-      end
-      cn = coefficent(t - j)
-      x += points[k] * cn
-      y += points[k] * cn
-    }
-    Vector.new(x.to_i, y.to_i)
-  end
-end
-
-App.main_loop
diff --git a/examples/__0300_3d.rb b/examples/__0300_3d.rb
deleted file mode 100644
index 793a95e..0000000
--- a/examples/__0300_3d.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# 3D
-#
-require_relative "helper"
-
-class Scene
-  def initialize(win)
-    @win = win
-    @points = []
-
-    @points << Stylet::Vector3.new(-200, +200, 75)
-    @points << Stylet::Vector3.new(+200, +200, 75)
-    @points << Stylet::Vector3.new(+200, -200, 75)
-    @points << Stylet::Vector3.new(-200, -200, 75)
-
-    @points << Stylet::Vector3.new(-200, +200, 50)
-    @points << Stylet::Vector3.new(+200, +200, 50)
-    @points << Stylet::Vector3.new(+200, -200, 50)
-    @points << Stylet::Vector3.new(-200, -200, 50)
-
-    @ridges = [
-      [0, 1],
-      [1, 2],
-      [2, 3],
-      [3, 0],
-
-      [4, 5],
-      [5, 6],
-      [6, 7],
-      [7, 4],
-
-      [0, 4],
-      [1, 5],
-      [2, 6],
-      [3, 7],
-    ]
-    @hhh = 25
-    @ydir = 0
-  end
-
-  def update
-    @hhh += @win.axis.down.repeat - @win.axis.up.repeat
-
-    # @pointsA.collect{|p|
-    #   s = Stylet::Vector.new
-    #   s.x = p.x * Stylet::Fee.cos(@ydir) - p.z * Stylet::Fee.sin(@ydir)
-    #   s.x = p.x * Stylet::Fee.cos(@ydir) - p.z * Stylet::Fee.sin(@ydir)
-    #   ((long)box2z[i].vx * rsin8(r)) / 128 + ((long)box2z[i].vz * rcos8(r)) / 128;
-    #   box2y[i].vy = box2z[i].vy;
-    # }
-    #
-    # for (i=0; i<VERTEX_N; i++) {
-    #     }
-
-    @points2 = @points.collect{|p|
-      Stylet::Vector.new(p.x.to_f * @hhh / p.z, p.y.to_f * @hhh / p.z)
-    }
-    @points3 = @points2.collect{|p|
-      @win.rect.center + Stylet::Vector.new(p.x, -p.y)
-    }
-    @ridges.each{|a, b|
-      @win.draw_line(@points3[a], @points3[b])
-    }
-    @points3.each_with_index{|p0, index|
-      @win.vputs index, :vector => p0
-    }
-    @win.vputs "hhh=#{@hhh}"
-  end
-end
-
-class App < Stylet::Base
-  include Helper::TriangleCursor
-
-  def before_main_loop
-    super if defined? super
-    self.title = "3D"
-    # @cursor_display = false
-    @objects << Scene.new(self)
-  end
-end
-
-App.main_loop
diff --git a/examples/__bullet_algos.rb b/examples/__bullet_algos.rb
deleted file mode 100644
index dc7a604..0000000
--- a/examples/__bullet_algos.rb
+++ /dev/null
@@ -1,225 +0,0 @@
-# -*- coding: utf-8 -*-
-$LOAD_PATH << ".." if $0 == __FILE__
-require "shooting"
-
-# 狙い撃ち弾
-# n-way弾
-# 円形弾
-# 分裂弾
-# 誘導弾
-# 誘導レーザー
-# ミサイル
-# 加速弾
-# 落下弾
-# 狙い撃ち弾+回転弾      # 回転弾が自機を狙う
-# 渦巻き弾
-# 停止する誘導弾
-# 直進するビーム
-
-module BulletDir
-  def compute
-    super
-    @target_dir = Fee.angle(@x, @y, @target.x, @target.y)
-  end
-end
-
-module BulletNeraiutidan
-  def compute
-    super
-    if @win.press_button?(SDL::Key::K1) || (joy && joy.button(0))
-      if @count.modulo(60 / 10).zero?
-        @win.bullets << Bullet.new(@win, @x, @y, @target_dir, 5.00)
-      end
-    end
-  end
-end
-
-class Bullet2 < BulletBase
-  include CircleGrid
-
-  def initialize(target, *args)
-    @target = target
-    super(*args)
-  end
-
-  def compute
-    compute_sincos
-    unless @win.pause_mode
-      if @count.modulo(1).zero?
-        d = Fee.angle(@x, @y, @target.x, @target.y)
-        gap = (d - @dir) % 1.00
-        if gap >= 0.5
-          sign = -1
-        else
-          sign = +1
-        end
-        @dir = (@dir + (1.0 / 256) * sign) % 1.0
-        @cx = @x
-        @cy = @y
-        @radius = @speed
-        @speed += 0.1
-      end
-    end
-  end
-end
-
-module BulletTuibi
-  def compute
-    super
-    if @win.press_button?(SDL::Key::K2) || (joy && joy.button(1))
-      div, mod = @count.divmod(60 / 10)
-      if mod.zero?
-        wide = 2
-        @win.bullets << Bullet2.new(@target, @win, @x, @y, @target_dir + rand * 1.0 / wide - 1.0 / (wide * 2), 1.0)
-      end
-    end
-  end
-end
-
-module Bullet3waydan
-  def compute
-    super
-    if @win.press_button?(SDL::Key::K4) || (joy && joy.button(2))
-      if @count.modulo(60 / 5).zero?
-        gap = 1.0 / 64
-        n = 3
-        n.times{|i|
-          d = @target_dir - (n / 2 * gap) + gap * i
-          @win.bullets << Bullet.new(@win, @x, @y, d, 5.00)
-        }
-      end
-    end
-  end
-end
-
-module BulletRandom
-  def compute
-    super
-    if @win.press_button?(SDL::Key::K3) || (joy && joy.button(3))
-      if @count.modulo(60 / 20).zero?
-        z = 1.0 / 24
-        d = @target_dir + (rand * z - z / 2) * 2
-        @win.bullets << Bullet.new(@win, @x, @y, d, 7)
-      end
-    end
-  end
-end
-
-module BulletUzumaki
-  def initialize(*)
-    super
-    @uzumaki_count = 0
-  end
-
-  def compute
-    super
-    if @win.press_button?(SDL::Key::K5) || (joy && joy.button(4))
-      div, mod = @count.divmod(60 / 20)
-      if mod.zero?
-        n = 4
-        n.times{|i|
-          d = 1.0 / n * i + (Fee.sin(1.0 / 32 * div) * 0.1)
-          @win.bullets << Bullet.new(@win, @x, @y, d, 2)
-        }
-      end
-    end
-  end
-end
-
-module BulletUzumakix2
-  def compute
-    super
-    if @win.press_button?(SDL::Key::K6) || (joy && joy.button(5))
-      div, mod = @count.divmod(60 / 10)
-      if mod.zero?
-        uzumaki2(div, +1)
-        uzumaki2(div, -1)
-      end
-    end
-  end
-
-  def uzumaki2(count, sign)
-    n = 5
-    gap = 1.0 / n
-    n.times{|i|
-      d = (n / 2 * gap) + gap * i + (count * 1.0 / 120 * sign) + (count * 0.001)
-      @win.bullets << Bullet.new(@win, @x, @y, d, 2.0)
-    }
-  end
-end
-
-module Bullet128waydan
-  def compute
-    super
-    if @win.press_button?(SDL::Key::K7) || (joy && joy.button(6))
-      if @count.modulo(60 / 2).zero?
-        n = 64
-        gap = 1.0 / n
-        n.times{|i|
-          @win.bullets << Bullet.new(@win, @x, @y, gap * i, 4.00)
-        }
-      end
-    end
-  end
-end
-
-module BulletUzumakix2Fast
-  def compute
-    super
-    if @win.press_button?(SDL::Key::K8) || (joy && joy.button(7))
-      div, mod = @count.divmod(60 / 20)
-      if mod.zero?
-        uzumaki2fast(div, +1)
-        uzumaki2fast(div, -1)
-      end
-    end
-  end
-
-  def uzumaki2fast(count, sign)
-    n = 3
-    gap = 1.0 / n
-    n.times{|i|
-      d = (n / 2 * gap) + gap * i + (count * 1.0 / 120 * sign) + (count * 0.001)
-      @win.bullets << Bullet.new(@win, @x, @y, d, 6.0)
-    }
-  end
-end
-
-class GunShipA < GunShip1
-  include BulletDir
-  include BulletNeraiutidan
-  include BulletTuibi
-  include Bullet3waydan
-  include BulletRandom
-  include BulletUzumaki
-  include BulletUzumakix2
-  include Bullet128waydan
-  include BulletUzumakix2Fast
-end
-
-class GunShipB < GunShip2
-  include BulletDir
-  include BulletNeraiutidan
-  include BulletTuibi
-  include Bullet3waydan
-  include BulletRandom
-  include BulletUzumaki
-  include BulletUzumakix2
-  include Bullet128waydan
-  include BulletUzumakix2Fast
-end
-
-class Application < WarSpace
-  def initialize
-    super
-    @draw_inst = Stylet::Sdl::Draw.instance
-    ship1 = GunShipA.new(self, @draw_inst.width / 2, @draw_inst.height / 8 * 1)
-    ship2 = GunShipB.new(self, @draw_inst.width / 2, @draw_inst.height / 8 * 7)
-    ship1.target = ship2
-    ship2.target = ship1
-    @ships << ship1
-    @ships << ship2
-  end
-end
-
-Application.new.run
diff --git a/examples/test_all.rb b/examples/test_all.rb
old mode 100755
new mode 100644
diff --git a/examples/trash/__0100_spline.rb b/examples/trash/__0100_spline.rb
new file mode 100644
index 0000000..f269528
--- /dev/null
+++ b/examples/trash/__0100_spline.rb
@@ -0,0 +1,78 @@
+# -*- coding: utf-8 -*-
+require_relative "bezier"
+
+class App < Bezier
+  def before_main_loop
+    super if defined? super
+
+    case true
+    when true
+      # 横に配置
+      n = 2
+      @points = Array.new(n + 1){|i|
+        x = (width * 0.1) + ((width * 0.8) / n * i)
+        y = hy
+        MovablePoint.new(self, x, y)
+      }
+    when true
+      # 円状に配置
+      n = 5
+      r = hy * 0.9
+      @points = Array.new(n){|i|
+        x = hx + Stylet::Fee.cos(1.0 / n * i) * r
+        y = hy + Stylet::Fee.sin(1.0 / n * i) * r
+        MovablePoint.new(self, x, y)
+      }
+    end
+
+    update_title
+  end
+
+  def coefficent(t)
+    r = nil
+    d = nil
+    if t < 0.0
+      t = -t
+    end
+    if t < 1.0
+      r = (3.0 * t * t * t -6.0 * t * t + 4.0) / 6.0
+    elsif t < 2.0
+      d = t - 2.0
+      r = -d * d * d / 6.0
+    else
+      r = 0.0
+    end
+    r
+  end
+
+  # Bスプライン
+  # http://www1.u-netsurf.ne.jp/~future/HTML/bspline.html
+
+  # _step = @points.size * 0.01;
+  # -1.0.step(@points.size, _step){|t|
+  #   draw_spline(@points, t)
+  # }
+
+  def bezier_point(points, d)
+    interpolate = 20
+    o = Stylet::Vector.new(0, 0)
+
+    x = 0.0
+    y = 0.0
+    -2.step(points.size + 2){|j|
+      k = j
+      if j < 0
+        k = 0
+      end
+      if j >= points.size
+        k = points.size - 1
+      end
+      cn = coefficent(t - j)
+      x += points[k] * cn
+      y += points[k] * cn
+    }
+    Vector.new(x.to_i, y.to_i)
+  end
+end
+
+App.main_loop
diff --git a/examples/trash/__0300_3d.rb b/examples/trash/__0300_3d.rb
new file mode 100644
index 0000000..793a95e
--- /dev/null
+++ b/examples/trash/__0300_3d.rb
@@ -0,0 +1,83 @@
+# -*- coding: utf-8 -*-
+#
+# 3D
+#
+require_relative "helper"
+
+class Scene
+  def initialize(win)
+    @win = win
+    @points = []
+
+    @points << Stylet::Vector3.new(-200, +200, 75)
+    @points << Stylet::Vector3.new(+200, +200, 75)
+    @points << Stylet::Vector3.new(+200, -200, 75)
+    @points << Stylet::Vector3.new(-200, -200, 75)
+
+    @points << Stylet::Vector3.new(-200, +200, 50)
+    @points << Stylet::Vector3.new(+200, +200, 50)
+    @points << Stylet::Vector3.new(+200, -200, 50)
+    @points << Stylet::Vector3.new(-200, -200, 50)
+
+    @ridges = [
+      [0, 1],
+      [1, 2],
+      [2, 3],
+      [3, 0],
+
+      [4, 5],
+      [5, 6],
+      [6, 7],
+      [7, 4],
+
+      [0, 4],
+      [1, 5],
+      [2, 6],
+      [3, 7],
+    ]
+    @hhh = 25
+    @ydir = 0
+  end
+
+  def update
+    @hhh += @win.axis.down.repeat - @win.axis.up.repeat
+
+    # @pointsA.collect{|p|
+    #   s = Stylet::Vector.new
+    #   s.x = p.x * Stylet::Fee.cos(@ydir) - p.z * Stylet::Fee.sin(@ydir)
+    #   s.x = p.x * Stylet::Fee.cos(@ydir) - p.z * Stylet::Fee.sin(@ydir)
+    #   ((long)box2z[i].vx * rsin8(r)) / 128 + ((long)box2z[i].vz * rcos8(r)) / 128;
+    #   box2y[i].vy = box2z[i].vy;
+    # }
+    #
+    # for (i=0; i<VERTEX_N; i++) {
+    #     }
+
+    @points2 = @points.collect{|p|
+      Stylet::Vector.new(p.x.to_f * @hhh / p.z, p.y.to_f * @hhh / p.z)
+    }
+    @points3 = @points2.collect{|p|
+      @win.rect.center + Stylet::Vector.new(p.x, -p.y)
+    }
+    @ridges.each{|a, b|
+      @win.draw_line(@points3[a], @points3[b])
+    }
+    @points3.each_with_index{|p0, index|
+      @win.vputs index, :vector => p0
+    }
+    @win.vputs "hhh=#{@hhh}"
+  end
+end
+
+class App < Stylet::Base
+  include Helper::TriangleCursor
+
+  def before_main_loop
+    super if defined? super
+    self.title = "3D"
+    # @cursor_display = false
+    @objects << Scene.new(self)
+  end
+end
+
+App.main_loop
diff --git a/examples/trash/__bullet_algos.rb b/examples/trash/__bullet_algos.rb
new file mode 100644
index 0000000..dc7a604
--- /dev/null
+++ b/examples/trash/__bullet_algos.rb
@@ -0,0 +1,225 @@
+# -*- coding: utf-8 -*-
+$LOAD_PATH << ".." if $0 == __FILE__
+require "shooting"
+
+# 狙い撃ち弾
+# n-way弾
+# 円形弾
+# 分裂弾
+# 誘導弾
+# 誘導レーザー
+# ミサイル
+# 加速弾
+# 落下弾
+# 狙い撃ち弾+回転弾      # 回転弾が自機を狙う
+# 渦巻き弾
+# 停止する誘導弾
+# 直進するビーム
+
+module BulletDir
+  def compute
+    super
+    @target_dir = Fee.angle(@x, @y, @target.x, @target.y)
+  end
+end
+
+module BulletNeraiutidan
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K1) || (joy && joy.button(0))
+      if @count.modulo(60 / 10).zero?
+        @win.bullets << Bullet.new(@win, @x, @y, @target_dir, 5.00)
+      end
+    end
+  end
+end
+
+class Bullet2 < BulletBase
+  include CircleGrid
+
+  def initialize(target, *args)
+    @target = target
+    super(*args)
+  end
+
+  def compute
+    compute_sincos
+    unless @win.pause_mode
+      if @count.modulo(1).zero?
+        d = Fee.angle(@x, @y, @target.x, @target.y)
+        gap = (d - @dir) % 1.00
+        if gap >= 0.5
+          sign = -1
+        else
+          sign = +1
+        end
+        @dir = (@dir + (1.0 / 256) * sign) % 1.0
+        @cx = @x
+        @cy = @y
+        @radius = @speed
+        @speed += 0.1
+      end
+    end
+  end
+end
+
+module BulletTuibi
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K2) || (joy && joy.button(1))
+      div, mod = @count.divmod(60 / 10)
+      if mod.zero?
+        wide = 2
+        @win.bullets << Bullet2.new(@target, @win, @x, @y, @target_dir + rand * 1.0 / wide - 1.0 / (wide * 2), 1.0)
+      end
+    end
+  end
+end
+
+module Bullet3waydan
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K4) || (joy && joy.button(2))
+      if @count.modulo(60 / 5).zero?
+        gap = 1.0 / 64
+        n = 3
+        n.times{|i|
+          d = @target_dir - (n / 2 * gap) + gap * i
+          @win.bullets << Bullet.new(@win, @x, @y, d, 5.00)
+        }
+      end
+    end
+  end
+end
+
+module BulletRandom
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K3) || (joy && joy.button(3))
+      if @count.modulo(60 / 20).zero?
+        z = 1.0 / 24
+        d = @target_dir + (rand * z - z / 2) * 2
+        @win.bullets << Bullet.new(@win, @x, @y, d, 7)
+      end
+    end
+  end
+end
+
+module BulletUzumaki
+  def initialize(*)
+    super
+    @uzumaki_count = 0
+  end
+
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K5) || (joy && joy.button(4))
+      div, mod = @count.divmod(60 / 20)
+      if mod.zero?
+        n = 4
+        n.times{|i|
+          d = 1.0 / n * i + (Fee.sin(1.0 / 32 * div) * 0.1)
+          @win.bullets << Bullet.new(@win, @x, @y, d, 2)
+        }
+      end
+    end
+  end
+end
+
+module BulletUzumakix2
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K6) || (joy && joy.button(5))
+      div, mod = @count.divmod(60 / 10)
+      if mod.zero?
+        uzumaki2(div, +1)
+        uzumaki2(div, -1)
+      end
+    end
+  end
+
+  def uzumaki2(count, sign)
+    n = 5
+    gap = 1.0 / n
+    n.times{|i|
+      d = (n / 2 * gap) + gap * i + (count * 1.0 / 120 * sign) + (count * 0.001)
+      @win.bullets << Bullet.new(@win, @x, @y, d, 2.0)
+    }
+  end
+end
+
+module Bullet128waydan
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K7) || (joy && joy.button(6))
+      if @count.modulo(60 / 2).zero?
+        n = 64
+        gap = 1.0 / n
+        n.times{|i|
+          @win.bullets << Bullet.new(@win, @x, @y, gap * i, 4.00)
+        }
+      end
+    end
+  end
+end
+
+module BulletUzumakix2Fast
+  def compute
+    super
+    if @win.press_button?(SDL::Key::K8) || (joy && joy.button(7))
+      div, mod = @count.divmod(60 / 20)
+      if mod.zero?
+        uzumaki2fast(div, +1)
+        uzumaki2fast(div, -1)
+      end
+    end
+  end
+
+  def uzumaki2fast(count, sign)
+    n = 3
+    gap = 1.0 / n
+    n.times{|i|
+      d = (n / 2 * gap) + gap * i + (count * 1.0 / 120 * sign) + (count * 0.001)
+      @win.bullets << Bullet.new(@win, @x, @y, d, 6.0)
+    }
+  end
+end
+
+class GunShipA < GunShip1
+  include BulletDir
+  include BulletNeraiutidan
+  include BulletTuibi
+  include Bullet3waydan
+  include BulletRandom
+  include BulletUzumaki
+  include BulletUzumakix2
+  include Bullet128waydan
+  include BulletUzumakix2Fast
+end
+
+class GunShipB < GunShip2
+  include BulletDir
+  include BulletNeraiutidan
+  include BulletTuibi
+  include Bullet3waydan
+  include BulletRandom
+  include BulletUzumaki
+  include BulletUzumakix2
+  include Bullet128waydan
+  include BulletUzumakix2Fast
+end
+
+class Application < WarSpace
+  def initialize
+    super
+    @draw_inst = Stylet::Sdl::Draw.instance
+    ship1 = GunShipA.new(self, @draw_inst.width / 2, @draw_inst.height / 8 * 1)
+    ship2 = GunShipB.new(self, @draw_inst.width / 2, @draw_inst.height / 8 * 7)
+    ship1.target = ship2
+    ship2.target = ship1
+    @ships << ship1
+    @ships << ship2
+  end
+end
+
+Application.new.run