[#1381] bound method — shugo@... (Shugo Maeda)

前田です。

21 messages 1998/02/04
[#1383] Re: bound method — matz@... (Yukihiro Matsumoto) 1998/02/05

まつもと ゆきひろです

[#1384] Re: bound method — keiju@... (石塚圭樹 ) 1998/02/05

けいじゅ@日本ラショナルソフトウェアです.

[#1385] Re: bound method — matz@... (Yukihiro Matsumoto) 1998/02/05

まつもと ゆきひろです

[#1387] Re: bound method — keiju@... (石塚圭樹 ) 1998/02/05

けいじゅ@日本ラショナルソフトウェアです.

[#1388] Re: bound method — matz@... (Yukihiro Matsumoto) 1998/02/05

まつもと ゆきひろです

[#1389] Re: bound method — keiju@... (石塚圭樹 ) 1998/02/05

けいじゅ@日本ラショナルソフトウェアです.

[#1396] Re: bound method — matz@... (Yukihiro Matsumoto) 1998/02/06

まつもと ゆきひろです

[#1410] GD — Masao Kanemitsu <masao-k@...>

30 messages 1998/02/10
[#1411] Re: GD — matz@... (Yukihiro Matsumoto) 1998/02/10

まつもと ゆきひろです

[#1413] Re: GD — WATANABE Hirofumi <watanabe@...> 1998/02/10

わたなべです.

[#1417] Re: GD — Masao Kanemitsu <masao-k@...> 1998/02/10

<199802100623.PAA03533@eban.ase.ptg.sony.co.jp> の、

[#1420] Re: GD — WATANABE Hirofumi <watanabe@...> 1998/02/10

わたなべです.

[#1426] Re: GD — Masao Kanemitsu <masao-k@...> 1998/02/10

<199802100733.QAA04028@eban.ase.ptg.sony.co.jp> の、

[#1428] Re: GD — WATANABE Hirofumi <watanabe@...> 1998/02/10

わたなべです.

[#1429] Re: GD — Masao Kanemitsu <masao-k@...> 1998/02/10

<199802100757.QAA04212@eban.ase.ptg.sony.co.jp> の、

[#1431] Re: GD — WATANABE Hirofumi <watanabe@...> 1998/02/10

わたなべです.

[#1434] Re: GD — Masao Kanemitsu <masao-k@...> 1998/02/12

<199802100952.SAA04346@eban.ase.ptg.sony.co.jp> の、

[#1435] Re: GD — WATANABE Hirofumi <watanabe@...> 1998/02/12

わたなべです.

[#1436] Re: GD — Masao Kanemitsu <masao-k@...> 1998/02/12

<199802120449.NAA00398@eban.ase.ptg.sony.co.jp> の、

[ruby-dev:1500] Re: tkmandel

From: Masao Kanemitsu <masao-k@...>
Date: 1998-02-19 09:01:43 UTC
List: ruby-dev #1500
<199802190520.OAA31625@picachu.netlab.co.jp> の、
   "[ruby-dev:1495] Re: tkmandel" において、
   "matz@netlab.co.jp (Yukihiro Matsumoto)"さんは書きました:

> |ズーム機能のバグ修正と手直し(ゆっくり深まるように)です:
> 
> このパッチ↓でdevided by zeroがでるようになってしまいました.
> どうしてなんでしょう?
> 
> |-  size = (d - a).abs if (size < (d - a).abs)
> |+  size = (d - b).abs if (size < (d - b).abs)


sizeが0になるような場合に、1に上げてやる必要がありますね。


> 
> さて,数回ズームすると落っこちる件ですが,毎回イメージを生成
> していた部分を流用するようにしたら,とりあえず落ちないように
> なりました.恐らくTkの内部でリークしているのだと思います.
> 
>                                 まつもと ゆきひろ /:|)

す、すごい。すごいきれいに治ってる。

すばらしいです。あと、一応、倍率が少しずつ深まるように
もう一段sqrtをかませたのと、初期値を少し上げてみました。

それから、

#   z = c = Complex(re, im)
#   for i in 0 .. $max_depth
#     z = (z * z) + c
#     break if z.abs2 > 5  ← ココ。
#   end
#   return i

の部分、以前は z.abs2 > 4 相当だったのですが、拡張モジュールになりますが
少し上げて 5 にしてやると、より深まるようです。

ありがとうございました。

M.Kanemitsu

Attachments (1)

tkmandel.rb (4.16 KB, text/x-ruby)
# require "complex"
require "mandel"
require "tkclass"
require "GD"

DefaultMaxDepth = 50
DefaultSX = -2.25
DefaultSY = 1.75
DefaultEX = 1.25
DefaultEY = -1.75

def reset
  $max_depth = DefaultMaxDepth
  $s_re = DefaultSX
  $s_im = DefaultSY
  $e_re = DefaultEX
  $e_im = DefaultEY
  $dx = ($e_re - $s_re).abs / Width
  $dy = ($e_im - $s_im).abs / Height
end


Width = 400
Height = 400

$c = Canvas.new {
       width Width
       height Height
     }
$c.pack

$c_rect = Rectangle.new($c, 0, 0, Width+1, Height+1)
$c_rect.fill "white"



$colors = []

def gd_setup
  $im = GD::Image.new(Width, Height)

  $white = $im.colorAllocate(255, 255, 255)
  $black = $im.colorAllocate(0, 0, 0)

  $im.transparent($white)
  $im.interlace = TRUE

  $color_max = 0
  for i in 0 .. 125
    $colors[$color_max] = $im.colorAllocate(250 - (i*2), i*2, 0)
    $color_max += 1
  end
  for i in 0 .. 125
    $colors[$color_max] = $im.colorAllocate(0, 250 - (i*2), i*2)
    $color_max += 1
  end
  $color_max -= 1
end


def zoom(a, b, c, d)
  center_x = (a + c) / 2
  center_y = (b + d) / 2
  size = (c - a).abs
  size = (d - b).abs if (size < (d - b).abs)
  size = 1 if (size < 1)
  zoom_rate = ((Width + Height) / 2).to_f / size
  $max_depth = ($max_depth.to_f * Math.sqrt(Math.sqrt(Math.sqrt(zoom_rate)))).to_i

  move_x_rate = (center_x - (Width / 2)).to_f / (Width / 2)
  move_y_rate = (center_y - (Height / 2)).to_f / (Height / 2)

  center_re = ($s_re + $e_re) / 2
  center_im = ($s_im + $e_im) / 2
  c_size_re = ($e_re - $s_re).abs
  c_size_im = ($e_im - $s_im).abs

  center_re = center_re + (move_x_rate * (c_size_re / 2))
  center_im = center_im - (move_y_rate * (c_size_im / 2))

  $s_re = center_re - ((c_size_re / 2) / zoom_rate)
  $s_im = center_im + ((c_size_im / 2) / zoom_rate)
  $e_re = center_re + ((c_size_re / 2) / zoom_rate)
  $e_im = center_im - ((c_size_im / 2) / zoom_rate)

  $dx = ($e_re - $s_re).abs / Width
  $dy = ($e_im - $s_im).abs / Height
end


def mandel(x, y)
  re = $s_re + ($dx * x)
  im = $s_im - ($dy * y)
#   z = c = Complex(re, im)
#   for i in 0 .. $max_depth
#     z = (z * z) + c
#     break if z.abs2 > 5
#   end
#   return i
  return Mandel.loop(re, im, $max_depth)
end

def calc
  return if $current_rect

  for x in 0 .. Width - 1
    depth = mandel(x, $calc_y)
    if depth >= $max_depth
      $im.setPixel(x, $calc_y, $black)
    else
      $im.setPixel(x, $calc_y, $colors[ $color_max * depth / $max_depth ])
    end
  end

  $calc_y += 1
  if (($calc_y % 20) == 0)
    print "#{($calc_y * 100 / Height)}% done. -- depth #{$max_depth}\n"
    open("#tmpmandel#.gif", "w") do |f|
      $im.gif(f)
    end
    unless $gif
      $gif = TkPhotoImage.new { file "#tmpmandel#.gif" }
    else
      $gif.file "#tmpmandel#.gif"
    end
    unless $mandel
      $mandel = TkcImage.new($c, Width/2, Height/2) { image $gif }
    else
      $mandel.image($gif)
    end
  end

  if ($calc_y > Height - 1)
    $calc_y = StartCalcY
    $calc_on = false
    open("#tmpmandel#.gif", "w") do |f|
      $im.gif(f)
    end
    $gif.file "#tmpmandel#.gif"
    $mandel.image($gif)
#    $gif.destroy
#    $gin = nil
  end

  if $calc_on
    Tk.after(1) { calc() }
  end
end

reset()
$calc_y = StartCalcY = 0
$calc_on = true
gd_setup()
calc()

def clear
#  $mandel.destroy if $mandel
  $calc_y = StartCalcY
end

$start_x = $start_y = 0
$current_rect = nil

def do_press(x, y)
  $start_x = x
  $start_y = y
  $current_rect = Rectangle.new($c, x, y, x, y) { outline "white" }
end

def do_motion(x, y)
  if $current_rect
    $current_rect.coords $start_x, $start_y, x, y
  end
end

def do_release(x, y)
  if $current_rect
    $current_rect.coords $start_x, $start_y, x, y
    $current_rect.destroy
    $current_rect = nil
    clear()
    $calc_on = true
    gd_setup()
    zoom($start_x, $start_y, x, y)
    calc()
  end
end

$c.bind("1", proc{|e| do_press e.x, e.y})
$c.bind("B1-Motion", proc{|x, y| do_motion x, y}, "%x %y")
$c.bind("ButtonRelease-1", proc{|x, y| do_release x, y}, "%x %y")

begin
  Tk.mainloop
ensure
  File.delete("#tmpmandel#.gif")
end

In This Thread

Prev Next