[SOLUTION] The Golden Fibonacci Ratio (#69)

D

David Tran

Simple Tk version.
"Inifinite" steps (rectangles);
press "Space" bar for each step;
automatic increase scroll region.



require 'tk'

class GoldenRect
include Enumerable
def initialize
@w =3D @h =3D 1
end

def each
inc_w =3D true
loop do
yield [@w, @h]
inc_w ? (@w +=3D @h) : (@h +=3D @w)
inc_w =3D !inc_w
end
end
end

canvas =3D TkCanvas.new() {
xscrollbar(sb_x =3D TkScrollbar.new)
yscrollbar(sb_y =3D TkScrollbar.new)
Tk.grid( self, sb_y, :sticky=3D>:news )
Tk.grid( sb_x, 'x', :sticky=3D>:we )
TkGrid.rowconfigure(Tk.root, 0, :weight=3D>1)
TkGrid.columnconfigure(Tk.root, 0, :weight=3D>1)
}

thread =3D Thread.new(canvas) { |c|
mx =3D my =3D 5 # margin x, y
sx =3D sy =3D 10 # rectangle unit scale
GoldenRect.new.each do |w, h|
c.create(TkcRectangle, mx, my, mx + (w * sx), my + (h * sy))
c.scrollregion([0, 0, (2 * mx) + (w * sx), (2 * my) + (h * sy)])
sleep
end
}

TkRoot.bind('space', proc { thread.wakeup })
Tk.mainloop



__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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top