Skip to content

Commit

Permalink
n property representing number of currently pertinent object added to…
Browse files Browse the repository at this point in the history
… SuperContinent as a potential element of a ValueGraph
  • Loading branch information
dktr0 committed Dec 19, 2018
1 parent 9408c5a commit 8ef76be
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ releaseClient: # make installClient or prodInstallClient first!

curlReleaseClient: # this uses curl to download and unzip a recent pre-built client from a GitHub release
rm -rf Estuary.jsexe
curl -o temp.zip -L https://github.com/d0kt0r0/estuary/releases/download/20181218/estuary-client-20181218.zip
curl -o temp.zip -L https://github.com/d0kt0r0/estuary/releases/download/20181219/estuary-client-20181219.zip
unzip temp.zip
rm -rf temp.zip
cp -Rf static/Dirt Estuary.jsexe
Expand Down
37 changes: 20 additions & 17 deletions client/src/Estuary/Languages/SuperContinent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ data ValueGraph =
Sum ValueGraph ValueGraph |
Product ValueGraph ValueGraph |
AudioProperty | -- for now there is only one audio property... but later this type can have more values
Random -- a random value between -1 and 1
Random | -- a random value between -1 and 1
ObjectN -- the number of the currently relevant object
deriving (Show)
-- *** should add a property reflecting current position in meter as well!

Expand All @@ -107,6 +108,7 @@ valueGraphComponent = choice [
parens valueGraphParser,
reserved "audio" >> return AudioProperty,
reserved "random" >> return Random,
reserved "n" >> return ObjectN,
valueParser >>= return . Constant
]

Expand Down Expand Up @@ -219,34 +221,35 @@ runDeltasOnObjects :: Double -> IntMap Object -> [Delta] -> ST (IntMap Object)
runDeltasOnObjects audio objs deltas = foldM (runDeltaOnObjects audio) objs deltas

runDeltaOnObjects :: Double -> IntMap Object -> Delta -> ST (IntMap Object)
runDeltaOnObjects audio objs delta = mapM (runDeltaOnObject audio delta) objs

runDeltaOnObject :: Double -> Delta -> Object -> ST Object
runDeltaOnObject audio (Delta prop graph) obj = do
val <- getValueFromGraph audio graph
runDeltaOnObjects audio objs delta = sequence $ mapWithKey (\k v -> runDeltaOnObject k audio delta v) objs
runDeltaOnObject :: Int -> Double -> Delta -> Object -> ST Object
runDeltaOnObject objectN audio (Delta prop graph) obj = do
val <- getValueFromGraph objectN audio graph
return $ Map.insert prop val obj

getValueFromGraph :: Double -> ValueGraph -> ST Value
getValueFromGraph _ (Constant v) = return v
getValueFromGraph audio (Sum x y) = do
x' <- getValueFromGraph audio x
y' <- getValueFromGraph audio y
getValueFromGraph :: Int -> Double -> ValueGraph -> ST Value
getValueFromGraph _ _ (Constant v) = return v
getValueFromGraph objectN audio (Sum x y) = do
x' <- getValueFromGraph objectN audio x
y' <- getValueFromGraph objectN audio y
return $ sumOfValues x' y'
getValueFromGraph audio (Product x y) = do
x' <- getValueFromGraph audio x
y' <- getValueFromGraph audio y
getValueFromGraph objectN audio (Product x y) = do
x' <- getValueFromGraph objectN audio x
y' <- getValueFromGraph objectN audio y
return $ productOfValues x' y'
getValueFromGraph audio (AudioProperty) = return $ ValueDouble audio
getValueFromGraph _ (Random) = do
getValueFromGraph _ audio (AudioProperty) = return $ ValueDouble audio
getValueFromGraph _ _ (Random) = do
x <- gets randomGen
y <- liftIO $ uniform x
return $ ValueDouble y
getValueFromGraph objectN _ ObjectN = return $ ValueInt objectN

-- below this line all there is is our Parsec tokenized parsing definitions

tokenParser :: P.TokenParser a
tokenParser = P.makeTokenParser $ haskellDef {
P.reservedNames = ["type","x0","y0","x1","y1","x2","y2","nil","triangle","audio","random","r","g","b","a"],
P.reservedNames = ["type","x0","y0","x1","y1","x2","y2","nil","triangle","audio","random","r","g","b","a","n"],
P.reservedOpNames = ["..","=","*","+"]
}

Expand Down

0 comments on commit 8ef76be

Please sign in to comment.