Title / Description
Code n=1000 #vertical and horizontal max xx=[] #array for real values of complex n.times{ |i| xx[i]=(i-500.0)/(n/5).to_f } yy=xx # array for imag values of complex max_intens=255 c=Complex(-0.35,0.6) #constant File.open("img.pgm", 'w') {|f| f.write("P2 \n# img.pgm\n#{n} #{n}\n{max_intens}\n") #image parameters #nested loops for calculating julia set n.times { |i| n.times { |j| z=Complex(xx[i],yy[j]) #current value of z iter=0 #iterator & intensity of colour that would be written while( z.abs < 2 && iter<max_intens ) z=z*z+c iter+=1 end f.write("#{max_intens-iter} ") #write to file (0 - 255) } f.write("\n") } }
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code