Skip to content

Commit

Permalink
It compiles after adding lightning and building a crappy framework
Browse files Browse the repository at this point in the history
  • Loading branch information
noahzgordon committed Jun 5, 2019
1 parent c3eee85 commit 85d8e53
Show file tree
Hide file tree
Showing 10 changed files with 587 additions and 40 deletions.
18 changes: 8 additions & 10 deletions src/Clouds/Model.elm
Expand Up @@ -57,7 +57,7 @@ type alias Flags =
}


init : Flags -> ( Model, Cmd Message )
init : Flags -> Model
init flags =
let
seed =
Expand All @@ -66,15 +66,13 @@ init flags =
width =
flags.window.width - 200
in
( { window = flags.window
, cloudRows =
[ buildCloudRow 0.5 width seed
]
, extremity = 0.5
, speed = 0.5
}
, Cmd.none
)
{ window = flags.window
, cloudRows =
[ buildCloudRow 0.5 width seed
]
, extremity = 0.5
, speed = 0.5
}


type alias CloudBuildData =
Expand Down
65 changes: 65 additions & 0 deletions src/Effects.elm
@@ -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
64 changes: 64 additions & 0 deletions src/Lightning/EffectView.elm
@@ -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
11 changes: 11 additions & 0 deletions src/Lightning/Messages.elm
@@ -0,0 +1,11 @@
module Lightning.Messages exposing (Modifier(..))

import Json.Decode as Json
import Time exposing (Posix)


type Modifier
= Fremulation
| Chaos
| Dilation
| Zoom
53 changes: 53 additions & 0 deletions src/Lightning/Model.elm
@@ -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
}

0 comments on commit 85d8e53

Please sign in to comment.