[#14715] HTTP Client with Ruby — TAKAHASHI Masayoshi <maki@...>

高橋征義です。

32 messages 1999/06/01
[#14834] Re: HTTP Client with Ruby — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/06/05

なひです.

[#14836] Re: HTTP Client with Ruby — TAKAHASHI Masayoshi <maki@...> 1999/06/05

高橋征義です。

[#14858] Re: HTTP Client with Ruby — gotoken@... (GOTO Kentaro) 1999/06/07

ごとけんです

[#14896] Re: HTTP Client with Ruby — TAKAHASHI Masayoshi <maki@...> 1999/06/07

高橋です。みなさまどうもありがとうございます。

[#14907] Re: HTTP Client with Ruby — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/06/08

なひです.

[#14766] ruby 1.3.4 on BSD/OS 3.1 — Yasunari Momoi <momo@...>

BSD/OS 3.1 (with kame) で ruby-1.3.4 を作ろうとしているんで

18 messages 1999/06/03
[#14770] Re: ruby 1.3.4 on BSD/OS 3.1 — matz@... (Yukihiro Matsumoto) 1999/06/03

まつもと ゆきひろです

[#15012] ext ML の過去ログはいずこ? — 中村暁史 <anakamur@...>

22 messages 1999/06/16
[#15013] Re: ext ML の過去ログはいずこ? — Shin-ichiro Hara <sinara@...> 1999/06/16

原です。

[#15014] Re: ext ML の過去ログはいずこ? — 中村暁史 <anakamur@...> 1999/06/16

[#15015] Re: ext ML の過去ログはいずこ? — Kazunori Akaishi <akaishi@...> 1999/06/16

akaishi です。

[#15016] Re: ext ML の過去ログはいずこ? — 中村暁史 <anakamur@...> 1999/06/16

[#15045] mail library — Minero Aoki <aamine@...>

あおきです。

96 messages 1999/06/20
[#15075] Re: mail library — Minero Aoki <aamine@...> 1999/06/22

あおきです。

[#15122] Re: mail library — Minero Aoki <aamine@...> 1999/06/28

あおきです。

[#15123] Re: mail library — matz@... (Yukihiro Matsumoto) 1999/06/28

まつもと ゆきひろです

[#15125] Re: mail library — WATANABE Hirofumi <watanabe@...> 1999/06/28

わたなべです.

[#15126] Re: mail library — matz@... (Yukihiro Matsumoto) 1999/06/28

まつもと ゆきひろです

[#15146] Re: mail library — Minero Aoki <aamine@...> 1999/06/29

あおきです。

[#15148] Re: mail library — matz@... (Yukihiro Matsumoto) 1999/06/29

まつもと ゆきひろです

[#15161] Re: mail library — Minero Aoki <aamine@...> 1999/06/30

あおきです。

[#15165] Re: mail library — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/06/30

なひです.

[#15167] Re: mail library — Minero Aoki <aamine@...> 1999/06/30

あおきです。

[#15219] Re: mail library — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/07/03

なひです.

[#15228] Re: mail library — hisanori@... 1999/07/05

松尾です。

[#15279] Re: mail library — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/07/07

なひです.

[#15172] Re:mail library — Takeo Iwama <iwamat@...> 1999/07/01

はじめまして、岩間です。

[#15218] JUS workshop ( was Re:mail library ) — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/07/03

なひです.mod_rubyと格闘中です.

[#15220] Mod_ruby server does not respond when POST request. — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/07/03

なひです.mod_rubyネタはruby-listでよいでしょうか?

[#15226] Re: Mod_ruby server does not respond when POST request. — Shugo Maeda <shugo@...> 1999/07/05

前田です。

[#15240] mod_ruby/0.1.2 with Apache/1.3.6 on Solaris/2.5.1 ( was Re: Mod_ruby server does not respond when POST request. ) — "NAKAMURA, Hiroshi" <nakahiro@...> 1999/07/05

なひです.

[#15242] Re: mod_ruby/0.1.2 with Apache/1.3.6 on Solaris/2.5.1 ( was Re: Mod_ruby server does not respond when POST request. ) — Shugo Maeda <shugo@...> 1999/07/05

前田です。

[#15308] Re: mod_ruby/0.1.2 with Apache/1.3.6 on Solaris/2.5.1 — Katsuyuki Komatsu <komatsu@...> 1999/07/08

小松です。

[#15310] Re: mod_ruby/0.1.2 with Apache/1.3.6 on Solaris/2.5.1 — Shugo Maeda <shugo@...> 1999/07/08

前田です。

[#15313] Re: mod_ruby/0.1.2 with Apache/1.3.6 on Solaris/2.5.1 — Katsuyuki Komatsu <komatsu@...> 1999/07/08

小松です。

[#15057] 複雑?な構造体の定義方法 — Koichi Shigematsu <shige@...>

しげまつ と申します。  とっても久しぶりの投稿です。

18 messages 1999/06/21
[#15058] Re: 複雑?な構造体の定義方法 — matz@... (Yukihiro Matsumoto) 1999/06/21

まつもと ゆきひろです

[#15059] Re: 複雑?な構造体の定義方法 — Koichi Shigematsu <shige@...> 1999/06/21

しげまつ です。

[#15061] Re: 複雑?な構造体の定義方法 — matz@... (Yukihiro Matsumoto) 1999/06/21

まつもと ゆきひろです

[#15065] pattern (Re: 複雑?な構造体の定義方法) — gotoken@... (GOTO Kentaro) 1999/06/21

ごとけんです

[#15076] Re: pattern (Re: 複雑?な構造体の定義方法) — matz@... (Yukihiro Matsumoto) 1999/06/22

まつもと ゆきひろです

[#15077] Re: pattern (Re: 複雑?な構造体の定義方法) — gotoken@... (GOTO Kentaro) 1999/06/22

ごとけんです

[ruby-list:15131] game of life: ruby/gtk version

From: Takahiro Maebashi <maebashi@...>
Date: 1999-06-28 05:18:22 UTC
List: ruby-list #15131
前橋です。

昔、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

In This Thread

Prev Next