diff options
author | Steven <steven.vasilogianis@gmail.com> | 2019-03-08 04:36:23 -0500 |
---|---|---|
committer | Steven <steven.vasilogianis@gmail.com> | 2019-03-08 04:36:23 -0500 |
commit | 7040c5aa653f11487b1d52e3c7aefc1e41f57136 (patch) | |
tree | c1fd0d9c72ea6766616ebc26ad7a891c5d809b82 | |
parent | 3e6c8dede8ac3506dbf9de06ebbb11f4469562ac (diff) |
lost tracks
-rw-r--r-- | GenSCAD.hs | 77 | ||||
-rw-r--r-- | shelves-pure.hs | 52 | ||||
-rw-r--r-- | shelves.hs | 65 |
3 files changed, 171 insertions, 23 deletions
diff --git a/GenSCAD.hs b/GenSCAD.hs new file mode 100644 index 0000000..90bcd74 --- /dev/null +++ b/GenSCAD.hs | |||
@@ -0,0 +1,77 @@ | |||
1 | module GenSCAD | ||
2 | ( placecube | ||
3 | ) where | ||
4 | |||
5 | import Linear.V3 | ||
6 | import Control.Lens | ||
7 | import Data.List | ||
8 | import Text.Printf | ||
9 | import System.IO.Temp | ||
10 | import System.Process | ||
11 | |||
12 | _V32l :: R3 c1 => c1 c -> [c] | ||
13 | _V32l c = [c ^. _x, c ^. _y, c ^. _z] | ||
14 | |||
15 | _V32s :: (R3 c1, Show a) => c1 a -> [Char] | ||
16 | _V32s c = intercalate "," (map show (_V32l c)) | ||
17 | |||
18 | -- placecube: OpenSCAD translate cube described by d to place designated by p | ||
19 | -- placecube (V3 1 2 3, V3 10 20 30) -> | ||
20 | -- translate([1, 2, 3]) { cube([10, 20, 30]); } | ||
21 | placecube obj = "translate([ " ++ _V32s(fst obj) ++ " ]) { cube([ " ++ _V32s(snd obj) ++ " ]); }" | ||
22 | --placecube (p,d) = printf "translate([%d, %d, %d]) { cube([%d, %d, %d]); }" (_V32l p ++ _V32l d) | ||
23 | |||
24 | |||
25 | -- take a list of tuples containing positions and dimensions for cubes and | ||
26 | -- generate corresponding code for rendering in OpenSCAD | ||
27 | -- genscad [(V3 0 0 0, V3 10 10 10), (V3 20 20 20, V3 10 10 10)] -> | ||
28 | -- placecube (V3 0 0 0, V3 10 10 10) -> translate ([...]) { cube([...]);} | ||
29 | -- placecube (V3 20 20 20, V3 10 10 10) -> ' | ||
30 | |||
31 | td = [(V3 0 1 2, V3 10 20 30), (V3 50 51 52, V3 11 22 33)] | ||
32 | |||
33 | --genscad :: [(V3 p, V3 d)] -> [Char] | ||
34 | --genscad objs = concat $ map (++ "\n") $ map placecube objs | ||
35 | genscad objs = concat $ map (++ "\n") $ map (placecube) objs | ||
36 | printscad objs = putStrLn $ genscad objs | ||
37 | --writefilescad objs = withSystemTempFile "genscad" -> fp gsf -> doprintscad objs | ||
38 | writetempscad objs = writeSystemTempFile "genscad" (genscad objs) | ||
39 | opentempscad objs = runCommand ("openscad " ++ "foo.scad") | ||
40 | --opentempscad objs = | ||
41 | |||
42 | -- savegenscad code file -> save generated code file | ||
43 | -- opensavegenscad code file -> generate scad, save to file, then open in OpenSCAD | ||
44 | |||
45 | -- readEditor :: IO String | ||
46 | -- readEditor = withSystemTempFile "read-editor" readEditor' | ||
47 | |||
48 | -- -- | Opens a file, fills it some content and returns it's contents after it's saved. | ||
49 | -- readEditorWith :: String -> IO String | ||
50 | -- readEditorWith contents = withSystemTempFile "read-editor" $ \fp temph -> do | ||
51 | -- hPutStr temph contents | ||
52 | -- hFlush temph | ||
53 | -- readEditor' fp temph | ||
54 | |||
55 | -- readEditor' :: FilePath -> Handle -> IO String | ||
56 | -- readEditor' fp temph = do | ||
57 | -- openEditor fp | ||
58 | -- hClose temph | ||
59 | -- readFile fp | ||
60 | |||
61 | |||
62 | |||
63 | -- compileRunPrint :: FilePath -> Ident -> IO String | ||
64 | -- compileRunPrint agdap var = | ||
65 | -- withSystemTempFile "module.mlf" $ | ||
66 | -- \mlfp mlfh -> do | ||
67 | -- callProcess "stack" ["exec", "agda-ocaml", "--", "-v0", "--mlf", agdap | ||
68 | -- , "-o", mlfp, "--print-var", var] | ||
69 | -- runModFile' mlfp mlfh | ||
70 | |||
71 | -- compileRun :: FilePath -> IO String | ||
72 | -- compileRun agdap = | ||
73 | -- withSystemTempFile "module.mlf" $ | ||
74 | -- \mlfp mlfh -> do | ||
75 | -- callProcess "stack" ["exec", "agda-ocaml", "--", "-v0", "--mlf", agdap | ||
76 | -- , "-o", mlfp] | ||
77 | -- runModFile' mlfp mlfh | ||
diff --git a/shelves-pure.hs b/shelves-pure.hs new file mode 100644 index 0000000..85873f7 --- /dev/null +++ b/shelves-pure.hs | |||
@@ -0,0 +1,52 @@ | |||
1 | import Linear.V3 | ||
2 | import Control.Lens | ||
3 | import Data.List | ||
4 | |||
5 | -- Karens Specifies: | ||
6 | |||
7 | shelf_heights = [12, 10, 10, 10, 6, 6] | ||
8 | shelf_length = 16 | ||
9 | shelf_depth = 6 | ||
10 | |||
11 | shelf_thickness = 0.5 | ||
12 | side_thickness = 0.5 | ||
13 | |||
14 | -- Behind Karen's Back | ||
15 | |||
16 | shelf_height = sum shelf_heights | ||
17 | |||
18 | sided = V3 side_thickness shelf_height shelf_depth | ||
19 | shelfd = V3 shelf_length shelf_thickness shelf_depth | ||
20 | |||
21 | |||
22 | sideps = [(V3 0 0 0), (V3 (sided ^. _x + shelfd ^. _x) 0 0)] | ||
23 | |||
24 | shelf_ys = scanl (+) 0 shelf_heights | ||
25 | shelfps = [(V3 x 0 0) | x <- shelf_ys] | ||
26 | |||
27 | |||
28 | place_pieces poss piece_dim = [[(p, piece_dim)] |p <- poss] | ||
29 | |||
30 | shelves = place_pieces shelfps shelfd | ||
31 | sides = place_pieces sideps sided | ||
32 | |||
33 | V32l v3 = [v3 ^. _x, v3 ^. _y, v3 ^. _z] | ||
34 | V32s v3 = intercalate ", " (map show (v32l v3)) | ||
35 | scadplace obj = genscadstr (fst (head obj)) (snd (head obj)) | ||
36 | genscadstr p o = "translate([" ++ v32s p ++ "]) { cube([" ++ v32s o ++ "]); }" | ||
37 | genscad ps = intercalate "" $ map scadplace ps | ||
38 | |||
39 | |||
40 | |||
41 | --genscad ps = map printf "POS: %s DIM: %s\n" p d) ps) | ||
42 | --genscad ps = ["P: " ++ (fst p) ++ " | O: " ++ (snd p) |p<-ps] | ||
43 | --genscad ps = [fst(p) |p<-ps] | ||
44 | --genscad ps = ["P: " ++ p ++ "D: " ++ d|(p,d) <- ps] | ||
45 | --genscad ps = map () | ||
46 | |||
47 | main = print 1 | ||
48 | --main = print $ genscad (shelves ++ sides) | ||
49 | |||
50 | |||
51 | |||
52 | |||
@@ -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 |