From 10966b90b18022b895c04c38e728067a57218ee2 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 25 Apr 2019 19:08:19 -0400 Subject: added support for new interface of OpenSCAD/Carpentry --- shelves.hs | 55 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/shelves.hs b/shelves.hs index 73551f2..c560cf4 100644 --- a/shelves.hs +++ b/shelves.hs @@ -1,27 +1,66 @@ import Graphics.OpenSCAD +import Linear.V3 +import OpenSCAD.Carpentry +import System.Process +-- the minimum paramaters to describe a shelf; the width and depth of a shelf, +-- a list consisting of the height of each shelf (from the bottom up). +-- boardThickness is the thickness of the boards to be used data Shelf = Shelf { - width :: Double, - depth :: Double, - boardThickness :: Double, - shelfHeights :: [Double] + width :: Double, + depth :: Double, + shelfHeights :: [Double], + boardThickness :: Double } deriving (Show) myShelf :: Shelf myShelf = Shelf { width = 36, depth = 8, boardThickness = 1, shelfHeights = [12, 12, 10, 10, 6, 6, 6] } + +calcShelfHeights :: Shelf -> [Double] +calcShelfHeights s = scanl (+) 0 [h + (boardThickness s)|h <- (shelfHeights s)] + modelShelf :: Shelf -> [Model3d] modelShelf s = let sidesPos = [(0,0,0), (boardThickness s + width s, 0, 0)] shelvesPos = let ys = scanl (+) 0 [h + boardThickness s|h <- shelfHeights s] in [ (boardThickness s, 0, y) | y <- ys ] - place board places = map (\p -> translate p board) places - in place sideBoard sidesPos ++ place shelfBoard shelvesPos + place' board places = map (\p -> translate p board) places + in place' sideBoard sidesPos ++ place' shelfBoard shelvesPos where shelfHeight = sum (shelfHeights s) + (boardThickness s) * (fromIntegral (length $ shelfHeights s) + 1) sideBoard = box (boardThickness s) (depth s) shelfHeight shelfBoard = box (width s) (depth s) (boardThickness s) -main :: IO () -main = drawL $ modelShelf myShelf +modelShelf' :: Shelf -> [Model3d] +modelShelf' s = + place sideBoard [V3 0 0 0, V3 (boardThickness s + width s) 0 0] ++ + place shelfBoard [(V3 (boardThickness s) 0 z) | z <- shelfZs] + where shelfHeight = sum (shelfHeights s) + (boardThickness s) * + (fromIntegral (length $ shelfHeights s) + 1) + sideBoard = V3 (boardThickness s) (depth s) shelfHeight + shelfBoard = V3 (width s) (depth s) (boardThickness s) + shelfZs = scanl (+) 0 [h + boardThickness s|h <- (shelfHeights s)] + +modelShelf'' :: Shelf -> [Model3d] +modelShelf'' s = + let sides = placeColored red sideBoard $ at [0, boardThickness s + width s] [0] [0] + shelves = placeColored blue shelfBoard $ at [(boardThickness s)] [0] shelfZs + in sides ++ shelves + where shelfHeight = sum (shelfHeights s) + (boardThickness s) * + (fromIntegral (length $ shelfHeights s) + 1) + sideBoard = V3 (boardThickness s) (depth s) shelfHeight + shelfBoard = V3 (width s) (depth s) (boardThickness s) + shelfZs = scanl (+) 0 [h + (boardThickness s)|h <- (shelfHeights s)] + + +shelf :: String +shelf = renderL $ modelShelf myShelf +shelf' :: String +shelf' = renderL $ modelShelf' myShelf +shelf'' :: String +shelf'' = renderL $ modelShelf'' myShelf + +main :: IO ProcessHandle +main = openTempSCAD $ shelf'' -- cgit v1.2.3