[#14715] HTTP Client with Ruby — TAKAHASHI Masayoshi <maki@...>
高橋征義です。
なひです.
高橋征義です。
ごとけんです
なひです.
高橋です。みなさまどうもありがとうございます。
なひです.
前橋です。
なひです.
なひです.すいません,駄目です.^^;
[#14747] Ruby-gtk の Text Widget について — Takano Naoki <takanon@...>
はじめまして。
[#14763] do end + do end — Wakou Aoyama <wakou@...>
青山です。
[#14765] ruby 1.3.4 with ipv6 — Yasunari Momoi <momo@...>
ruby 1.3.4 を入れたんですが,IPv6 対応しているんですね (^^).
[#14766] ruby 1.3.4 on BSD/OS 3.1 — Yasunari Momoi <momo@...>
BSD/OS 3.1 (with kame) で ruby-1.3.4 を作ろうとしているんで
まつもと ゆきひろです
前田です。
わたなべです.
[#14790] Microsoft Perl ? — ARIMA Yasuhiro <fit0298@...>
有馬です。
[#14833] Regacy scripts depend the ruby old version. — ARIMA Yasuhiro <fit0298@...>
有馬です。
[#14842] texinfo document for ruby-1.3 — Koji Arai <JCA02266@...>
新井です。
まつもと ゆきひろです
新井です。
From: Koji Arai <JCA02266@nifty.ne.jp>
[#14854] Rubyfaq-990607 — Akira Endo <akendo@...3.rim.or.jp>
遠藤です.
[#14860] CVSup server — Yasuhiro Fukuma <yasuf@...>
福間%未読メールどっさり@福岡 です。
[#14863] OO Software Construction by Meyer — Akira Endo <akendo@...3.rim.or.jp>
遠藤です.
[#14874] ruby-gtk trouble — Jun Adachi <adachi@...>
安達@沖データと申します。
[#14900] Rubyfaq-990608 — Akira Endo <akendo@...3.rim.or.jp>
遠藤です.
[#14917] Ruby/Tk and Threads — Tomoyuki Kosimizu <greentea@...2.so-net.ne.jp>
こんにちは、越水です。
[#14953] 男親なら誰でも思う — 中村暁史 <anakamur@...>
[#14957] textarea with CGI.rb — HATTORI Masashi <hattori@...>
服部といいます。こんにちは。
[#14970] thread with curses — HATTORI Masashi <hattori@...>
服部といいます。こんにちは。
[#14980] 初期化メソッドの追加 — ARIMA Yasuhiro <fit0298@...>
有馬です。
[#15003] 文字列から数値への変換失敗を検出したい — ARIMA Yasuhiro <fit0298@...>
有馬です。
[#15012] ext ML の過去ログはいずこ? — 中村暁史 <anakamur@...>
原です。
akaishi です。
わたなべです.
前田です。
[#15045] mail library — Minero Aoki <aamine@...>
あおきです。
あおきです。
あおきです。
まつもと ゆきひろです
わたなべです.
まつもと ゆきひろです
石橋秀仁です.
あおきです。
まつもと ゆきひろです
あおきです。
なひです.
あおきです。
なひです.
松尾です。
なひです.
松尾です。
有馬@FITECです。
松尾です。
はじめまして、岩間です。
なひです.mod_rubyと格闘中です.
なひです.mod_rubyネタはruby-listでよいでしょうか?
前田です。
なひです.
前田です。
なひです.
小松です。
前田です。
小松です。
前田です。
小松です。
前田です。
小松です。
まつもと ゆきひろです
たむら です。
あおきです。
まつもと ゆきひろです
あおきです。
まつもと ゆきひろです
あおきです。
[#15057] 複雑?な構造体の定義方法 — Koichi Shigematsu <shige@...>
しげまつ と申します。 とっても久しぶりの投稿です。
まつもと ゆきひろです
しげまつ です。
まつもと ゆきひろです
ごとけんです
まつもと ゆきひろです
ごとけんです
まつもと ゆきひろです
In message "[ruby-list:15078] Re: pattern (Re: 複雑?な構造体の定義方法)"
[#15093] String#rindex with arbitrary starting point — kjana@... (YANAGAWA Kazuhisa)
「String#rindex の第二引数ってば,探索を『始める』ポイントじゃなくて
前田です。
[#15112] pty on NeXTSTEP3.3J — SHIROYAMA Takayuki <psi@...>
[#15116] irb & ruby — Takashi Nishimoto <g96p0935@...>
ruby の最新版 (990625) を /usr/local 以下にインストールしたのですが、
[#15121] ruby-gtk-0.19 released — Hiroshi Igarashi <igarashi@...>
いがらし%Ruby/GTKメンテナ です。
From: Hiroshi Igarashi <igarashi@ueda.info.waseda.ac.jp>
いがらしです。
[#15131] game of life: ruby/gtk version — Takahiro Maebashi <maebashi@...>
前橋です。
[#15160] undefined method `-@' for Fixnum (NameError) — Tomoyuki Kosimizu <greentea@...2.so-net.ne.jp>
こんにちは、越水です。
まつもと ゆきひろです
[ruby-list:15131] game of life: ruby/gtk version
前橋です。
昔、ruby/tk を使ってライフゲームを作りましたが、それの ruby/gtk バージョ
ンを作ってみました。使い方は tk 版と同じです。見ればわかるでしょう。
tk 用のコードも残っているので、
view = GtkLifeGame.new
という部分を
view = TkLifeGame.new
にすれば ruby/tk でも動きます。
----------------------------------------------------------------------
#! /usr/local/bin/ruby
require 'tk'
require 'gtk'
class LifeGame
def initialize view
@view = view
@width, @height = view.size
view.game = self
resize @width, @height
center = @height / 2 * @width + @width / 2
@grid[center] = true
@grid[center+1] = true
@grid[center+@width] = true
@grid[center+@width-1] = true
@grid[center+@width+@width] = true
end
def resize width, height
default = [-width-1, -width, -width+1, -1,
1, width-1, width, width+1]
@neighbors = []
@neighbors.fill default, 0, width*height
(0..width*height-1).each {|i|
x = i % width
y = i / width
if x == 0
@neighbors[i] = [-width, -width+1, 1, width, width+1]
elsif x == width-1
@neighbors[i] = [-width-1, -width, -1, width-1, width]
end
if y == 0
@neighbors[i] = @neighbors[i].clone
@neighbors[i].delete_if {|v| v < -1}
elsif y == height-1
@neighbors[i] = @neighbors[i].clone
@neighbors[i].delete_if {|v| v > 1}
end
}
@grid = {} unless @grid
oldgrid = @grid
@grid = {}
oldgrid.each_key {|k|
x = k % @width
y = k / @width
@grid[y * width + x] = true if x <= width && y <= height
}
@width, @height = [width, height]
@view.display(@grid)
end
def flip x, y
i = x + y * @width
if @grid[i]
@grid[i] = nil
else
@grid[i] = true
end
@view.display @grid
end
def nextgen
n = {}
@grid.each_key {|i|
n[i] = 0 unless n[i]
@neighbors[i].each {|pos|
if n[i+pos] then n[i+pos] += 1 else n[i+pos] = 1 end
} if @neighbors[i]
}
n.each {|i, n|
@grid[i] = if (n == 3 || @grid[i] && n == 2) then true else nil end
}
@view.display @grid
end
def run
@view.display @grid
@view.run
end
end
#----------------------------------------------------------------------
class LifeGameView
attr_accessor :game
def initialize width=80, height=80, rectsize=6
@width = width
@height = height
@rectsize = rectsize
@goflag = false
@prevgrid = {}
@rectangles = {}
end
def size
[@width, @height]
end
def run
end
def go
end
def display grid
grid.each_key {|i|
if @prevgrid[i]
@prevgrid[i] = nil
else
setrect(i)
end
}
@prevgrid.each_key {|i|
resetrect(i)
}
@prevgrid = grid.dup
end
def setrect i
end
def resetrect i
end
end
#----------------------------------------------------------------------
class TkLifeGame < LifeGameView
include Tk
def initialize parent=nil, width=80, height=80, rectsize=6
super width, height, rectsize
@canvas = TkCanvas.new(parent,
'width'=>width * rectsize,
'height'=>height * rectsize,
'borderwidth'=>1,
'relief'=>'sunken')
nextbutton = TkButton.new(parent,
'text'=>'next',
'command'=>proc {game.nextgen})
gobutton = TkButton.new(parent,
'text'=>'go',
'command'=>proc {
@goflag = !@goflag
if @goflag
gobutton.text 'stop'
go
else
gobutton.text 'go'
end
})
quitbutton = TkButton.new(parent,
'text'=>'quit',
'command'=>proc {exit})
@canvas.pack
nextbutton.pack 'side'=>'left'
gobutton.pack 'side'=>'left'
quitbutton.pack 'side'=>'right'
@canvas.bind '1', proc {|x, y|
game.flip(x / @rectsize, y / @rectsize)
update
}, '%x %y'
@after = TkAfter.new.set_start_proc(0, proc {go})
end
def run
Tk.mainloop
end
def go
game.nextgen
update
if @goflag
@after.restart
end
end
def setrect(i)
x = i % @width
y = i / @width
#klass = TkcOval
klass = TkcRectangle
@rectangles[i] = klass.new(@canvas,
x * @rectsize,
y * @rectsize,
x * @rectsize + @rectsize - 2,
y * @rectsize + @rectsize - 2,
'fill'=>'black')
end
def resetrect(i)
@rectangles[i].destroy
@rectangles[i] = nil
end
end
#----------------------------------------------------------------------
class GtkLifeGame < LifeGameView
class Canvas < Gtk::DrawingArea
def initialize
super
signal_connect('expose_event') {|w, e| expose_event w,e}
signal_connect('configure_event') {|w, e| configure_event w,e}
@buffer = nil
@bgc = nil
end
def expose_event w,e
if @buffer
rec = e.area
w.window.draw_pixmap(@bgc, @buffer, rec.x, rec.y,
rec.x, rec.y, rec.width, rec.height)
end
false
end
def clear b = @buffer
return unless b
g = b.get_geometry
@bgc = style.bg_gc(state) unless @bgc
if g[2] > 0 and g[3] > 0
b.draw_rectangle @bgc, true, 0, 0, g[2], g[3]
end
end
def configure_event w, e
g = w.window.get_geometry
if g[2] > 0 and g[3] > 0
b = Gdk::Pixmap.new(w.window, g[2], g[3], -1)
clear(b)
if @buffer
g = @buffer.get_geometry
b.draw_pixmap(@bgc, @buffer, 0, 0,
g[0], g[1], g[2], g[3])
end
@buffer = b
end
false
end
def draw_rectangle gc, fill, x1, y1, width, height
if @buffer
@buffer.draw_rectangle gc, fill, x1, y1, width, height
draw(Gdk::Rectangle.new x1, y1, width, height)
end
end
end
def initialize width=80, height=80, rectsize=6
super
window = Gtk::Window.new(Gtk::WINDOW_TOPLEVEL)
vbox = Gtk::VBox.new(false, 0)
frame = Gtk::Frame.new(nil)
frame.set_shadow_type Gtk::SHADOW_IN
@canvas = Canvas.new
@canvas.set_events Gdk::BUTTON_PRESS_MASK
@canvas.set_usize(width * rectsize, height * rectsize)
frame.add @canvas
@canvas.show
hbox = Gtk::HBox.new(false, 0)
nextbutton = Gtk::Button.new('next')
gobutton = Gtk::Button.new
golabel = Gtk::Label.new('go')
gobutton.add golabel
golabel.show
quitbutton = Gtk::Button.new('quit')
hbox.pack_start nextbutton, false, false, 0
hbox.pack_start gobutton, false, false, 0
hbox.pack_end quitbutton, false, false, 0
nextbutton.show
gobutton.show
quitbutton.show
vbox.pack_start frame, true, true, 0
vbox.pack_start hbox, false, false, 0
frame.show
hbox.show
window.add vbox
vbox.show
window.show
window.signal_connect('delete_event') {exit}
window.signal_connect('destroy_event') {exit}
@canvas.signal_connect('button_press_event') {|w, ev|
game.flip(ev.x / @rectsize, ev.y / @rectsize)
}
@canvas.signal_connect('configure_event') {|w, ev|
@width = ev.width / @rectsize
@height = ev.height / @rectsize
game.resize(ev.width / @rectsize, ev.height / @rectsize)
false
}
nextbutton.signal_connect('clicked') {game.nextgen}
gobutton.signal_connect('clicked') {
@goflag = !@goflag
if @goflag
golabel.set 'stop'
go
else
golabel.set 'go'
end
}
quitbutton.signal_connect('clicked') {exit}
@fg_gc = @canvas.style.fg_gc(Gtk::STATE_NORMAL)
@bg_gc = @canvas.style.bg_gc(Gtk::STATE_NORMAL)
end
def run
Gtk.main
end
def go
game.nextgen
if @goflag
Gtk.idle_add {go}
end
false
end
def setrect(i)
rect(i, @fg_gc)
end
def resetrect(i)
rect(i, @bg_gc)
end
def rect(i, gc)
x = i % @width
y = i / @width
@canvas.draw_rectangle(gc, true,
x * @rectsize, y * @rectsize,
@rectsize - 1, @rectsize - 1)
end
end
#----------------------------------------------------------------------
view = GtkLifeGame.new
#view = TkLifeGame.new
g = LifeGame.new(view)
g.run