Skip to content

Instantly share code, notes, and snippets.

@sorki
Created April 23, 2022 13:44
Show Gist options
  • Save sorki/611dd83388b5f51fbd88b1927c6d7a14 to your computer and use it in GitHub Desktop.
Save sorki/611dd83388b5f51fbd88b1927c6d7a14 to your computer and use it in GitHub Desktop.
Displace implicit function
import Prelude
import Control.Applicative (pure)
import Graphics.Implicit
import Graphics.Implicit.Definitions
import Graphics.Implicit.Primitives
displaced
:: (Object obj vec)
=> (vec -> Double)
-> obj
-> obj
displaced dispFn obj = implicit
(\i ->
let prim = getImplicit obj i
disp = dispFn i
in prim + disp
)
-- XXX
((*2) <$> getBox obj)
mul (V3 a b c) = a * b * c
-- main = writeSTL 1 "displaced.stl" $ displaced (\v@(V3 x y z) -> mul ( (cos . (*(2))) <$> v ) ) $ sphere 10
main = writeSTL 1 "displaced.stl" $ displaced (\v@(V3 x y z) -> mul (
V3 (sin . (*(2)) $ x)
(cos . (*(1/2)) $ y)
(sin z)
) ) $ sphere 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment