File: mandel.rb

package info (click to toggle)
libnarray-ruby 0.5.9-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 564 kB
  • ctags: 564
  • sloc: ansic: 4,620; ruby: 1,513; python: 70; makefile: 5
file content (41 lines) | stat: -rw-r--r-- 646 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# NArray demo : Mandelbrot

require 'narray'

def mandel(w,h)
  zoom=3.5

  z = ( NArray.scomplex(w,1).indgen!/w-0.65 )*zoom + 
      ( NArray.scomplex(1,h).indgen!/h-0.5 )*(zoom*1.im)
  c = z.dup
  a = NArray.sint(h,w)
  idx = NArray.int(h,w).indgen!

  for i in 1..30
    z = z**2+c
    idx_t,idx_f = (z.abs>2).where2
    print i," size=",idx_t.size,"\n"
    ii = idx[idx_t]
    a[ii] = i
    break if idx_f.size==0
    idx = idx[idx_f]
    z = z[idx_f]
    c = c[idx_f]
  end
  a
end


#
#    TEST TEST TEST
#
if __FILE__ == $0

  require 'nimage'

  win = NImage.show mandel(400,400)

  print "Hit return key..."
  STDIN.getc
  win.close
end