From 7040c5aa653f11487b1d52e3c7aefc1e41f57136 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 8 Mar 2019 04:36:23 -0500 Subject: lost tracks --- GenSCAD.hs | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ shelves-pure.hs | 52 ++++++++++++++++++++++++++++++++++++++ shelves.hs | 65 +++++++++++++++++++++++++++++++----------------- 3 files changed, 171 insertions(+), 23 deletions(-) create mode 100644 GenSCAD.hs create mode 100644 shelves-pure.hs diff --git a/GenSCAD.hs b/GenSCAD.hs new file mode 100644 index 0000000..90bcd74 --- /dev/null +++ b/GenSCAD.hs @@ -0,0 +1,77 @@ +module GenSCAD +( placecube +) where + +import Linear.V3 +import Control.Lens +import Data.List +import Text.Printf +import System.IO.Temp +import System.Process + +_V32l :: R3 c1 => c1 c -> [c] +_V32l c = [c ^. _x, c ^. _y, c ^. _z] + +_V32s :: (R3 c1, Show a) => c1 a -> [Char] +_V32s c = intercalate "," (map show (_V32l c)) + +-- placecube: OpenSCAD translate cube described by d to place designated by p +-- placecube (V3 1 2 3, V3 10 20 30) -> +-- translate([1, 2, 3]) { cube([10, 20, 30]); } +placecube obj = "translate([ " ++ _V32s(fst obj) ++ " ]) { cube([ " ++ _V32s(snd obj) ++ " ]); }" +--placecube (p,d) = printf "translate([%d, %d, %d]) { cube([%d, %d, %d]); }" (_V32l p ++ _V32l d) + + +-- take a list of tuples containing positions and dimensions for cubes and +-- generate corresponding code for rendering in OpenSCAD +-- genscad [(V3 0 0 0, V3 10 10 10), (V3 20 20 20, V3 10 10 10)] -> +-- placecube (V3 0 0 0, V3 10 10 10) -> translate ([...]) { cube([...]);} +-- placecube (V3 20 20 20, V3 10 10 10) -> ' + +td = [(V3 0 1 2, V3 10 20 30), (V3 50 51 52, V3 11 22 33)] + +--genscad :: [(V3 p, V3 d)] -> [Char] +--genscad objs = concat $ map (++ "\n") $ map placecube objs +genscad objs = concat $ map (++ "\n") $ map (placecube) objs +printscad objs = putStrLn $ genscad objs +--writefilescad objs = withSystemTempFile "genscad" -> fp gsf -> doprintscad objs +writetempscad objs = writeSystemTempFile "genscad" (genscad objs) +opentempscad objs = runCommand ("openscad " ++ "foo.scad") +--opentempscad objs = + +-- savegenscad code file -> save generated code file +-- opensavegenscad code file -> generate scad, save to file, then open in OpenSCAD + +-- readEditor :: IO String +-- readEditor = withSystemTempFile "read-editor" readEditor' + +-- -- | Opens a file, fills it some content and returns it's contents after it's saved. +-- readEditorWith :: String -> IO String +-- readEditorWith contents = withSystemTempFile "read-editor" $ \fp temph -> do +-- hPutStr temph contents +-- hFlush temph +-- readEditor' fp temph + +-- readEditor' :: FilePath -> Handle -> IO String +-- readEditor' fp temph = do +-- openEditor fp +-- hClose temph +-- readFile fp + + + +-- compileRunPrint :: FilePath -> Ident -> IO String +-- compileRunPrint agdap var = +-- withSystemTempFile "module.mlf" $ +-- \mlfp mlfh -> do +-- callProcess "stack" ["exec", "agda-ocaml", "--", "-v0", "--mlf", agdap +-- , "-o", mlfp, "--print-var", var] +-- runModFile' mlfp mlfh + +-- compileRun :: FilePath -> IO String +-- compileRun agdap = +-- withSystemTempFile "module.mlf" $ +-- \mlfp mlfh -> do +-- callProcess "stack" ["exec", "agda-ocaml", "--", "-v0", "--mlf", agdap +-- , "-o", mlfp] +-- 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 @@ +import Linear.V3 +import Control.Lens +import Data.List + +-- Karens Specifies: + +shelf_heights = [12, 10, 10, 10, 6, 6] +shelf_length = 16 +shelf_depth = 6 + +shelf_thickness = 0.5 +side_thickness = 0.5 + +-- Behind Karen's Back + +shelf_height = sum shelf_heights + +sided = V3 side_thickness shelf_height shelf_depth +shelfd = V3 shelf_length shelf_thickness shelf_depth + + +sideps = [(V3 0 0 0), (V3 (sided ^. _x + shelfd ^. _x) 0 0)] + +shelf_ys = scanl (+) 0 shelf_heights +shelfps = [(V3 x 0 0) | x <- shelf_ys] + + +place_pieces poss piece_dim = [[(p, piece_dim)] |p <- poss] + +shelves = place_pieces shelfps shelfd +sides = place_pieces sideps sided + +V32l v3 = [v3 ^. _x, v3 ^. _y, v3 ^. _z] +V32s v3 = intercalate ", " (map show (v32l v3)) +scadplace obj = genscadstr (fst (head obj)) (snd (head obj)) +genscadstr p o = "translate([" ++ v32s p ++ "]) { cube([" ++ v32s o ++ "]); }" +genscad ps = intercalate "" $ map scadplace ps + + + +--genscad ps = map printf "POS: %s DIM: %s\n" p d) ps) +--genscad ps = ["P: " ++ (fst p) ++ " | O: " ++ (snd p) |p<-ps] +--genscad ps = [fst(p) |p<-ps] +--genscad ps = ["P: " ++ p ++ "D: " ++ d|(p,d) <- ps] +--genscad ps = map () + +main = print 1 +--main = print $ genscad (shelves ++ sides) + + + + diff --git a/shelves.hs b/shelves.hs index be37931..e78a5cc 100644 --- a/shelves.hs +++ b/shelves.hs @@ -1,44 +1,63 @@ import Text.Printf import Linear.V3 ---import Control.Lens +import Control.Lens +import Data.List -sp xa@(_:xs) = sp xs ++ [sum(xa)] +shelf_thickness = 0.5 +shelf_width = 4 +shelf_length = 12 * 2 +shelf_dim = V3 shelf_length shelf_width shelf_thickness +shelf_heights = [8, 8, 8, 8, 8] --- fo2 f xs = +-- working algorithm doing the same as `scanl (+) 0 shelf_heights` +--acc [] = [0] +--acc xs = acc(init xs) ++ [sum xs] ---repeatlast xs = xs ++ --- sp sh = 0 ++ head sh ++ +shelf_height = (sum shelf_heights) + (shelf_dim ^. _z * (fromIntegral (length shelf_heights) + 1)) -shelf_thickness = 0.5 -shelf_width = 4 -shelf_length = 16 -shelfd = [shelf_thickness, shelf_width, shelf_length] +side_dim = V3 0.5 shelf_width shelf_height -shelf_heights = [2,3,5,5] -sh = shelf_heights +--shelf_y_poss = scanl (+) 0 shelf_heights +shelf_y_poss = scanl (+) 0 [h+shelf_thickness| h <- shelf_heights] +shelves_pos = [V3 (side_dim ^. _x) 0 y | y <- shelf_y_poss] +shelves = [(p, shelf_dim) | p <- shelves_pos] ---side_dims = [0.5,last sh,shelf_width] ---side_poss = [[0,0,0], [shelf_length + (side_dims[0] * 2), 0, 0]] +--sides = [(V3 0 0 0, side_dim), (V3 (side_dim ^. _x + shelf_length) 0 0, side_dim)] +sides_pos = [V3 0 0 0, V3 (side_dim ^. _x + shelf_length) 0 0] +sides = [(p, side_dim) | p <- sides_pos] +--V3_to_string v = drop 3 (show v) --- working algorithm doing the same as `scanl (+) 0 shelf_heights` ---acc [] = [0] ---acc xs = acc(init xs) ++ [sum xs] +_V32l v3 = [v3 ^. _x, v3 ^. _y, v3 ^. _z] +_V32s v3 = intercalate ", " (map show (_V32l v3)) +scad_place (p,d) = "translate([ " ++ _V32s(p) ++ " ]) { cube([ " ++ _V32s(d) ++ " ]);}" +genscad objs = concat $ map (++ "\n") $ map scad_place objs +scadshelf = genscad $ shelves ++ sides -shelf_y_poss = scanl (+) 0 shelf_heights -shelf_poss = [ [0,y,0] | y <- shelf_y_poss ] -shelf_height = sum shelf_heights +--gen_shelf :: [Fractional] -> Fractional -> Fractional -> [Char] +--gen_shelf shelf_heights depth length = -scad_place_board pos dim = "transform(" ++ show(pos) ++ ") { cube(" ++ show(dim) ++ ");}" -scad_place_shelf pos = scad_place_board pos shelfd -scad_place_shelves = map (scad_place_shelf) shelf_poss ---scad_place_sides = map (scad_place_board) [ [0, 0, 0], + + +main = do putStrLn scadshelf + + + +--main = map (putStrLn) ["one", "two"] + +--genshelf = genscad $ shelves ++ sides + +--main = map print $ gen_scad $ shelves ++ sides + +--scad_place_sides = map (scad_place_board) [[[V3 0 0 0], side_dim], [[V3 side_dim ^. _x, 0, 0], side_dim]] --scad_place_shelf vpos = scad_place_board show([0, vpos, 0]) show(shelfd) +--genscad shelves ++ sides + --gen_openscad = map (scad_place_piece --accu [x] = x -- cgit v1.2.3