Skip to content

Instantly share code, notes, and snippets.

@markroxor
Created August 30, 2020 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markroxor/661fb71a78575684026e39fed610213d to your computer and use it in GitHub Desktop.
Save markroxor/661fb71a78575684026e39fed610213d to your computer and use it in GitHub Desktop.
temp.hs
r1 = 32
c1 = 63
-- triangle :: Int -> Int -> [[Int]]
triangle r c = [[a, c, 0], [0,r,r]] where a = c/2 -- ceiling ( (fromIntegral c) /2)
-- adder :: Int -> Int -> Int -> [[Float]]
adder r c f1 = [[0, -c*f1,c*f1], [r*f1, -r*f1, -r*f1 ]]
l1 = triangle r1 c1
r1' = adder r1 c1 1
flip' l1 r1' = [zipWith (+) (l1!!0) (r1'!!0), zipWith (+) (l1!!1) (r1'!!1)]
r2' = adder r1 c1 (-1)
row' = [foldl (\acc x -> "_" ++ acc) "" [1..c1]]
rc' = foldl (\acc x -> row' ++ acc ) row' [1..r1]
-- putStrLn $ unlines rc
rotate = drop <> take -- ????!!!! how does it works
slopes l1 = [zipWith (-) (l1 !!0) (rotate 1 (l1!!0)), zipWith (-) (l1 !! 1) (rotate 1 (l1!!1))]
line (x,y) (dx,dy)
| dx == 0 = signum x
| otherwise = signum $ y - (dy/dx) * x
get l1 n = (zip (l1!!0) (l1!!1)) !! n
is_same_side_ l1 x y n = fromRational (((line (get l1 (2-n)) (get (slopes l1) n)) * (line (x,y) (get (slopes l1) n))))
-- is_same_side l1 x y = foldl1 (\acc n -> n * acc) [0..2]
-- is_same_side l1 x y = foldl1 (\acc n -> (is_same_side_ l1 x y n) * acc) [0..2]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment