2023年6月3日土曜日

シェルピンスキーのギャスケット。Haskell+Python.turtle


import HTurtle
import Data.Complex
main = do
    let p0 = (0,0)
    let p1 = (200.00000000000006,346.41016151377545)
    let p2 = (400,0)
    start
    speed 10
    shape "turtle"
    triangle [p0,p1,p2] "black" True
    sg 3 [p0,p1,p2] 
    end
sg n [a,b,c] = do
    triangle [mp0,mp1,mp2] "white" True
    if n <= 1 
    then return () 
    else do 
        sg (n-1) [a, mp0,mp2]
        sg (n-1) [b,mp0,mp1]
        sg (n-1) [c,mp2,mp1]
    where
        mp0 = mp (a,b)
        mp1 = mp (b,c)
        mp2 = mp (c,a)
mp ((a,b),(c,d)) = let (e:+f) = c2 in (e,f)
    where 
        c0 = (a:+b)  
        c1 = (c:+d)  
        c2 = (c0+c1)/2

0 件のコメント:

コメントを投稿