diff options
Diffstat (limited to 'shelves.hs')
-rw-r--r-- | shelves.hs | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -3,37 +3,52 @@ import Control.Lens | |||
3 | import Data.List | 3 | import Data.List |
4 | import GenSCAD | 4 | import GenSCAD |
5 | 5 | ||
6 | shelf_thickness :: Double | ||
6 | shelf_thickness = 0.5 | 7 | shelf_thickness = 0.5 |
8 | shelf_width :: Double | ||
7 | shelf_width = 8 | 9 | shelf_width = 8 |
10 | shelf_length :: Double | ||
8 | shelf_length = 36 * 2 | 11 | shelf_length = 36 * 2 |
12 | shelf_dim :: V3 Double | ||
9 | shelf_dim = V3 shelf_length shelf_width shelf_thickness | 13 | shelf_dim = V3 shelf_length shelf_width shelf_thickness |
10 | 14 | ||
15 | shelf_heights :: [Double] | ||
11 | shelf_heights = [12, 10, 8, 8, 8, 8, 8] | 16 | shelf_heights = [12, 10, 8, 8, 8, 8, 8] |
12 | 17 | ||
13 | -- working algorithm doing the same as `scanl (+) 0 shelf_heights` | 18 | -- working algorithm doing the same as `scanl (+) 0 shelf_heights` |
14 | --acc [] = [0] | 19 | --acc [] = [0] |
15 | --acc xs = acc(init xs) ++ [sum xs] | 20 | --acc xs = acc(init xs) ++ [sum xs] |
16 | 21 | ||
22 | shelf_height :: Double | ||
17 | shelf_height = (sum shelf_heights) + (shelf_dim ^. _z * (fromIntegral (length shelf_heights) + 1)) | 23 | shelf_height = (sum shelf_heights) + (shelf_dim ^. _z * (fromIntegral (length shelf_heights) + 1)) |
18 | 24 | ||
25 | side_dim :: V3 Double | ||
19 | side_dim = V3 0.5 shelf_width shelf_height | 26 | side_dim = V3 0.5 shelf_width shelf_height |
20 | 27 | ||
21 | --shelf_y_poss = scanl (+) 0 shelf_heights | 28 | --shelf_y_poss = scanl (+) 0 shelf_heights |
29 | shelf_y_poss :: [Double] | ||
22 | shelf_y_poss = scanl (+) 0 [h+shelf_thickness| h <- shelf_heights] | 30 | shelf_y_poss = scanl (+) 0 [h+shelf_thickness| h <- shelf_heights] |
31 | shelves_pos :: [V3 Double] | ||
23 | shelves_pos = [V3 (side_dim ^. _x) 0 y | y <- shelf_y_poss] | 32 | shelves_pos = [V3 (side_dim ^. _x) 0 y | y <- shelf_y_poss] |
33 | shelves :: [(V3 Double, V3 Double)] | ||
24 | shelves = [(p, shelf_dim) | p <- shelves_pos] | 34 | shelves = [(p, shelf_dim) | p <- shelves_pos] |
25 | 35 | ||
26 | --sides = [(V3 0 0 0, side_dim), (V3 (side_dim ^. _x + shelf_length) 0 0, side_dim)] | 36 | --sides = [(V3 0 0 0, side_dim), (V3 (side_dim ^. _x + shelf_length) 0 0, side_dim)] |
37 | sides_pos :: [V3 Double] | ||
27 | sides_pos = [V3 0 0 0, V3 (side_dim ^. _x + shelf_length) 0 0] | 38 | sides_pos = [V3 0 0 0, V3 (side_dim ^. _x + shelf_length) 0 0] |
39 | sides :: [(V3 Double, V3 Double)] | ||
28 | sides = [(p, side_dim) | p <- sides_pos] | 40 | sides = [(p, side_dim) | p <- sides_pos] |
29 | 41 | ||
30 | --V3_to_string v = drop 3 (show v) | 42 | --V3_to_string v = drop 3 (show v) |
31 | 43 | ||
44 | _V32l :: R3 t => t a -> [a] | ||
32 | _V32l v3 = [v3 ^. _x, v3 ^. _y, v3 ^. _z] | 45 | _V32l v3 = [v3 ^. _x, v3 ^. _y, v3 ^. _z] |
46 | _V32s :: (Show a, R3 t) => t a -> [Char] | ||
33 | _V32s v3 = intercalate ", " (map show (_V32l v3)) | 47 | _V32s v3 = intercalate ", " (map show (_V32l v3)) |
34 | --scad_place (p,d) = "translate([ " ++ _V32s(p) ++ " ]) { cube([ " ++ _V32s(d) ++ " ]);}" | 48 | --scad_place (p,d) = "translate([ " ++ _V32s(p) ++ " ]) { cube([ " ++ _V32s(d) ++ " ]);}" |
35 | --genscad objs = concat $ map (++ "\n") $ map scad_place objs | 49 | --genscad objs = concat $ map (++ "\n") $ map scad_place objs |
36 | 50 | ||
51 | scadshelf :: String | ||
37 | scadshelf = genscad $ shelves ++ sides | 52 | scadshelf = genscad $ shelves ++ sides |
38 | 53 | ||
39 | --gen_shelf :: [Fractional] -> Fractional -> Fractional -> [Char] | 54 | --gen_shelf :: [Fractional] -> Fractional -> Fractional -> [Char] |
@@ -41,6 +56,7 @@ scadshelf = genscad $ shelves ++ sides | |||
41 | 56 | ||
42 | 57 | ||
43 | 58 | ||
59 | main :: IO () | ||
44 | main = do putStrLn scadshelf | 60 | main = do putStrLn scadshelf |
45 | 61 | ||
46 | 62 | ||