summaryrefslogtreecommitdiff
path: root/shelves.hs
diff options
context:
space:
mode:
Diffstat (limited to 'shelves.hs')
-rw-r--r--shelves.hs65
1 files changed, 42 insertions, 23 deletions
diff --git a/shelves.hs b/shelves.hs
index be37931..e78a5cc 100644
--- a/shelves.hs
+++ b/shelves.hs
@@ -1,44 +1,63 @@
1import Text.Printf 1import Text.Printf
2import Linear.V3 2import Linear.V3
3--import Control.Lens 3import Control.Lens
4import Data.List
4 5
5sp xa@(_:xs) = sp xs ++ [sum(xa)] 6shelf_thickness = 0.5
7shelf_width = 4
8shelf_length = 12 * 2
9shelf_dim = V3 shelf_length shelf_width shelf_thickness
6 10
11shelf_heights = [8, 8, 8, 8, 8]
7 12
8-- fo2 f xs = 13-- working algorithm doing the same as `scanl (+) 0 shelf_heights`
14--acc [] = [0]
15--acc xs = acc(init xs) ++ [sum xs]
9 16
10--repeatlast xs = xs ++ 17shelf_height = (sum shelf_heights) + (shelf_dim ^. _z * (fromIntegral (length shelf_heights) + 1))
11-- sp sh = 0 ++ head sh ++
12 18
13shelf_thickness = 0.5 19side_dim = V3 0.5 shelf_width shelf_height
14shelf_width = 4
15shelf_length = 16
16shelfd = [shelf_thickness, shelf_width, shelf_length]
17 20
18shelf_heights = [2,3,5,5] 21--shelf_y_poss = scanl (+) 0 shelf_heights
19sh = shelf_heights 22shelf_y_poss = scanl (+) 0 [h+shelf_thickness| h <- shelf_heights]
23shelves_pos = [V3 (side_dim ^. _x) 0 y | y <- shelf_y_poss]
24shelves = [(p, shelf_dim) | p <- shelves_pos]
20 25
21--side_dims = [0.5,last sh,shelf_width] 26--sides = [(V3 0 0 0, side_dim), (V3 (side_dim ^. _x + shelf_length) 0 0, side_dim)]
22--side_poss = [[0,0,0], [shelf_length + (side_dims[0] * 2), 0, 0]] 27sides_pos = [V3 0 0 0, V3 (side_dim ^. _x + shelf_length) 0 0]
28sides = [(p, side_dim) | p <- sides_pos]
23 29
30--V3_to_string v = drop 3 (show v)
24 31
25-- working algorithm doing the same as `scanl (+) 0 shelf_heights` 32_V32l v3 = [v3 ^. _x, v3 ^. _y, v3 ^. _z]
26--acc [] = [0] 33_V32s v3 = intercalate ", " (map show (_V32l v3))
27--acc xs = acc(init xs) ++ [sum xs] 34scad_place (p,d) = "translate([ " ++ _V32s(p) ++ " ]) { cube([ " ++ _V32s(d) ++ " ]);}"
35genscad objs = concat $ map (++ "\n") $ map scad_place objs
28 36
37scadshelf = genscad $ shelves ++ sides
29 38
30shelf_y_poss = scanl (+) 0 shelf_heights 39--gen_shelf :: [Fractional] -> Fractional -> Fractional -> [Char]
31shelf_poss = [ [0,y,0] | y <- shelf_y_poss ] 40--gen_shelf shelf_heights depth length =
32shelf_height = sum shelf_heights
33 41
34scad_place_board pos dim = "transform(" ++ show(pos) ++ ") { cube(" ++ show(dim) ++ ");}" 42
35scad_place_shelf pos = scad_place_board pos shelfd 43
36scad_place_shelves = map (scad_place_shelf) shelf_poss 44main = do putStrLn scadshelf
37--scad_place_sides = map (scad_place_board) [ [0, 0, 0], 45
46
47
48--main = map (putStrLn) ["one", "two"]
49
50--genshelf = genscad $ shelves ++ sides
51
52--main = map print $ gen_scad $ shelves ++ sides
53
54--scad_place_sides = map (scad_place_board) [[[V3 0 0 0], side_dim], [[V3 side_dim ^. _x, 0, 0], side_dim]]
38 55
39--scad_place_shelf vpos = scad_place_board show([0, vpos, 0]) show(shelfd) 56--scad_place_shelf vpos = scad_place_board show([0, vpos, 0]) show(shelfd)
40 57
41 58
59--genscad shelves ++ sides
60
42--gen_openscad = map (scad_place_piece 61--gen_openscad = map (scad_place_piece
43 62
44--accu [x] = x 63--accu [x] = x