Skip to content

Commit

Permalink
Weird stuff going on
Browse files Browse the repository at this point in the history
  • Loading branch information
noahzgordon committed Jun 6, 2019
1 parent 9dc7e74 commit 763b105
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 35 deletions.
23 changes: 20 additions & 3 deletions src/Main.elm
Expand Up @@ -31,6 +31,11 @@ main =
{ title = Effects.name eff
, body = View.draw eff model.otherEffects
}

NoiseEffect eff ->
{ title = Effects.name eff
, body = View.draw eff model.otherEffects
}
, update = update
, subscriptions = subscriptions
}
Expand All @@ -53,6 +58,10 @@ update message model =
LightningEffect eff ->
LightningEffect <|
Effects.tick eff time

NoiseEffect eff ->
NoiseEffect <|
Effects.tick eff time
}
, Cmd.none
)
Expand Down Expand Up @@ -92,16 +101,24 @@ update message model =
CloudEffect _ ->
False

LightningEffect _ ->
_ ->
True

LightningEffect _ ->
case otherEff of
CloudEffect _ ->
LightningEffect _ ->
False

_ ->
True

LightningEffect _ ->
NoiseEffect _ ->
case otherEff of
NoiseEffect _ ->
False

_ ->
True
)
|> List.append [ model.currentEffect ]
}
Expand Down
3 changes: 3 additions & 0 deletions src/Messages.elm
Expand Up @@ -4,6 +4,7 @@ import Clouds.Model
import Html exposing (Html)
import Json.Decode as Json
import Lightning.Model
import Noise.Model
import Time exposing (Posix)


Expand All @@ -22,11 +23,13 @@ type Effect model mod
type MetaEffect
= CloudEffect (Effect Clouds.Model.Model CloudModifier)
| LightningEffect (Effect Lightning.Model.Model LightningModifier)
| NoiseEffect (Effect Noise.Model.Model ())


type Modifier
= CloudMod CloudModifier
| LightningMod LightningModifier
| NoiseMod ()


type CloudModifier
Expand Down
52 changes: 32 additions & 20 deletions src/Model.elm
Expand Up @@ -9,6 +9,8 @@ import Lightning.EffectView
import Lightning.Model
import Lightning.Update
import Messages exposing (..)
import Noise.EffectView
import Noise.Model
import Time exposing (Posix)


Expand All @@ -31,27 +33,15 @@ type alias Flags =
init : Flags -> ( Model, Cmd Message )
init flags =
( { currentEffect =
CloudEffect <|
NoiseEffect <|
Effects.build
{ name = "O'Keefe Clouds"
, draw = Clouds.EffectView.draw
, mods =
[ ( Extremity, "funkitude", .extremity )
, ( Speed, "speed", .speed )
]
, model = Clouds.Model.init flags
, tick = Clouds.Update.tick
, modConstructor = CloudMod
, applyModifier =
\effect mod val ->
case mod of
Extremity ->
Effects.updateModel effect
(\m -> { m | extremity = val })

Speed ->
Effects.updateModel effect
(\m -> { m | speed = val })
{ name = "Noise"
, draw = Noise.EffectView.draw
, mods = []
, model = Noise.Model.init flags
, tick = \t m -> { m | time = Time.posixToMillis t }
, modConstructor = NoiseMod
, applyModifier = \eff _ _ -> eff
}
, otherEffects =
[ LightningEffect <|
Expand Down Expand Up @@ -86,6 +76,28 @@ init flags =
Effects.updateModel effect
(\m -> { m | zoom = val })
}
, CloudEffect <|
Effects.build
{ name = "O'Keefe Clouds"
, draw = Clouds.EffectView.draw
, mods =
[ ( Extremity, "funkitude", .extremity )
, ( Speed, "speed", .speed )
]
, model = Clouds.Model.init flags
, tick = Clouds.Update.tick
, modConstructor = CloudMod
, applyModifier =
\effect mod val ->
case mod of
Extremity ->
Effects.updateModel effect
(\m -> { m | extremity = val })

Speed ->
Effects.updateModel effect
(\m -> { m | speed = val })
}
]
}
, Cmd.none
Expand Down
65 changes: 65 additions & 0 deletions src/Noise/EffectView.elm
@@ -0,0 +1,65 @@
module Noise.EffectView exposing (draw)

import Color exposing (Color, rgba)
import Html exposing (Html)
import Messages exposing (Message)
import Noise.Model exposing (..)
import Perlin
import TypedSvg exposing (..)
import TypedSvg.Attributes as Attributes exposing (..)
import TypedSvg.Core exposing (..)
import TypedSvg.Types exposing (..)


draw : Model -> Html Message
draw model =
let
imageWidth =
model.window.width - 200

baseHeight =
model.window.height / 2
in
svg
[ width (imageWidth |> px)
, height (model.window.height |> px)
]
(List.concat
[ [ line
[ x1 (px 20)
, x2 (px <| imageWidth - 20)
, y1 (px baseHeight)
, y2 (px baseHeight)
, stroke (rgba 0 0 0 0.3)
, strokeWidth (px 5)
]
[]
]
, List.range 20 (round <| imageWidth - 20)
|> List.map toFloat
|> List.foldl
(\x ( lastY, lines ) ->
let
xPos =
x / imageWidth - 40

newY =
Perlin.noise ( xPos, lastY, toFloat model.time / 8640 ) model.seed
in
( newY
, lines
++ [ line
[ x1 (px x)
, x2 (px (x + 1))
, y1 (px (lastY * model.window.height))
, y2 (px (newY * model.window.height))
, stroke (rgba 0 0 0 1)
]
[]
]
)
)
( Perlin.noise ( 19 / imageWidth - 40, 0, toFloat model.time / 8640 ) model.seed, [] )
|> Tuple.second
]
)
22 changes: 22 additions & 0 deletions src/Noise/Model.elm
@@ -0,0 +1,22 @@
module Noise.Model exposing (Model, init)

import Random


type alias Model =
{ window : Dimensions
, seed : Random.Seed
, time : Int
}


type alias Dimensions =
{ width : Float, height : Float }


init : { a | window : Dimensions, time : Int } -> Model
init flags =
{ window = flags.window
, seed = Random.initialSeed flags.time
, time = flags.time
}

0 comments on commit 763b105

Please sign in to comment.