Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It compiles after adding lightning and building a crappy framework
- Loading branch information
1 parent
c3eee85
commit 85d8e53
Showing
10 changed files
with
587 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
module Effects exposing (Effect, applyModifier, build, draw, modConstructor, model, modifiers, tick, updateModel) | ||
|
||
import Html exposing (Html) | ||
import Messages exposing (..) | ||
import Time exposing (Posix) | ||
|
||
|
||
type Effect model mod | ||
= Effect | ||
{ draw : model -> Html Message | ||
, mods : List ( mod, String, model -> Float ) | ||
, model : model | ||
, tick : Posix -> model -> model | ||
, modConstructor : mod -> Modifier | ||
, applyModifier : Effect model mod -> mod -> Float -> Effect model mod | ||
} | ||
|
||
|
||
build : | ||
{ draw : model -> Html Message | ||
, mods : List ( mod, String, model -> Float ) | ||
, model : model | ||
, tick : Posix -> model -> model | ||
, modConstructor : mod -> Modifier | ||
, applyModifier : Effect model mod -> mod -> Float -> Effect model mod | ||
} | ||
-> Effect model mod | ||
build config = | ||
Effect config | ||
|
||
|
||
draw : Effect model mod -> Html Message | ||
draw (Effect eff) = | ||
eff.draw eff.model | ||
|
||
|
||
modifiers : Effect model mod -> List ( mod, String, model -> Float ) | ||
modifiers (Effect eff) = | ||
eff.mods | ||
|
||
|
||
model : Effect model mod -> model | ||
model (Effect eff) = | ||
eff.model | ||
|
||
|
||
modConstructor : Effect model mod -> (mod -> Modifier) | ||
modConstructor (Effect eff) = | ||
eff.modConstructor | ||
|
||
|
||
tick : Effect model mod -> Posix -> Effect model mod | ||
tick (Effect eff) time = | ||
Effect { eff | model = eff.tick time eff.model } | ||
|
||
|
||
updateModel : Effect model mod -> (model -> model) -> Effect model mod | ||
updateModel (Effect eff) fn = | ||
Effect <| | ||
{ eff | model = fn eff.model } | ||
|
||
|
||
applyModifier : Effect model mod -> mod -> Float -> Effect model mod | ||
applyModifier ((Effect eff) as effect) mod val = | ||
eff.applyModifier effect mod val |
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,64 @@ | ||
module Lightning.EffectView exposing (draw) | ||
|
||
import Arc2d | ||
import Color exposing (Color, rgb) | ||
import Html exposing (Html) | ||
import Lightning.Model exposing (..) | ||
import Messages exposing (Message) | ||
import Point2d as Point | ||
import TypedSvg exposing (..) | ||
import TypedSvg.Attributes as Attributes exposing (..) | ||
import TypedSvg.Core exposing (..) | ||
import TypedSvg.Types exposing (..) | ||
|
||
|
||
draw : Model -> Html Message | ||
draw model = | ||
svg | ||
[ width (model.window.width - 200 |> px) | ||
, height (model.window.height |> px) | ||
] | ||
([ rect | ||
[ width (100 |> percent) | ||
, height (100 |> percent) | ||
, fill (rgb 0 0 0 |> Fill) | ||
] | ||
[] | ||
] | ||
++ List.concat (List.map drawBolt model.bolts) | ||
) | ||
|
||
|
||
drawBolt : Bolt -> List (Svg Message) | ||
drawBolt bolt = | ||
List.concat (List.map (drawArc bolt.origin) bolt.arcs) | ||
|
||
|
||
drawArc : Coords -> Arc -> List (Svg Message) | ||
drawArc { x, y } (Arc arc) = | ||
let | ||
( endX, endY ) = | ||
Arc2d.with | ||
{ centerPoint = Point.fromCoordinates ( x, y ) | ||
, radius = arc.length | ||
, startAngle = 0 | ||
, sweptAngle = arc.angle | ||
} | ||
|> Arc2d.endPoint | ||
|> Point.coordinates | ||
in | ||
[ line | ||
[ x1 (x |> px) | ||
, y1 (y |> px) | ||
, x2 (endX |> px) | ||
, y2 (endY |> px) | ||
, stroke arcColor | ||
] | ||
[] | ||
] | ||
++ List.concat (List.map (drawArc { x = endX, y = endY }) arc.arcs) | ||
|
||
|
||
arcColor : Color | ||
arcColor = | ||
rgb 1 1 1 |
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,11 @@ | ||
module Lightning.Messages exposing (Modifier(..)) | ||
|
||
import Json.Decode as Json | ||
import Time exposing (Posix) | ||
|
||
|
||
type Modifier | ||
= Fremulation | ||
| Chaos | ||
| Dilation | ||
| Zoom |
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,53 @@ | ||
module Lightning.Model exposing (Arc(..), Bolt, Coords, Dimensions, Model, init) | ||
|
||
import Messages exposing (Message) | ||
import Random | ||
|
||
|
||
type alias Model = | ||
{ window : Dimensions | ||
, bolts : List Bolt | ||
, fremulation : Float | ||
, chaos : Float | ||
, dilation : Float | ||
, zoom : Float | ||
} | ||
|
||
|
||
type alias Dimensions = | ||
{ width : Float, height : Float } | ||
|
||
|
||
type alias Coords = | ||
{ x : Float, y : Float } | ||
|
||
|
||
type alias Bolt = | ||
{ origin : Coords | ||
, lifeTime : Int | ||
, seed : Random.Seed | ||
, arcs : List Arc | ||
} | ||
|
||
|
||
type Arc | ||
= Arc ArcInfo | ||
|
||
|
||
type alias ArcInfo = | ||
{ length : Float | ||
, arcs : List Arc | ||
, angle : Float | ||
, origAngle : Float | ||
} | ||
|
||
|
||
init : { a | window : Dimensions } -> Model | ||
init flags = | ||
{ window = flags.window | ||
, bolts = [] | ||
, fremulation = 0.5 | ||
, chaos = 0.5 | ||
, dilation = 0.5 | ||
, zoom = 0.5 | ||
} |
Oops, something went wrong.