Skip to content

Commit

Permalink
Rewrote demo selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Miko Mynttinen committed Apr 1, 2016
1 parent 715033c commit af832a8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 14 deletions.
77 changes: 63 additions & 14 deletions demo1.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,75 @@ import Window
import Plasma exposing (..)
import Hypnocorn exposing (..)
import Rotozoom exposing (..)
import Starfield

main =
Signal.map3 view Window.width Window.height (Signal.foldp (+) 0 (fps 30))

view w h t =
if ((t/1000) < 10) then
cornfield w h t
else if ((t/1000) < 40) then
rotozoom w h t
else if ((t/1000) < 60) then
hypnocorn w h t
else if ((t/1000) < 80) then
plasma w h t

type Effect = Cornfield | Rotozoom | Hypnocorn | Plasma | Starfield | Chilicorn

type alias State =
{ effect : Effect
, time : Float
, stars: Starfield.Stars
}

initialState : State
initialState =
{ effect = Chilicorn
, time = 0
, stars = Starfield.stars
}

updateState : Float -> State -> State
updateState time state =
let
effect = selectEffectTime (time / 1000)
in
{ state |
effect = effect,
time = time
}

selectEffectTime : Float -> Effect
selectEffectTime t =
if t < 10 then
Cornfield
else if t < 20 then
Starfield
else if t < 40 then
Rotozoom
else if t < 60 then
Hypnocorn
else if t < 80 then
Plasma
else
chilicorn w h t
Chilicorn


main : Signal Element
main =
Signal.map2 view (Signal.foldp updateState initialState (Signal.foldp (+) 0 (fps 60))) Window.dimensions


view : State -> (Int, Int) -> Element
view state (w, h) =
case state.effect of
Cornfield ->
cornfield w h state.time
Hypnocorn ->
hypnocorn w h state.time
Starfield ->
Starfield.view (Starfield.update state.time state.stars) (w, h)
Chilicorn ->
chilicorn w h state.time
Rotozoom ->
rotozoom w h state.time
Plasma ->
plasma w h state.time

chilicorn w h t =
collage w h
[ image h h "chilicorn.png"
|> toForm
|> scale (0.33)
|> alpha (1.05 - sin(t/1000))
]
]
2 changes: 2 additions & 0 deletions starfield.elm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module Starfield where

import Color exposing (..)
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
Expand Down

0 comments on commit af832a8

Please sign in to comment.