From c8ecdd4b892e819555bcd6a7cef76197dd864f2c Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 20 Mar 2019 01:01:36 -0400 Subject: filled in stubs removed old code --- shelves.hs | 103 +++++++++++++------------------------------------------------ 1 file changed, 21 insertions(+), 82 deletions(-) diff --git a/shelves.hs b/shelves.hs index 0484ff5..73551f2 100644 --- a/shelves.hs +++ b/shelves.hs @@ -1,88 +1,27 @@ -import Control.Lens -import GenSCAD (genscad) import Graphics.OpenSCAD -import Linear.V3 -data Shelf +data Shelf = Shelf { + width :: Double, + depth :: Double, + boardThickness :: Double, + shelfHeights :: [Double] +} deriving (Show) myShelf :: Shelf -myShelf = undefined - -modelShelf :: Shelf -> Model3d -modelShelf = undefined +myShelf = Shelf { width = 36, depth = 8, boardThickness = 1, + shelfHeights = [12, 12, 10, 10, 6, 6, 6] } + +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 + 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 = draw $ modelShelf myShelf - -shelf_thickness :: Double -shelf_thickness = 0.5 -shelf_width :: Double -shelf_width = 8 -shelf_length :: Double -shelf_length = 36 * 2 -shelf_dim :: V3 Double -shelf_dim = V3 shelf_length shelf_width shelf_thickness - -shelf_heights :: [Double] -shelf_heights = [12, 10, 8, 8, 8, 8, 8] - --- working algorithm doing the same as `scanl (+) 0 shelf_heights` ---acc [] = [0] ---acc xs = acc(init xs) ++ [sum xs] - -shelf_height :: Double -shelf_height = (sum shelf_heights) + (shelf_dim ^. _z * (fromIntegral (length shelf_heights) + 1)) - -side_dim :: V3 Double -side_dim = V3 0.5 shelf_width shelf_height - ---shelf_y_poss = scanl (+) 0 shelf_heights -shelf_y_poss :: [Double] -shelf_y_poss = scanl (+) 0 [h+shelf_thickness| h <- shelf_heights] -shelves_pos :: [V3 Double] -shelves_pos = [V3 (side_dim ^. _x) 0 y | y <- shelf_y_poss] -shelves :: [(V3 Double, V3 Double)] -shelves = [(p, shelf_dim) | p <- shelves_pos] - ---sides = [(V3 0 0 0, side_dim), (V3 (side_dim ^. _x + shelf_length) 0 0, side_dim)] -sides_pos :: [V3 Double] -sides_pos = [V3 0 0 0, V3 (side_dim ^. _x + shelf_length) 0 0] -sides :: [(V3 Double, V3 Double)] -sides = [(p, side_dim) | p <- sides_pos] - ---V3_to_string v = drop 3 (show v) - ---scad_place (p,d) = "translate([ " ++ _V32s(p) ++ " ]) { cube([ " ++ _V32s(d) ++ " ]);}" ---genscad objs = concat $ map (++ "\n") $ map scad_place objs - -scadshelf :: String -scadshelf = genscad $ shelves ++ sides - ---gen_shelf :: [Fractional] -> Fractional -> Fractional -> [Char] ---gen_shelf shelf_heights depth length = - - - --- main :: IO () --- main = do putStrLn scadshelf - - - ---main = map (putStrLn) ["one", "two"] - ---genshelf = genscad $ shelves ++ sides - ---main = map print $ gen_scad $ shelves ++ sides - ---scad_place_sides = map (scad_place_board) [[[V3 0 0 0], side_dim], [[V3 side_dim ^. _x, 0, 0], side_dim]] - ---scad_place_shelf vpos = scad_place_board show([0, vpos, 0]) show(shelfd) - - ---genscad shelves ++ sides - ---gen_openscad = map (scad_place_piece - ---accu [x] = x ---accu xs = sum(xs) ++ accu(tail xs) --- OUTPUT: [0,5,8,10] +main = drawL $ modelShelf myShelf -- cgit v1.2.3