diff options
-rw-r--r-- | shelves.hs | 103 |
1 files changed, 21 insertions, 82 deletions
@@ -1,88 +1,27 @@ | |||
1 | import Control.Lens | ||
2 | import GenSCAD (genscad) | ||
3 | import Graphics.OpenSCAD | 1 | import Graphics.OpenSCAD |
4 | import Linear.V3 | ||
5 | 2 | ||
6 | data Shelf | 3 | data Shelf = Shelf { |
4 | width :: Double, | ||
5 | depth :: Double, | ||
6 | boardThickness :: Double, | ||
7 | shelfHeights :: [Double] | ||
8 | } deriving (Show) | ||
7 | 9 | ||
8 | myShelf :: Shelf | 10 | myShelf :: Shelf |
9 | myShelf = undefined | 11 | myShelf = Shelf { width = 36, depth = 8, boardThickness = 1, |
10 | 12 | shelfHeights = [12, 12, 10, 10, 6, 6, 6] } | |
11 | modelShelf :: Shelf -> Model3d | 13 | |
12 | modelShelf = undefined | 14 | modelShelf :: Shelf -> [Model3d] |
15 | modelShelf s = | ||
16 | let sidesPos = [(0,0,0), (boardThickness s + width s, 0, 0)] | ||
17 | shelvesPos = let ys = scanl (+) 0 [h + boardThickness s|h <- shelfHeights s] | ||
18 | in [ (boardThickness s, 0, y) | y <- ys ] | ||
19 | place board places = map (\p -> translate p board) places | ||
20 | in place sideBoard sidesPos ++ place shelfBoard shelvesPos | ||
21 | where shelfHeight = sum (shelfHeights s) + (boardThickness s) * | ||
22 | (fromIntegral (length $ shelfHeights s) + 1) | ||
23 | sideBoard = box (boardThickness s) (depth s) shelfHeight | ||
24 | shelfBoard = box (width s) (depth s) (boardThickness s) | ||
13 | 25 | ||
14 | main :: IO () | 26 | main :: IO () |
15 | main = draw $ modelShelf myShelf | 27 | main = drawL $ modelShelf myShelf |
16 | |||
17 | shelf_thickness :: Double | ||
18 | shelf_thickness = 0.5 | ||
19 | shelf_width :: Double | ||
20 | shelf_width = 8 | ||
21 | shelf_length :: Double | ||
22 | shelf_length = 36 * 2 | ||
23 | shelf_dim :: V3 Double | ||
24 | shelf_dim = V3 shelf_length shelf_width shelf_thickness | ||
25 | |||
26 | shelf_heights :: [Double] | ||
27 | shelf_heights = [12, 10, 8, 8, 8, 8, 8] | ||
28 | |||
29 | -- working algorithm doing the same as `scanl (+) 0 shelf_heights` | ||
30 | --acc [] = [0] | ||
31 | --acc xs = acc(init xs) ++ [sum xs] | ||
32 | |||
33 | shelf_height :: Double | ||
34 | shelf_height = (sum shelf_heights) + (shelf_dim ^. _z * (fromIntegral (length shelf_heights) + 1)) | ||
35 | |||
36 | side_dim :: V3 Double | ||
37 | side_dim = V3 0.5 shelf_width shelf_height | ||
38 | |||
39 | --shelf_y_poss = scanl (+) 0 shelf_heights | ||
40 | shelf_y_poss :: [Double] | ||
41 | shelf_y_poss = scanl (+) 0 [h+shelf_thickness| h <- shelf_heights] | ||
42 | shelves_pos :: [V3 Double] | ||
43 | shelves_pos = [V3 (side_dim ^. _x) 0 y | y <- shelf_y_poss] | ||
44 | shelves :: [(V3 Double, V3 Double)] | ||
45 | shelves = [(p, shelf_dim) | p <- shelves_pos] | ||
46 | |||
47 | --sides = [(V3 0 0 0, side_dim), (V3 (side_dim ^. _x + shelf_length) 0 0, side_dim)] | ||
48 | sides_pos :: [V3 Double] | ||
49 | sides_pos = [V3 0 0 0, V3 (side_dim ^. _x + shelf_length) 0 0] | ||
50 | sides :: [(V3 Double, V3 Double)] | ||
51 | sides = [(p, side_dim) | p <- sides_pos] | ||
52 | |||
53 | --V3_to_string v = drop 3 (show v) | ||
54 | |||
55 | --scad_place (p,d) = "translate([ " ++ _V32s(p) ++ " ]) { cube([ " ++ _V32s(d) ++ " ]);}" | ||
56 | --genscad objs = concat $ map (++ "\n") $ map scad_place objs | ||
57 | |||
58 | scadshelf :: String | ||
59 | scadshelf = genscad $ shelves ++ sides | ||
60 | |||
61 | --gen_shelf :: [Fractional] -> Fractional -> Fractional -> [Char] | ||
62 | --gen_shelf shelf_heights depth length = | ||
63 | |||
64 | |||
65 | |||
66 | -- main :: IO () | ||
67 | -- main = do putStrLn scadshelf | ||
68 | |||
69 | |||
70 | |||
71 | --main = map (putStrLn) ["one", "two"] | ||
72 | |||
73 | --genshelf = genscad $ shelves ++ sides | ||
74 | |||
75 | --main = map print $ gen_scad $ shelves ++ sides | ||
76 | |||
77 | --scad_place_sides = map (scad_place_board) [[[V3 0 0 0], side_dim], [[V3 side_dim ^. _x, 0, 0], side_dim]] | ||
78 | |||
79 | --scad_place_shelf vpos = scad_place_board show([0, vpos, 0]) show(shelfd) | ||
80 | |||
81 | |||
82 | --genscad shelves ++ sides | ||
83 | |||
84 | --gen_openscad = map (scad_place_piece | ||
85 | |||
86 | --accu [x] = x | ||
87 | --accu xs = sum(xs) ++ accu(tail xs) | ||
88 | -- OUTPUT: [0,5,8,10] | ||