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
9dc7e74
commit 763b105
Showing
7 changed files
with
314 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
] | ||
) |
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,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 | ||
} |
Oops, something went wrong.