[SOLUTION] The Golden Fibonacci Ratio (#69)

D

David Tran

A PDF version "translate" from Christian Neukirchen's Postscript Code.
( http://www.ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/182741 )



(puts "Usage #$0 filename"; exit(1)) unless ARGV[0]

require 'pdf/writer'

pdf =3D PDF::Writer.new
pdf.translate_axis(100, 100)
s =3D 400
colors =3D [0.7, 0.5, 0.3].map { |e| Color::GrayScale.from_fraction(e) }
phi =3D (Math.sqrt(5) - 1 ) / 2

def box(i, pdf)
pdf.move_to(0,0).line_to(i,0).line_to(i,i).line_to(0,i).close_fill
pdf.move_to(0,0).line_to(i,0).line_to(i,i).line_to(0,i).close_stroke
end

style =3D pdf.stroke_style?

10.times do |i|
pdf.fill_color(colors[i % colors.size])
pdf.stroke_color(Color::RGB::Black)
box(s, pdf)
pdf.stroke_color(Color::RGB.from_fraction(0.8, 0.4, 0))
pdf.ellipse2_at(0, s, s, s, 0, -90).stroke
pdf.translate_axis(s, s)
pdf.rotate_axis(90)
pdf.scale_axis(phi, phi)
style.width /=3D phi
pdf.stroke_style!(style)
end

pdf.save_as(ARGV[0])



__END__
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top