This commit is contained in:
2024-11-09 18:42:52 +03:00
commit 2e7c02ca85
6 changed files with 144 additions and 0 deletions

33
lab2/fern_with_mod.hs Normal file
View File

@@ -0,0 +1,33 @@
-- Не работает, потому что важно именно в случайном порядке применять трансформации
type Point = (Float, Float)
transformation1 :: Point -> Point
transformation1 (_, y) = (0, 0.16 * y)
transformation2 :: Point -> Point
transformation2 (x, y) = (0.85 * x + 0.04 * y, -0.04 * x + 0.85 * y + 1.6)
transformation3 :: Point -> Point
transformation3 (x, y) = (0.2 * x - 0.26 * y, 0.23 * x + 0.22 * y + 1.6)
transformation4 :: Point -> Point
transformation4 (x, y) = (-0.15 * x + 0.28 * y, 0.26 * x + 0.24 * y + 0.44)
applyTransformation :: Point -> Int -> Point
applyTransformation (x, y) n
| r == 0 = transformation1 (x, y)
| r <= 85 = transformation2 (x, y)
| r <= 92 = transformation3 (x, y)
| otherwise = transformation4 (x, y)
where
r = n `mod` 100
barnsleyFern :: Point -> Int -> [Point]
barnsleyFern _ 0 = []
barnsleyFern point n = point : barnsleyFern (applyTransformation point n) (n - 1)
main :: IO ()
main = do
let fractal = barnsleyFern (0, 0) 1000
print fractal