This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
67e37a6
commit e505b1d
Showing
15 changed files
with
133 additions
and
35 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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Lunarbox.Data.Dataflow.Native.ControlFlow | ||
( if' | ||
) where | ||
|
||
import Lunarbox.Data.Dataflow.Expression (NativeExpression(..)) | ||
import Lunarbox.Data.Dataflow.Native.NativeConfig (NativeConfig(..)) | ||
import Lunarbox.Data.Dataflow.Runtime (RuntimeValue(..), binaryFunction) | ||
import Lunarbox.Data.Dataflow.Scheme (Scheme(..)) | ||
import Lunarbox.Data.Dataflow.Type (TVarName(..), Type(..), typeBool) | ||
import Lunarbox.Data.Editor.FunctionData (FunctionData, internal) | ||
import Lunarbox.Data.Editor.FunctionName (FunctionName(..)) | ||
import Prelude (const, flip, ($)) | ||
|
||
typeIf :: Scheme | ||
typeIf = Forall [ return ] $ TArrow typeBool $ TArrow typeReturn typeReturn | ||
where | ||
return = TVarName "a" | ||
|
||
typeReturn = TVarariable return | ||
|
||
evalIf :: RuntimeValue -> RuntimeValue | ||
evalIf (Bool true) = binaryFunction const | ||
|
||
evalIf _ = binaryFunction $ flip const | ||
|
||
if' :: NativeConfig FunctionData | ||
if' = | ||
NativeConfig | ||
{ name: FunctionName "if" | ||
, expression: (NativeExpression typeIf $ Function evalIf) | ||
, functionData: internal [ { name: "condition" }, { name: "then" }, { name: "else" } ] | ||
} |
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
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
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
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
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
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,5 +1,19 @@ | ||
module Lunarbox.Data.Editor.Constants (nodeRadius) where | ||
module Lunarbox.Data.Editor.Constants | ||
( nodeRadius | ||
, arcSpacing | ||
, arcWidth | ||
) where | ||
|
||
import Math (Radians) | ||
|
||
-- visual radius for nodes | ||
nodeRadius :: Number | ||
nodeRadius = 50.0 | ||
|
||
-- How much spage to display between node inputs | ||
arcSpacing :: Radians | ||
arcSpacing = 0.1 | ||
|
||
-- What width should the stroke of node inputs have | ||
arcWidth :: Number | ||
arcWidth = 5.0 |
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
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,10 +1,44 @@ | ||
module Lunarbox.Svg.Attributes where | ||
module Lunarbox.Svg.Attributes | ||
( strokeWidth | ||
, arc | ||
, transparent | ||
) where | ||
|
||
import Prelude | ||
import Data.Typelevel.Num (d0, d1) | ||
import Data.Vec (vec2, (!!)) | ||
import Halogen.HTML (IProp) | ||
import Lunarbox.Capability.Editor.Node.NodeInput (Arc(..), length) | ||
import Lunarbox.Data.Vector (Vec2) | ||
import Math (Radians, cos, pi, sin) | ||
import Svg.Attributes (Color(..), Command(..)) | ||
import Svg.Attributes as SA | ||
import Unsafe.Coerce (unsafeCoerce) | ||
|
||
-- There's a bug with halogen-svg which doen's allow me to use this | ||
-- so I made a wrapper which allows me anywhere where I can use a stroke | ||
strokeWidth :: forall r i. Number -> IProp ( stroke :: String | r ) i | ||
strokeWidth = unsafeCoerce SA.strokeWidth | ||
|
||
polarToCartesian :: Number -> Radians -> Vec2 Number | ||
polarToCartesian radius angle = (radius * _) <$> vec2 (cos angle) (sin angle) | ||
|
||
arcLength :: Radians -> Radians -> Radians | ||
arcLength start end = length $ Arc start end unit | ||
|
||
-- The A command for svg is pretty hard to use. | ||
-- This is a wrapper which allows using it for circle arcs | ||
arc :: Number -> Radians -> Radians -> Array Command | ||
arc radius startAngle endAngle = | ||
let | ||
start = polarToCartesian radius endAngle | ||
|
||
end = polarToCartesian radius startAngle | ||
|
||
largeArcFlag = not $ arcLength startAngle endAngle >= pi | ||
in | ||
[ M (start !! d0) $ start !! d1, A radius radius 0.0 largeArcFlag true (end !! d0) (end !! d1) ] | ||
|
||
-- Transparent color | ||
transparent :: Color | ||
transparent = RGBA 0 0 0 0.0 |