diff options
Diffstat (limited to 'shelves.hs')
-rw-r--r-- | shelves.hs | 65 |
1 files changed, 42 insertions, 23 deletions
@@ -1,44 +1,63 @@ | |||
1 | import Text.Printf | 1 | import Text.Printf |
2 | import Linear.V3 | 2 | import Linear.V3 |
3 | --import Control.Lens | 3 | import Control.Lens |
4 | import Data.List | ||
4 | 5 | ||
5 | sp xa@(_:xs) = sp xs ++ [sum(xa)] | 6 | shelf_thickness = 0.5 |
7 | shelf_width = 4 | ||
8 | shelf_length = 12 * 2 | ||
9 | shelf_dim = V3 shelf_length shelf_width shelf_thickness | ||
6 | 10 | ||
11 | shelf_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 ++ | 17 | shelf_height = (sum shelf_heights) + (shelf_dim ^. _z * (fromIntegral (length shelf_heights) + 1)) |
11 | -- sp sh = 0 ++ head sh ++ | ||
12 | 18 | ||
13 | shelf_thickness = 0.5 | 19 | side_dim = V3 0.5 shelf_width shelf_height |
14 | shelf_width = 4 | ||
15 | shelf_length = 16 | ||
16 | shelfd = [shelf_thickness, shelf_width, shelf_length] | ||
17 | 20 | ||
18 | shelf_heights = [2,3,5,5] | 21 | --shelf_y_poss = scanl (+) 0 shelf_heights |
19 | sh = shelf_heights | 22 | shelf_y_poss = scanl (+) 0 [h+shelf_thickness| h <- shelf_heights] |
23 | shelves_pos = [V3 (side_dim ^. _x) 0 y | y <- shelf_y_poss] | ||
24 | shelves = [(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]] | 27 | sides_pos = [V3 0 0 0, V3 (side_dim ^. _x + shelf_length) 0 0] |
28 | sides = [(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] | 34 | scad_place (p,d) = "translate([ " ++ _V32s(p) ++ " ]) { cube([ " ++ _V32s(d) ++ " ]);}" |
35 | genscad objs = concat $ map (++ "\n") $ map scad_place objs | ||
28 | 36 | ||
37 | scadshelf = genscad $ shelves ++ sides | ||
29 | 38 | ||
30 | shelf_y_poss = scanl (+) 0 shelf_heights | 39 | --gen_shelf :: [Fractional] -> Fractional -> Fractional -> [Char] |
31 | shelf_poss = [ [0,y,0] | y <- shelf_y_poss ] | 40 | --gen_shelf shelf_heights depth length = |
32 | shelf_height = sum shelf_heights | ||
33 | 41 | ||
34 | scad_place_board pos dim = "transform(" ++ show(pos) ++ ") { cube(" ++ show(dim) ++ ");}" | 42 | |
35 | scad_place_shelf pos = scad_place_board pos shelfd | 43 | |
36 | scad_place_shelves = map (scad_place_shelf) shelf_poss | 44 | main = 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 |