-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
{-| | ||
Module : Lsystem.Generator | ||
Description : Generate the L-system | ||
Copyright : (c) Zebulun Arendsee, 2018 | ||
License : MIT | ||
Maintainer : [email protected] | ||
Stability : experimental | ||
-} | ||
|
||
module Lsystem.Generator | ||
( | ||
step | ||
|
@@ -40,9 +49,9 @@ applyRules g lc rc rs n = fromMaybe [n] . firstSuccess (applyRule p) $ rs | |
applyRule :: Chance -> Rule -> Maybe [Node] | ||
applyRule _ (DeterministicRule cont cond match repl) = | ||
return (repl lc rc n) -- replace node if: | ||
>>= match n -- * the node is of the correct form | ||
>>= cont lc rc -- * it is in the required context | ||
>>= cond lc rc n -- * all parametric restrictions are met | ||
>>= match n -- the node is of the correct form | ||
>>= cont lc rc -- it is in the required context | ||
>>= cond lc rc n -- all parametric restrictions are met | ||
applyRule p (StochasticRule rs') = case (choose p rs') of | ||
-- p is rescaled by dividing by the selected rule's probability | ||
Just (cp', r) -> applyRule (p / cp') r | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
{-| | ||
Module : Lsystem.Grammar | ||
Description : Core types | ||
Copyright : (c) Zebulun Arendsee, 2018 | ||
License : MIT | ||
Maintainer : [email protected] | ||
Stability : experimental | ||
-} | ||
|
||
module Lsystem.Grammar | ||
( | ||
System(..) | ||
|
@@ -13,17 +22,17 @@ module Lsystem.Grammar | |
, Chance | ||
) where | ||
|
||
-- context-sensitive stochastic parameterized L-systems | ||
-- | ||
|
||
type Distance = Double -- x > 0 | ||
type Yaw = Double -- -180 < x < 180 | ||
type Pitch = Double -- -180 < x < 180 | ||
type Roll = Double -- -180 < x < 180 | ||
type Distance = Double -- ^ x > 0 | ||
type Yaw = Double -- ^ -180 < x < 180 | ||
type Pitch = Double -- ^ -180 < x < 180 | ||
type Roll = Double -- ^ -180 < x < 180 | ||
|
||
type LeftContext = [Node] | ||
type RightContext = [Node] | ||
|
||
type Chance = Double -- 0 <= x <= 1 | ||
type Chance = Double -- ^ 0 <= x <= 1 | ||
|
||
data System = System { | ||
systemBasis :: [Node] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,15 @@ | |
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
{-| | ||
Module : Lsystem.Render | ||
Description : Render a generated L-system | ||
Copyright : (c) Zebulun Arendsee, 2018 | ||
License : MIT | ||
Maintainer : [email protected] | ||
Stability : experimental | ||
-} | ||
|
||
module Lsystem.Render | ||
( | ||
renderSystem | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
{-| | ||
Module : Lsystem.Sugar | ||
Description : Functions for simplifying L-system specification | ||
Copyright : (c) Zebulun Arendsee, 2018 | ||
License : MIT | ||
Maintainer : [email protected] | ||
Stability : experimental | ||
-} | ||
|
||
module Lsystem.Sugar | ||
( | ||
transDol | ||
|
@@ -68,11 +77,11 @@ matchWidth _ _ = Nothing | |
unconditional :: LeftContext -> RightContext -> Node -> a -> Maybe a | ||
unconditional _ _ _ x = Just x | ||
|
||
-- Check is A is a similar to B. For branches, A must be a subtree of B. | ||
-- | Check is A is a similar to B. For branches, A must be a subtree of B. | ||
similar | ||
:: Node -- A | ||
-> Node -- B | ||
-> Bool -- True is A is in B (where `in` is weirdly defined ...) | ||
:: Node -- ^ A | ||
-> Node -- ^ B | ||
-> Bool -- ^ True if A is in B (where `in` is weirdly defined ...) | ||
similar (NodeDummy _ s) (NodeDummy _ t) = s == t | ||
similar (NodeDraw _ _ ) (NodeDraw _ _) = True | ||
similar (NodeRotate _ _ _ _) (NodeRotate _ _ _ _) = True | ||
|
@@ -92,11 +101,11 @@ similar (NodeBranch mss) (NodeBranch nss) = any id $ map (anyBranch nss) mss | |
similar _ _ = False | ||
|
||
contextMatch | ||
:: [Node] -- elements to ignore | ||
-> [Node] -- left contextual pattern | ||
-> [Node] -- right contextual pattern | ||
-> [Node] -- left context | ||
-> [Node] -- right context | ||
:: [Node] -- ^ elements to ignore | ||
-> [Node] -- ^ left contextual pattern | ||
-> [Node] -- ^ right contextual pattern | ||
-> [Node] -- ^ left context | ||
-> [Node] -- ^ right context | ||
-> a -> Maybe a -- combinator kludge (I really should go to Bool) | ||
contextMatch ss lpat rpat lc rc x = | ||
return x | ||
|