Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
11
Task/Pythagoras-tree/Haskell/pythagoras-tree-1.hs
Normal file
11
Task/Pythagoras-tree/Haskell/pythagoras-tree-1.hs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
mkBranches :: [(Float,Float)] -> [[(Float,Float)]]
|
||||
mkBranches [a, b, c, d] = let d = 0.5 <*> (b <+> (-1 <*> a))
|
||||
l1 = d <+> orth d
|
||||
l2 = orth l1
|
||||
in
|
||||
[ [a <+> l2, b <+> (2 <*> l2), a <+> l1, a]
|
||||
, [a <+> (2 <*> l1), b <+> l1, b, b <+> l2] ]
|
||||
where
|
||||
(a, b) <+> (c, d) = (a+c, b+d)
|
||||
n <*> (a, b) = (a*n, b*n)
|
||||
orth (a, b) = (-b, a)
|
||||
3
Task/Pythagoras-tree/Haskell/pythagoras-tree-2.hs
Normal file
3
Task/Pythagoras-tree/Haskell/pythagoras-tree-2.hs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
squares = concat $ take 10 $ iterateM mkBranches start
|
||||
where start = [(0,100),(100,100),(100,0),(0,0)]
|
||||
iterateM f x = iterate (>>= f) (pure x)
|
||||
5
Task/Pythagoras-tree/Haskell/pythagoras-tree-3.hs
Normal file
5
Task/Pythagoras-tree/Haskell/pythagoras-tree-3.hs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
--import should go to the top of the code
|
||||
import Graphics.Gloss
|
||||
|
||||
main = display (InWindow "Pithagoras tree" (400, 400) (0, 0)) white tree
|
||||
where tree = foldMap lineLoop squares
|
||||
6
Task/Pythagoras-tree/Haskell/pythagoras-tree-4.hs
Normal file
6
Task/Pythagoras-tree/Haskell/pythagoras-tree-4.hs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
main = writeFile "pith.svg" svg
|
||||
where svg = "<svg " ++ attrs ++ foldMap (mkLine . close) squares ++ "</svg>"
|
||||
attrs = "fill='none' stroke='black' height='400' width='600'>"
|
||||
mkLine path = "<polyline points ='" ++ foldMap mkPoint path ++ "'/>"
|
||||
mkPoint (x,y) = show (250+x) ++ "," ++ show (400-y) ++ " "
|
||||
close lst = lst ++ [head lst]
|
||||
7
Task/Pythagoras-tree/Haskell/pythagoras-tree-5.hs
Normal file
7
Task/Pythagoras-tree/Haskell/pythagoras-tree-5.hs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
--import should go to the top of the code
|
||||
import Graphics.EasyPlot
|
||||
|
||||
--change PNG by the desired format
|
||||
main = plot (PNG "pith.png") $ map (mkLine . close) squares
|
||||
where mkLine = Data2D [Style Lines, Color Black,Title ""] []
|
||||
close lst = lst ++ [head lst]
|
||||
Loading…
Add table
Add a link
Reference in a new issue