diff options
Diffstat (limited to 'shelves.hs')
-rw-r--r-- | shelves.hs | 52 |
1 files changed, 50 insertions, 2 deletions
@@ -14,8 +14,8 @@ data Shelf = Shelf { | |||
14 | } deriving (Show) | 14 | } deriving (Show) |
15 | 15 | ||
16 | myShelf :: Shelf | 16 | myShelf :: Shelf |
17 | myShelf = Shelf { width = 36, depth = 8, boardThickness = 1, | 17 | myShelf = Shelf { width = 12*4, depth = 12, boardThickness = 1, |
18 | shelfHeights = [12, 12, 10, 10, 6, 6, 6] } | 18 | shelfHeights = [15, 8, 8, 8] } |
19 | 19 | ||
20 | 20 | ||
21 | calcShelfHeights :: Shelf -> [Double] | 21 | calcShelfHeights :: Shelf -> [Double] |
@@ -54,6 +54,52 @@ modelShelf'' s = | |||
54 | shelfBoard = V3 (width s) (depth s) (boardThickness s) | 54 | shelfBoard = V3 (width s) (depth s) (boardThickness s) |
55 | shelfZs = scanl (+) 0 [h + (boardThickness s)|h <- (shelfHeights s)] | 55 | shelfZs = scanl (+) 0 [h + (boardThickness s)|h <- (shelfHeights s)] |
56 | 56 | ||
57 | data ModeledShelf = ModeledShelf { | ||
58 | shelfDimensions :: V3 Double, | ||
59 | shelfPositions :: [V3 Double], | ||
60 | sideDimensions :: V3 Double, | ||
61 | sidePositions :: [V3 Double], | ||
62 | rendered :: [Model3d], | ||
63 | cutlist :: String | ||
64 | } deriving (Show) | ||
65 | |||
66 | modelShelf''' :: Shelf -> ModeledShelf | ||
67 | modelShelf''' s = | ||
68 | ModeledShelf { shelfDimensions = shelfB, | ||
69 | shelfPositions = shelfP, | ||
70 | sideDimensions = sideB, | ||
71 | sidePositions = sideP, | ||
72 | rendered = placeColored red sideB sideP ++ | ||
73 | placeColored blue shelfB shelfP, | ||
74 | cutlist = cutlist | ||
75 | } | ||
76 | where shelfHeight = sum (shelfHeights s) + (boardThickness s) * | ||
77 | (fromIntegral (length $ shelfHeights s) + 1) | ||
78 | sideB = V3 (boardThickness s) (depth s) shelfHeight | ||
79 | sideP = at [0, boardThickness s + width s] [0] [0] | ||
80 | shelfB = V3 (width s) (depth s) (boardThickness s) | ||
81 | shelfP = at [(boardThickness s)] [0] $ scanl (+) 0 [h + (boardThickness s)|h <- (shelfHeights s)] | ||
82 | cutlist = "Shelves: (" ++ (show (length shelfP)) ++ ") @ " | ||
83 | ++ (show shelfB) ++ | ||
84 | "\nSides: (2) @ " ++ (show sideB) | ||
85 | |||
86 | assembleShelf s = assemble [shelves, sides] | ||
87 | where | ||
88 | shelfHeight = | ||
89 | sum (shelfHeights s) + | ||
90 | (boardThickness s) * (fromIntegral (length $ shelfHeights s) + 1) | ||
91 | sides = | ||
92 | let sideB = V3 (boardThickness s) (depth s) shelfHeight | ||
93 | sideP = at [0, boardThickness s + width s] [0] [0] | ||
94 | in component "sides" sideB _xyz sideP | ||
95 | shelves = | ||
96 | let shelfB = V3 (width s) (depth s) (boardThickness s) | ||
97 | shelfP = | ||
98 | let pz = | ||
99 | scanl (+) 0 [h + (boardThickness s) | h <- (shelfHeights s)] | ||
100 | in at [(boardThickness s)] [0] pz | ||
101 | in component "shelves" shelfB _xyz shelfP | ||
102 | |||
57 | 103 | ||
58 | shelf :: String | 104 | shelf :: String |
59 | shelf = renderL $ modelShelf myShelf | 105 | shelf = renderL $ modelShelf myShelf |
@@ -62,5 +108,7 @@ shelf' = renderL $ modelShelf' myShelf | |||
62 | shelf'' :: String | 108 | shelf'' :: String |
63 | shelf'' = renderL $ modelShelf'' myShelf | 109 | shelf'' = renderL $ modelShelf'' myShelf |
64 | 110 | ||
111 | (cuts, model) = assembleShelf myShelf | ||
112 | |||
65 | main :: IO ProcessHandle | 113 | main :: IO ProcessHandle |
66 | main = openTempSCAD $ shelf'' | 114 | main = openTempSCAD $ shelf'' |