0hc.net Menu
Home Overview
About Menu
Impressum

Sierpinski Gasket

require 'tk' class Draw def transform(abb) @xlinks[@stufe] = @a[abb] * @xlinks[@stufe+1] + @e[abb] @ylinks[@stufe] = @d[abb] * @ylinks[@stufe+1] + @f[abb] @xrechts[@stufe] = @a[abb] * @xrechts[@stufe+1] + @e[abb] @yrechts[@stufe] = @d[abb] * @yrechts[@stufe+1] + @f[abb] @xoben[@stufe] = @a[abb] * @xoben[@stufe+1] + @e[abb] @yoben[@stufe] = @d[abb] * @yoben[@stufe+1] + @f[abb] zeichne() end def verzweige() @stufe -= 1 (1..3).each {|i| transform(i)} @stufe +=1 end def zeichne() verzweige() if @stufe > 1 TkcLine.new(@canvas, @links+@xlinks[1], @wl-@ylinks[1], @links+@xrechts[1], @wl-@yrechts[1]).fill('black') TkcLine.new(@canvas, @links+@xrechts[1], @wl-@yrechts[1], @links+@xoben[1], @wl-@yoben[1]).fill('black') TkcLine.new(@canvas, @links+@xoben[1], @wl-@yoben[1], @links+@xlinks[1], @wl-@ylinks[1]).fill('black') end def amz(i) x = [] (1..i).each {|j| x[j]=0} return x end def initialize root = TkRoot.new { title "MVKM Iteration" } @canvas = TkCanvas.new(root) @canvas.height(600) @canvas.width(600) @canvas.pack @stufe = 8 @xlinks = amz(@stufe+1).dup @xrechts = amz(@stufe+1).dup @xoben = amz(@stufe+1).dup @ylinks = amz(@stufe+1).dup @yrechts = amz(@stufe+1).dup @yoben = amz(@stufe+1).dup @a = amz(3).dup @b = amz(3).dup @c = amz(3).dup @d = amz(3).dup @e = amz(3).dup @f = amz(3).dup @links = 50 @w = 500 @wl = @w + @links @xlinks[@stufe] = 0 @ylinks[@stufe] = 0 @xrechts[@stufe] = @w @yrechts[@stufe] = 0 @xoben[@stufe] = 0.5*@w @yoben[@stufe] = @w @a[1] = 0.5; @a[2] = 0.5; @a[3] = 0.5 @b[1] = 0.0; @b[2] = 0.0; @b[3] = 0.0 @c[1] = 0.0; @c[2] = 0.0; @c[3] = 0.0 @d[1] = 0.5; @d[2] = 0.5; @d[3] = 0.5 @e[1] = 0.0; @e[2] = 0.5*@w; @e[3] = 0.25*@w @f[1] = 0.0; @f[2] = 0.0; @f[3] = 0.5*@w zeichne() end end Draw.new Tk.mainloop
0hc.net    © 2001-2014 Harald Wolfsgruber