From 045e93425e9353d5537e8c14595db0a48377184e Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 12 Mar 2019 19:25:41 -0400 Subject: lost track --- GenSCAD.hs | 90 ++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 52 insertions(+), 38 deletions(-) (limited to 'GenSCAD.hs') diff --git a/GenSCAD.hs b/GenSCAD.hs index 90bcd74..c8a27b7 100644 --- a/GenSCAD.hs +++ b/GenSCAD.hs @@ -1,5 +1,14 @@ module GenSCAD -( placecube +( placecube +, genscad +, printscad +, writetempscad +, opentempscad +, cube +, translate +, cubeat +, color +, colorcubeat ) where import Linear.V3 @@ -8,6 +17,12 @@ import Data.List import Text.Printf import System.IO.Temp import System.Process +import Data.Colour +import Data.Colour.RGBSpace +import Data.Colour.SRGB +import Data.Colour.Names + + _V32l :: R3 c1 => c1 c -> [c] _V32l c = [c ^. _x, c ^. _y, c ^. _z] @@ -18,6 +33,33 @@ _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]); } + +--crandrgb = intercalate "," +color rgb what = "color ([" ++ rgb ++ "]) {" ++ what ++ "}" +translate to what = "translate([ " ++ to ++ "]) { " ++ what ++ " }" +cube d = "cube([ " ++ d ++ "]);" +cubeat d here = translate here $ (cube d) +colorcubeat rgb d pos = color rgb $ translate pos $ cube d + +--place [x] = "ERROR" +place [d, p] = cubeat d p +place [r, d, p] = colorcubeat r d p + +--place[o] = scad (fst o) (snd o) +--place o = scad (fst (head o)) (snd (head o)) ++ place (tail o) +--place o = [scad d p| (p,d) <- o] +--place (o) = scad (fst (head o)) (snd (head o)) ++ place (tail o) + + +--scad [] = [] +--scad obj = (place (head obj)) ++ "\n" ++ scad (tail obj) +scad [(d, p)] = cubeat p d +--scad [(r, d, p)] = colorcubeat r d p +--scad [x] = if (length x == 3) then (colorcubeat (x !! 0) (x !! 1) (x !! 2)) +-- else (cubeat (x !! 0) (x !!1)) +--scad (x:s) = scad [x] ++ scad s + + 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) @@ -28,50 +70,22 @@ placecube obj = "translate([ " ++ _V32s(fst obj) ++ " ]) { cube([ " ++ _V32s(sn -- 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)] +--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 + +--scad (c, p, d) = colorcubeat c d p +--scad (p,d) = cubeat d p 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 = +writetempscad objs = writeSystemTempFile "genscad.scad" (genscad objs) +opentempscad objs = do + fp <- writetempscad objs + runCommand $ "openscad " ++ fp +--opentempscad objs = print $ "openscad " ++ (writetempscad 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 -- cgit v1.2.3