Cleanでコッホ曲線

書いたよ。

以下そーす

Start world  
	# testwindow = Window "TestDraw" NilLS [WindowClose (noLS closeProcess)
	                                       ,WindowViewSize size
	                                       ,WindowLook True (\_ _ -> example6)
	                                       ,WindowViewDomain { corner1=origin,corner2=maxdomain }
	                                       ]
	
	= startIO  SDI Void (snd o openWindow undef testwindow) [ProcessClose closeProcess] world	

where
	size      = { w=500, h=500 }
	origin    = zero
	maxdomain = { x=origin.x+size.w, y=origin.y+size.h }

	example6 = fst o (coch 4 {x=0,y=200} 500.0 0.0)
	
	coch :: Int Point2 Real Real *Picture -> (*Picture,Point2)
	coch level point len  degree pic
		| level == 0   = let point` = (nextPoint point len degree) in ((drawLine point point` pic), point`)
		| otherwise  //  
			           # (pic,point) = coch (level-1) point len` degree   pic         
			           # degree             = degree+60.0
			           # (pic,point) = coch (level-1) point len` degree pic   
			           # degree             = degree+240.0					   
				   # (pic,point) = coch (level-1) point len` degree  pic  
			           # degree             = degree+60.0
		               = coch (level-1) point len` degree pic
	
		where 
			nextPoint current l deg = {x=x2,y=y2}
			where
			    // 最初この関数が悪さを… entier
				x2 = point.x + toInt (l * cos (toRadian (toReal deg)))
				y2 = point.y + toInt (l * sin (toRadian (toReal deg)))
			len` = len / 3.0

 	toRadian :: Real -> Real
 	toRadian a = a * PI  / 180.0
 	toDegree :: Real -> Real
 	toDegree a = a * 180.0 / PI



おまけ
"koichi"から"i"を除くと"koch"になるどうでもいいことに気づいてしまった…
以下Haskell

filter (not . (== 'i')) "koichi"