summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven <steven.vasilogianis@gmail.com>2019-03-08 04:36:23 -0500
committerSteven <steven.vasilogianis@gmail.com>2019-03-08 04:36:23 -0500
commit7040c5aa653f11487b1d52e3c7aefc1e41f57136 (patch)
treec1fd0d9c72ea6766616ebc26ad7a891c5d809b82
parent3e6c8dede8ac3506dbf9de06ebbb11f4469562ac (diff)
lost tracks
-rw-r--r--GenSCAD.hs77
-rw-r--r--shelves-pure.hs52
-rw-r--r--shelves.hs65
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 @@
1module GenSCAD
2( placecube
3) where
4
5import Linear.V3
6import Control.Lens
7import Data.List
8import Text.Printf
9import System.IO.Temp
10import 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]); }
21placecube 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
31td = [(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
35genscad objs = concat $ map (++ "\n") $ map (placecube) objs
36printscad objs = putStrLn $ genscad objs
37--writefilescad objs = withSystemTempFile "genscad" -> fp gsf -> doprintscad objs
38writetempscad objs = writeSystemTempFile "genscad" (genscad objs)
39opentempscad 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 @@
1import Linear.V3
2import Control.Lens
3import Data.List
4
5-- Karens Specifies:
6
7shelf_heights = [12, 10, 10, 10, 6, 6]
8shelf_length = 16
9shelf_depth = 6
10
11shelf_thickness = 0.5
12side_thickness = 0.5
13
14-- Behind Karen's Back
15
16shelf_height = sum shelf_heights
17
18sided = V3 side_thickness shelf_height shelf_depth
19shelfd = V3 shelf_length shelf_thickness shelf_depth
20
21
22sideps = [(V3 0 0 0), (V3 (sided ^. _x + shelfd ^. _x) 0 0)]
23
24shelf_ys = scanl (+) 0 shelf_heights
25shelfps = [(V3 x 0 0) | x <- shelf_ys]
26
27
28place_pieces poss piece_dim = [[(p, piece_dim)] |p <- poss]
29
30shelves = place_pieces shelfps shelfd
31sides = place_pieces sideps sided
32
33V32l v3 = [v3 ^. _x, v3 ^. _y, v3 ^. _z]
34V32s v3 = intercalate ", " (map show (v32l v3))
35scadplace obj = genscadstr (fst (head obj)) (snd (head obj))
36genscadstr p o = "translate([" ++ v32s p ++ "]) { cube([" ++ v32s o ++ "]); }"
37genscad 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
47main = print 1
48--main = print $ genscad (shelves ++ sides)
49
50
51
52
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