require 'thread' require 'drb' require 'gtk' require 'mandel_m' DefaultMaxDepth = 30 DefaultSX = -2.25 DefaultSY = 1.75 DefaultZoom = 3.5 Width = 400 Height = 400 def arg_zoom zoom(Float(ARGV[0]), Float(ARGV[1]), Float(ARGV[2])) end def zoom(s_re, s_im, zoom_rate) dx = zoom_rate / Width dy = zoom_rate / Height [s_re, dx, s_im, dy, (60*Math.sqrt(Math.sqrt(Math.sqrt(zoom_rate)))).to_i] end def make_tuple(m, y0, y1) ['mandel', DRb.uri, m.to_a, y0, y1] end def calc_rows_preview(m, preview) uri, y0, y1, buf = $ts.in([DRb.uri, nil, nil, nil]) line = "\0" *(m.width * 3) for y in y0..y1 off = (y - y0) *m.width*3 line[0,m.width*3] = buf[off,m.width*3] preview.draw_row(line, 0, y, m.width) preview.draw(nil) end end def calc_internal(preview) depth = x = y = i = idx = 0 color_max = $color_max if ARGV.size == 3 s_re, dx, s_im, dy, max_depth = arg_zoom else s_re, dx, s_im, dy, max_depth = zoom(DefaultSX, DefaultSY, DefaultZoom) end $done = false m = MandelArgs.new(Width, Height, s_re, s_im, dx, dy, max_depth) step = 10 y0 = 0 y1 = step count = 0 tuples = [] while y0 < Height tuples.push make_tuple(m, y0, y1) count += 1 y0 = y0 + step y1 = ([y1 + step, Height - 1].min) end $ts.out(*tuples) count.times do |c| calc_rows_preview(m, preview) end $done = true exit end def calc(preview) $th = Thread.start { begin calc_internal(preview) rescue p $! exit end } end there = ARGV.shift unless there $stderr.puts("usage: #{$0} ") exit 1 end DRb.start_service() $ts = DRbObject.new(nil, there) window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL) window.set_title("mandel") preview = Gtk::Preview::new(Gtk::PREVIEW_COLOR) preview.size(Width, Height) window.add(preview) preview.show window.show calc(preview) Gtk::main()