Created
September 17, 2015 19:59
-
-
Save mgold/8a2fb3af88d1347c0475 to your computer and use it in GitHub Desktop.
Sine animation (Elm 0.15.1)
This file contains hidden or 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
import Graphics.Collage exposing (..) | |
import Color exposing (rgb) | |
import Window | |
import Time | |
obj_resolution = 360 | |
waves_amount=6 | |
wave_height=0.1 | |
sine_pct=0.5 -- setting in percantage how big is the part | |
smoothing_amount=0.14 | |
smooth_pct=1 | |
sine_resolution = sine_pct*obj_resolution | |
smoothed_resolution = sine_resolution*smoothing_amount | |
colors = [rgb 55 147 146, rgb 46 73 82, rgb 11 201 199] | |
phases = [0, degrees 90 , degrees 180] | |
data = List.map2 (,) colors phases | |
width i r = {r| width <- i} | |
waves w h t = | |
let radius = (min w h) |> toFloat |> (*) 0.4 | |
points phase = List.map (wavePoint radius phase t) [0..obj_resolution] | |
wave (color, phase) = points phase |> path |> traced (solid color |> width 6) | |
in List.map wave data |> group | |
wavePoint radius phase t i = | |
let angle = degrees i -- only works because obj_resolution = 360 | |
smooth_pct = | |
if i < smoothed_resolution | |
then i/smoothed_resolution | |
else if i > sine_resolution*(1-smoothing_amount) && i <= sine_resolution | |
then (sine_resolution-i)/smoothed_resolution | |
else if i == obj_resolution | |
then 0 | |
else 1 | |
radiusAddon = | |
if i > sine_resolution && i /= obj_resolution | |
then 0 | |
else radius*wave_height*smooth_pct*cos((angle+t)*waves_amount+phase) | |
in fromPolar (radius+radiusAddon+phase*3, angle+t) | |
clock = Signal.foldp (\dt t -> t - dt/650) 0 (Time.fps 30) | |
black = rgb 16 16 16 | |
scene (w,h) t = | |
collage w h | |
[ rect (toFloat w) (toFloat h) |> filled black | |
, waves w h t | |
] | |
main = Signal.map2 scene Window.dimensions clock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment