#/*********************************************************** # koch.rb -- Koch (¥³¥Ã¥Û) ¶ÊÀþ #***********************************************************/ require "plotter.rb" PI = 3.141592653589793 DMAX = 0.005 $costbl = [] $sintbl = [] def koch if ($d <= DMAX) draw_rel($d * $costbl[$a % 6], $d * $sintbl[$a % 6]) else $d /= 3.0; koch(); $a += 1; koch() $a += 4; koch(); $a += 1; koch() $d *= 3 end end gr_on for $a in 0...6 $costbl[$a] = Math::cos($a * PI / 3.0) $sintbl[$a] = Math::sin($a * PI / 3.0) end move(0, 0); $d = 2; $a = 0; koch() gr_off exit 0