summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven <steven.vasilogianis@gmail.com>2019-03-12 19:25:41 -0400
committerSteven <steven.vasilogianis@gmail.com>2019-03-12 19:25:41 -0400
commit045e93425e9353d5537e8c14595db0a48377184e (patch)
tree155181c776af30e404d4101cf5c5d9e31f0cafa1
parent7040c5aa653f11487b1d52e3c7aefc1e41f57136 (diff)
lost track
-rw-r--r--GenSCAD.hs90
-rw-r--r--shelves.hs12
2 files changed, 58 insertions, 44 deletions
diff --git a/GenSCAD.hs b/GenSCAD.hs
index 90bcd74..c8a27b7 100644
--- a/GenSCAD.hs
+++ b/GenSCAD.hs
@@ -1,5 +1,14 @@
1module GenSCAD 1module GenSCAD
2( placecube 2( placecube
3, genscad
4, printscad
5, writetempscad
6, opentempscad
7, cube
8, translate
9, cubeat
10, color
11, colorcubeat
3) where 12) where
4 13
5import Linear.V3 14import Linear.V3
@@ -8,6 +17,12 @@ import Data.List
8import Text.Printf 17import Text.Printf
9import System.IO.Temp 18import System.IO.Temp
10import System.Process 19import System.Process
20import Data.Colour
21import Data.Colour.RGBSpace
22import Data.Colour.SRGB
23import Data.Colour.Names
24
25
11 26
12_V32l :: R3 c1 => c1 c -> [c] 27_V32l :: R3 c1 => c1 c -> [c]
13_V32l c = [c ^. _x, c ^. _y, c ^. _z] 28_V32l c = [c ^. _x, c ^. _y, c ^. _z]
@@ -18,6 +33,33 @@ _V32s c = intercalate "," (map show (_V32l c))
18-- placecube: OpenSCAD translate cube described by d to place designated by p 33-- placecube: OpenSCAD translate cube described by d to place designated by p
19-- placecube (V3 1 2 3, V3 10 20 30) -> 34-- placecube (V3 1 2 3, V3 10 20 30) ->
20-- translate([1, 2, 3]) { cube([10, 20, 30]); } 35-- translate([1, 2, 3]) { cube([10, 20, 30]); }
36
37--crandrgb = intercalate ","
38color rgb what = "color ([" ++ rgb ++ "]) {" ++ what ++ "}"
39translate to what = "translate([ " ++ to ++ "]) { " ++ what ++ " }"
40cube d = "cube([ " ++ d ++ "]);"
41cubeat d here = translate here $ (cube d)
42colorcubeat rgb d pos = color rgb $ translate pos $ cube d
43
44--place [x] = "ERROR"
45place [d, p] = cubeat d p
46place [r, d, p] = colorcubeat r d p
47
48--place[o] = scad (fst o) (snd o)
49--place o = scad (fst (head o)) (snd (head o)) ++ place (tail o)
50--place o = [scad d p| (p,d) <- o]
51--place (o) = scad (fst (head o)) (snd (head o)) ++ place (tail o)
52
53
54--scad [] = []
55--scad obj = (place (head obj)) ++ "\n" ++ scad (tail obj)
56scad [(d, p)] = cubeat p d
57--scad [(r, d, p)] = colorcubeat r d p
58--scad [x] = if (length x == 3) then (colorcubeat (x !! 0) (x !! 1) (x !! 2))
59-- else (cubeat (x !! 0) (x !!1))
60--scad (x:s) = scad [x] ++ scad s
61
62
21placecube obj = "translate([ " ++ _V32s(fst obj) ++ " ]) { cube([ " ++ _V32s(snd obj) ++ " ]); }" 63placecube 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) 64--placecube (p,d) = printf "translate([%d, %d, %d]) { cube([%d, %d, %d]); }" (_V32l p ++ _V32l d)
23 65
@@ -28,50 +70,22 @@ placecube obj = "translate([ " ++ _V32s(fst obj) ++ " ]) { cube([ " ++ _V32s(sn
28-- placecube (V3 0 0 0, V3 10 10 10) -> translate ([...]) { cube([...]);} 70-- placecube (V3 0 0 0, V3 10 10 10) -> translate ([...]) { cube([...]);}
29-- placecube (V3 20 20 20, V3 10 10 10) -> ' 71-- placecube (V3 20 20 20, V3 10 10 10) -> '
30 72
31td = [(V3 0 1 2, V3 10 20 30), (V3 50 51 52, V3 11 22 33)] 73--td = [(V3 0 1 2, V3 10 20 30), (V3 50 51 52, V3 11 22 33)]
32 74
33--genscad :: [(V3 p, V3 d)] -> [Char] 75--genscad :: [(V3 p, V3 d)] -> [Char]
34--genscad objs = concat $ map (++ "\n") $ map placecube objs 76--genscad objs = concat $ map (++ "\n") $ map placecube objs
77
78--scad (c, p, d) = colorcubeat c d p
79--scad (p,d) = cubeat d p
35genscad objs = concat $ map (++ "\n") $ map (placecube) objs 80genscad objs = concat $ map (++ "\n") $ map (placecube) objs
36printscad objs = putStrLn $ genscad objs 81printscad objs = putStrLn $ genscad objs
37--writefilescad objs = withSystemTempFile "genscad" -> fp gsf -> doprintscad objs 82--writefilescad objs = withSystemTempFile "genscad" -> fp gsf -> doprintscad objs
38writetempscad objs = writeSystemTempFile "genscad" (genscad objs) 83writetempscad objs = writeSystemTempFile "genscad.scad" (genscad objs)
39opentempscad objs = runCommand ("openscad " ++ "foo.scad") 84opentempscad objs = do
40--opentempscad objs = 85 fp <- writetempscad objs
86 runCommand $ "openscad " ++ fp
87--opentempscad objs = print $ "openscad " ++ (writetempscad objs)
41 88
42-- savegenscad code file -> save generated code file 89-- savegenscad code file -> save generated code file
43-- opensavegenscad code file -> generate scad, save to file, then open in OpenSCAD 90-- opensavegenscad code file -> generate scad, save to file, then open in OpenSCAD
44 91
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.hs b/shelves.hs
index e78a5cc..0136e1c 100644
--- a/shelves.hs
+++ b/shelves.hs
@@ -1,14 +1,14 @@
1import Text.Printf
2import Linear.V3 1import Linear.V3
3import Control.Lens 2import Control.Lens
4import Data.List 3import Data.List
4import GenSCAD
5 5
6shelf_thickness = 0.5 6shelf_thickness = 0.5
7shelf_width = 4 7shelf_width = 8
8shelf_length = 12 * 2 8shelf_length = 36 * 2
9shelf_dim = V3 shelf_length shelf_width shelf_thickness 9shelf_dim = V3 shelf_length shelf_width shelf_thickness
10 10
11shelf_heights = [8, 8, 8, 8, 8] 11shelf_heights = [12, 10, 8, 8, 8, 8, 8]
12 12
13-- working algorithm doing the same as `scanl (+) 0 shelf_heights` 13-- working algorithm doing the same as `scanl (+) 0 shelf_heights`
14--acc [] = [0] 14--acc [] = [0]
@@ -31,8 +31,8 @@ sides = [(p, side_dim) | p <- sides_pos]
31 31
32_V32l v3 = [v3 ^. _x, v3 ^. _y, v3 ^. _z] 32_V32l v3 = [v3 ^. _x, v3 ^. _y, v3 ^. _z]
33_V32s v3 = intercalate ", " (map show (_V32l v3)) 33_V32s v3 = intercalate ", " (map show (_V32l v3))
34scad_place (p,d) = "translate([ " ++ _V32s(p) ++ " ]) { cube([ " ++ _V32s(d) ++ " ]);}" 34--scad_place (p,d) = "translate([ " ++ _V32s(p) ++ " ]) { cube([ " ++ _V32s(d) ++ " ]);}"
35genscad objs = concat $ map (++ "\n") $ map scad_place objs 35--genscad objs = concat $ map (++ "\n") $ map scad_place objs
36 36
37scadshelf = genscad $ shelves ++ sides 37scadshelf = genscad $ shelves ++ sides
38 38