Update examples to new API

Closes #360.
This commit is contained in:
Richard Marko 2021-04-17 13:36:00 +02:00
parent b77993656e
commit ed7e38f2c8
5 changed files with 24 additions and 15 deletions

View File

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

View File

@ -1,9 +1,10 @@
-- Example 12 - the rounded union of a square and a circle. -- Example 12 - the rounded union of a square and a circle.
import Control.Applicative (pure)
import Graphics.Implicit import Graphics.Implicit
out = unionR 14 [ out = unionR 14 [
squareR 0 (80, 80) square True (pure 80) -- pure 80 turns into (V2 80 80)
, translate (40,40) $ circle 30 , translate (pure 40) $ circle 30
] ]
main = writeSVG 2 "example12.svg" out main = writeSVG 2 "example12.svg" out

View File

@ -1,9 +1,10 @@
-- Example 13 - the rounded union of a cube and a sphere. -- Example 13 - the rounded union of a cube and a sphere.
import Control.Applicative (pure)
import Graphics.Implicit import Graphics.Implicit
out = union [ out = union [
cubeR 0 False (20, 20, 20) cube False (pure 20) -- same as (V3 20 20 20)
, translate (20, 20, 20) $ sphere 15 , translate (pure 20) $ sphere 15
] ]
main = writeSTL 1 "example13.stl" out main = writeSTL 1 "example13.stl" out

View File

@ -1,8 +1,12 @@
import Control.Applicative (pure)
import Graphics.Implicit import Graphics.Implicit
import Graphics.Implicit.Definitions import Graphics.Implicit.Definitions
import Graphics.Implicit.Primitives import Graphics.Implicit.Primitives
roundbox:: SymbolicObj3 roundbox:: SymbolicObj3
roundbox = implicit (\(x,y,z) -> x^4 + y^4 + z^4 - 15000) ((-20,-20,-20),(20,20,20)) roundbox =
implicit
(\(V3 x y z) -> x^4 + y^4 + z^4 - 15000)
(pure (-20), pure 20)
main = writeSTL 2 "example16.stl" roundbox main = writeSTL 2 "example16.stl" roundbox

View File

@ -1,22 +1,25 @@
-- Example 17, pulled from our benchmarking suite. -- Example 17, pulled from our benchmarking suite.
import Prelude ((<$>), ($), zip3, fmap, fromIntegral, (*), (/)) import Control.Applicative (pure)
import Graphics.Implicit (union, translate, rect3R, writeSTL) import Prelude ((<$>), ($), zipWith3, fmap, fromIntegral, (*), (/), Bool(..))
import Graphics.Implicit (cube, union, translate, writeSTL, V3(..))
import Graphics.Implicit.Definitions (Fast, , 3, SymbolicObj3) import Graphics.Implicit.Definitions (Fast, , 3, SymbolicObj3)
default (Fast, ) default (Fast, )
object2 :: SymbolicObj3 object2 :: SymbolicObj3
object2 = squarePipe (10, 10, 10) 1 100 object2 = squarePipe (pure 10) 1 100
where where
squarePipe :: 3 -> -> -> SymbolicObj3 squarePipe :: 3 -> -> -> SymbolicObj3
squarePipe (x,y,z) diameter precision = squarePipe (V3 x y z) diameter precision =
union union
((\start -> translate start ((\start -> translate start
$ cubeR 0 False (diameter, diameter, diameter) $ cube True (pure diameter)
) )
<$> <$>
zip3 (fmap (\n -> (fromIntegral n / precision) * x) [0..100]) zipWith3
(fmap (\n -> (fromIntegral n / precision) * y) [0..100]) V3
(fmap (\n -> (fromIntegral n / precision) * z) [0..100])) (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 main = writeSTL 1 "example17.stl" object2