summaryrefslogtreecommitdiff
path: root/shelves.hs
diff options
context:
space:
mode:
Diffstat (limited to 'shelves.hs')
-rw-r--r--shelves.hs52
1 files changed, 50 insertions, 2 deletions
diff --git a/shelves.hs b/shelves.hs
index c560cf4..16f029f 100644
--- a/shelves.hs
+++ b/shelves.hs
@@ -14,8 +14,8 @@ data Shelf = Shelf {
14} deriving (Show) 14} deriving (Show)
15 15
16myShelf :: Shelf 16myShelf :: Shelf
17myShelf = Shelf { width = 36, depth = 8, boardThickness = 1, 17myShelf = 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
21calcShelfHeights :: Shelf -> [Double] 21calcShelfHeights :: 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
57data 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
66modelShelf''' :: Shelf -> ModeledShelf
67modelShelf''' 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
86assembleShelf 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
58shelf :: String 104shelf :: String
59shelf = renderL $ modelShelf myShelf 105shelf = renderL $ modelShelf myShelf
@@ -62,5 +108,7 @@ shelf' = renderL $ modelShelf' myShelf
62shelf'' :: String 108shelf'' :: String
63shelf'' = renderL $ modelShelf'' myShelf 109shelf'' = renderL $ modelShelf'' myShelf
64 110
111(cuts, model) = assembleShelf myShelf
112
65main :: IO ProcessHandle 113main :: IO ProcessHandle
66main = openTempSCAD $ shelf'' 114main = openTempSCAD $ shelf''