summaryrefslogtreecommitdiff
path: root/shelves.hs
diff options
context:
space:
mode:
Diffstat (limited to 'shelves.hs')
-rw-r--r--shelves.hs16
1 files changed, 16 insertions, 0 deletions
diff --git a/shelves.hs b/shelves.hs
index 0136e1c..b1cfd76 100644
--- a/shelves.hs
+++ b/shelves.hs
@@ -3,37 +3,52 @@ import Control.Lens
3import Data.List 3import Data.List
4import GenSCAD 4import GenSCAD
5 5
6shelf_thickness :: Double
6shelf_thickness = 0.5 7shelf_thickness = 0.5
8shelf_width :: Double
7shelf_width = 8 9shelf_width = 8
10shelf_length :: Double
8shelf_length = 36 * 2 11shelf_length = 36 * 2
12shelf_dim :: V3 Double
9shelf_dim = V3 shelf_length shelf_width shelf_thickness 13shelf_dim = V3 shelf_length shelf_width shelf_thickness
10 14
15shelf_heights :: [Double]
11shelf_heights = [12, 10, 8, 8, 8, 8, 8] 16shelf_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
22shelf_height :: Double
17shelf_height = (sum shelf_heights) + (shelf_dim ^. _z * (fromIntegral (length shelf_heights) + 1)) 23shelf_height = (sum shelf_heights) + (shelf_dim ^. _z * (fromIntegral (length shelf_heights) + 1))
18 24
25side_dim :: V3 Double
19side_dim = V3 0.5 shelf_width shelf_height 26side_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
29shelf_y_poss :: [Double]
22shelf_y_poss = scanl (+) 0 [h+shelf_thickness| h <- shelf_heights] 30shelf_y_poss = scanl (+) 0 [h+shelf_thickness| h <- shelf_heights]
31shelves_pos :: [V3 Double]
23shelves_pos = [V3 (side_dim ^. _x) 0 y | y <- shelf_y_poss] 32shelves_pos = [V3 (side_dim ^. _x) 0 y | y <- shelf_y_poss]
33shelves :: [(V3 Double, V3 Double)]
24shelves = [(p, shelf_dim) | p <- shelves_pos] 34shelves = [(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)]
37sides_pos :: [V3 Double]
27sides_pos = [V3 0 0 0, V3 (side_dim ^. _x + shelf_length) 0 0] 38sides_pos = [V3 0 0 0, V3 (side_dim ^. _x + shelf_length) 0 0]
39sides :: [(V3 Double, V3 Double)]
28sides = [(p, side_dim) | p <- sides_pos] 40sides = [(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
51scadshelf :: String
37scadshelf = genscad $ shelves ++ sides 52scadshelf = 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
59main :: IO ()
44main = do putStrLn scadshelf 60main = do putStrLn scadshelf
45 61
46 62