Tidy Haskell examples

Both in Examples dir and README.
This commit is contained in:
Richard Marko 2020-12-05 10:25:01 +01:00
parent 64c595f7bc
commit 6d4162e137
5 changed files with 24 additions and 20 deletions

View File

@ -2,8 +2,9 @@
import Graphics.Implicit
out = union [
rectR 0 (-40,-40) (40,40),
translate (40,40) (circle 30) ]
squareR 0 True (80, 80)
, translate (40, 40) $ circle 30
]
main = writeSVG 2 "example11.svg" out

View File

@ -2,7 +2,8 @@
import Graphics.Implicit
out = unionR 14 [
rectR 0 (-40,-40) (40,40),
translate (40,40) (circle 30) ]
squareR 0 (80, 80)
, translate (40,40) $ circle 30
]
main = writeSVG 2 "example12.svg" out

View File

@ -2,7 +2,8 @@
import Graphics.Implicit
out = union [
rect3R 0 (0,0,0) (20,20,20),
translate (20,20,20) (sphere 15) ]
cubeR 0 False (20, 20, 20)
, translate (20, 20, 20) $ sphere 15
]
main = writeSTL 1 "example13.stl" out

View File

@ -3,22 +3,20 @@ import Prelude ((<$>), ($), zip3, fmap, fromIntegral, (*), (/))
import Graphics.Implicit (union, translate, rect3R, writeSTL)
import Graphics.Implicit.Definitions (Fast, , 3, SymbolicObj3)
default (Fast, )
object2 :: SymbolicObj3
object2 = squarePipe (10,10,10) 1 100
object2 = squarePipe (10, 10, 10) 1 100
where
squarePipe :: 3 -> -> -> SymbolicObj3
squarePipe (x,y,z) diameter precision =
union
((\start-> translate start
$ rect3R 0 (0,0,0) (diameter,diameter,diameter)
((\start -> translate start
$ cubeR 0 False (diameter, diameter, diameter)
)
<$>
zip3 (fmap (\n->(fromIntegral n/precision)*x) [0..100])
(fmap (\n->(fromIntegral n/precision)*y) [0..100])
(fmap (\n->(fromIntegral n/precision)*z) [0..100]))
zip3 (fmap (\n -> (fromIntegral n / precision) * x) [0..100])
(fmap (\n -> (fromIntegral n / precision) * y) [0..100])
(fmap (\n -> (fromIntegral n / precision) * z) [0..100]))
main = writeSTL 1 "example17.stl" object2

View File

@ -196,8 +196,9 @@ Everything you saw above can be done with the Haskell API. For example, a simple
import Graphics.Implicit
out = union [
rectR 0 (-40,-40) (40,40),
translate (40,40) (circle 30) ]
squareR 0 True (80, 80)
, translate (40, 40) (circle 30)
]
main = writeSVG 2 "test.svg" out
```
@ -212,8 +213,9 @@ A rounded union:
import Graphics.Implicit
out = unionR 14 [
rectR 0 (-40,-40) (40,40),
translate (40,40) (circle 30) ]
squareR 0 True (80, 80)
, translate (80, 80) (circle 30)
]
main = writeSVG 2 "test.svg" out
```
@ -227,8 +229,9 @@ A simple 3D example:
import Graphics.Implicit
out = union [
rect3R 0 (0,0,0) (20,20,20),
translate (20,20,20) (sphere 15) ]
cubeR 0 False (20, 20, 20)
, translate (20, 20, 20) (sphere 15)
]
main = writeSTL 1 "test.stl" out
```