GTK+で落書き 4(Ruby)

引き続き Gem 'oekaki' で落書きです。
oekaki | RubyGems.org | your community gem host
GTK+でお絵かきしてみた(Ruby) - Camera Obscura



Ruby コード。

require 'oekaki'
include Math

L = 300; O = L / 2
R = 140
step = 20

i = 0

Oekaki.app width: L, height: L do
  draw do
    color(0, 0, 0)
    rectangle(true, 0, 0, L, L)
    color(0x87 * 256, 0xce * 256, 0xeb * 256)    #skyblue
    arc(false, O - R, O - R, R * 2, R * 2, 0, 64 * 360)
  end
  
  id = timer(500) do
    ar = []
    θ = i * step * PI / 180
    x = R * cos(θ)
    y = R * sin(θ)
    ar << [O + x, O - y]
    3.times do
      x, y = -y, x
      ar << [O + x, O - y]
    end
    color(0x22 * 256, 0x8b * 256, 0x22 * 256)    #forestgreen
    polygon(false, ar)
    i += 1
    Gtk.timeout_remove(id) if i * step > 180
    true
  end
end