summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2019-03-15 16:58:54 -0400
committerAndrew Cady <d@jerkface.net>2019-03-15 16:58:54 -0400
commit0ee05c63d5c022acb50065d6333fe56069be4d03 (patch)
tree55c4bcb6966790608c63459a93e1bf0c9174880d
parent9e948c3dba9124e7cef54bc64fc76038b89f45f8 (diff)
fill out stubbed code based on existing code
also removed the unused definition
-rw-r--r--shelves.hs113
1 files changed, 38 insertions, 75 deletions
diff --git a/shelves.hs b/shelves.hs
index 6ed051a..0ea28ee 100644
--- a/shelves.hs
+++ b/shelves.hs
@@ -1,93 +1,56 @@
1{-# LANGUAGE RecordWildCards #-}
1import Control.Lens 2import Control.Lens
2import Graphics.OpenSCAD 3import Graphics.OpenSCAD
3import Linear.V3 4import Linear.V3
4 5
5genscad :: [(V3 Double, V3 Double)] -> String 6genscad :: [(V3 Double, V3 Double)] -> String
6genscad = render . union . map transBox 7genscad = render . transBoxes
7 where
8 transBox :: (V3 Double, V3 Double) -> Model3d
9 transBox (V3 x1 y1 z1, V3 x2 y2 z2) = translate (x1,y1,z1) $ box x2 y2 z2
10
11data Shelf
12
13myShelf :: Shelf
14myShelf = undefined
15
16modelShelf :: Shelf -> Model3d
17modelShelf = undefined
18
19main :: IO ()
20main = draw $ modelShelf myShelf
21
22shelf_thickness :: Double
23shelf_thickness = 0.5
24shelf_width :: Double
25shelf_width = 8
26shelf_length :: Double
27shelf_length = 36 * 2
28shelf_dim :: V3 Double
29shelf_dim = V3 shelf_length shelf_width shelf_thickness
30
31shelf_heights :: [Double]
32shelf_heights = [12, 10, 8, 8, 8, 8, 8]
33
34-- working algorithm doing the same as `scanl (+) 0 shelf_heights`
35--acc [] = [0]
36--acc xs = acc(init xs) ++ [sum xs]
37
38shelf_height :: Double
39shelf_height = (sum shelf_heights) + (shelf_dim ^. _z * (fromIntegral (length shelf_heights) + 1))
40 8
41side_dim :: V3 Double 9transBoxes :: [(V3 Double, V3 Double)] -> Model Vector3d
42side_dim = V3 0.5 shelf_width shelf_height 10transBoxes = union . map transBox
43 11
44--shelf_y_poss = scanl (+) 0 shelf_heights 12transBox :: (V3 Double, V3 Double) -> Model3d
45shelf_y_poss :: [Double] 13transBox (V3 x1 y1 z1, V3 x2 y2 z2) = translate (x1,y1,z1) $ box x2 y2 z2
46shelf_y_poss = scanl (+) 0 [h+shelf_thickness| h <- shelf_heights]
47shelves_pos :: [V3 Double]
48shelves_pos = [V3 (side_dim ^. _x) 0 y | y <- shelf_y_poss]
49shelves :: [(V3 Double, V3 Double)]
50shelves = [(p, shelf_dim) | p <- shelves_pos]
51 14
52--sides = [(V3 0 0 0, side_dim), (V3 (side_dim ^. _x + shelf_length) 0 0, side_dim)] 15type Inches = Double
53sides_pos :: [V3 Double]
54sides_pos = [V3 0 0 0, V3 (side_dim ^. _x + shelf_length) 0 0]
55sides :: [(V3 Double, V3 Double)]
56sides = [(p, side_dim) | p <- sides_pos]
57 16
58--V3_to_string v = drop 3 (show v) 17data Shelf = Shelf {
18 shelfThickness :: Inches,
19 shelfWidth :: Inches,
20 shelfLength :: Inches,
21 shelfHeights :: [Inches],
22 shelfSideDimX :: Inches
23}
59 24
60--scad_place (p,d) = "translate([ " ++ _V32s(p) ++ " ]) { cube([ " ++ _V32s(d) ++ " ]);}" 25shelfDim :: Shelf -> V3 Inches
61--genscad objs = concat $ map (++ "\n") $ map scad_place objs 26shelfDim Shelf{..} = V3 shelfLength shelfWidth shelfThickness
62 27
63scadshelf :: String 28shelves' :: Shelf -> [(V3 Double, V3 Double)]
64scadshelf = genscad $ shelves ++ sides 29shelves' s@Shelf{..} = [(p, shelfDim s) | p <- shelvesPos]
65 30 where
66--gen_shelf :: [Fractional] -> Fractional -> Fractional -> [Char] 31 shelfHeight = (sum shelfHeights) + (shelfDim s ^. _z * (fromIntegral (length shelfHeights) + 1))
67--gen_shelf shelf_heights depth length =
68
69
70
71-- main :: IO ()
72-- main = do putStrLn scadshelf
73
74
75
76--main = map (putStrLn) ["one", "two"]
77
78--genshelf = genscad $ shelves ++ sides
79 32
80--main = map print $ gen_scad $ shelves ++ sides 33 shelfSideDim :: V3 Inches
34 shelfSideDim = V3 shelfSideDimX shelfWidth shelfHeight
81 35
82--scad_place_sides = map (scad_place_board) [[[V3 0 0 0], side_dim], [[V3 side_dim ^. _x, 0, 0], side_dim]] 36 shelfYPos :: [Inches]
37 shelfYPos = scanl (+) 0 [h+shelfThickness| h <- shelfHeights]
83 38
84--scad_place_shelf vpos = scad_place_board show([0, vpos, 0]) show(shelfd) 39 shelvesPos :: [V3 Double]
40 shelvesPos = [V3 (shelfSideDim ^. _x) 0 y | y <- shelfYPos]
85 41
42myShelf :: Shelf
43myShelf = Shelf {
44 shelfThickness = 0.5,
45 shelfWidth = 8,
46 shelfLength = 36 * 2,
47 shelfHeights = [12, 10, 8, 8, 8, 8, 8],
48 shelfSideDimX = 0.5
49}
86 50
87--genscad shelves ++ sides 51modelShelf :: Shelf -> Model3d
52modelShelf = transBoxes . shelves'
88 53
89--gen_openscad = map (scad_place_piece 54main :: IO ()
55main = draw $ modelShelf myShelf
90 56
91--accu [x] = x
92--accu xs = sum(xs) ++ accu(tail xs)
93-- OUTPUT: [0,5,8,10]