Created
September 3, 2020 16:03
-
-
Save markroxor/f67493eda44dad233cd83cd6da89de8d to your computer and use it in GitHub Desktop.
temp2.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r1 = 32 | |
c1 = 63 | |
-- triangle :: Int -> Int -> [[Int]] | |
-- ciel x | |
triangle r c = [[a, c, 0], [0,r,r]] where a = (c/2) -- ceiling ( (fromInteigral 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))] | |
fromBool x | |
| x == True = 0 | |
| x == False = -1 | |
line (x', y') (x,y) (dx,dy) | |
| dx == 0 = case x of { | |
0 -> fromBool $ (&&) ((&&) (x' >= (min x x2)) (x' <= (max x x2))) ((&&) (y' >= (min y y2)) (y' <= (max y y2))); | |
x -> x; | |
} | |
| otherwise = signum $ y' - m * x' - c | |
where | |
m = dy/dx | |
c = y - m*x | |
x2 = x-dx | |
y2 = y-dy | |
-- () | (signum x'-x) == 0 | |
get l1 n = (zip (l1!!0) (l1!!1)) !! n | |
is_same_side_ l1 x y n = (((line (get l1 ((n-1) `mod` 3)) (get l1 n) (get (slopes l1) n)) * (line (x,y) (get l1 n) (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] | |
printables = ['_', '1'] | |
is_same_side l1 x y f1 | |
| prod == 0 = (printables !! (f1 `mod` 2)) | |
| prod == 1 = (printables !! (f1 `mod` 2)) | |
| otherwise = (printables !! ((f1+1) `mod` 2)) | |
where | |
prod = (is_same_side_ l1 x y 0) * (is_same_side_ l1 x y 1) * (is_same_side_ l1 x y 2) | |
test_tr = [[0, 0, 3], [0.0, 4.0, 0.0]] | |
-- putStrLn $ unlines [[is_same_side l1 x y | (x,y) <- zip [1..c1] [i,i..]] | i <- [0..r1] ] | |
l2 = l1 | |
stage1 l1 = [[is_same_side l1 x y 1 | (x,y) <- zip [1..c1] [i,i..]] | i <- [0..r1] ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment