Skip to content

Commit

Permalink
More modifiers on wave clock, remove random colors
Browse files Browse the repository at this point in the history
  • Loading branch information
noahzgordon committed Jun 28, 2019
1 parent 4beb56b commit abf2951
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 30 deletions.
75 changes: 65 additions & 10 deletions elm.js
Expand Up @@ -8466,11 +8466,9 @@ var author$project$WaveClock$Model$init = function (flags) {
return {
angNoise: angNoise,
angle: (-elm$core$Basics$pi) / 2,
colorChange: -1,
colorVal: 254,
lastTick: flags.time,
lines: _List_Nil,
modifiers: {angNoise: 1, delay: 0, radNoise: 1, radius: 1, step: 1},
modifiers: {angNoise: 1, delay: 0, hue: 0, lightness: 0.5, radNoise: 1, radius: 1, saturation: 0, step: 1},
radNoise: radiusNoise,
seed: seed4,
time: elm$time$Time$millisToPosix(flags.time),
Expand All @@ -8481,8 +8479,11 @@ var author$project$WaveClock$Model$init = function (flags) {
};
var author$project$WaveClock$Update$AngNoise = {$: 'AngNoise'};
var author$project$WaveClock$Update$Delay = {$: 'Delay'};
var author$project$WaveClock$Update$Hue = {$: 'Hue'};
var author$project$WaveClock$Update$Lightness = {$: 'Lightness'};
var author$project$WaveClock$Update$RadNoise = {$: 'RadNoise'};
var author$project$WaveClock$Update$Radius = {$: 'Radius'};
var author$project$WaveClock$Update$Saturation = {$: 'Saturation'};
var author$project$WaveClock$Update$Step = {$: 'Step'};
var elm$core$Debug$log = _Debug_log;
var author$project$WaveClock$Update$modify = F3(
Expand Down Expand Up @@ -8523,22 +8524,46 @@ var author$project$WaveClock$Update$modify = F3(
modifiers,
{step: val * 2})
});
default:
case 'Delay':
return _Utils_update(
model,
{
modifiers: _Utils_update(
modifiers,
{delay: val})
});
case 'Hue':
return _Utils_update(
model,
{
modifiers: _Utils_update(
modifiers,
{hue: val})
});
case 'Saturation':
return _Utils_update(
model,
{
modifiers: _Utils_update(
modifiers,
{saturation: val})
});
default:
return _Utils_update(
model,
{
modifiers: _Utils_update(
modifiers,
{lightness: val})
});
}
});
var author$project$WaveClock$Update$tick = F2(
function (time, model) {
var timeInt = elm$time$Time$posixToMillis(time);
if (_Utils_cmp(
if ((model.modifiers.delay === 1) || (_Utils_cmp(
timeInt - elm$core$Basics$round(model.modifiers.delay * 1000),
model.lastTick) < 0) {
model.lastTick) < 0)) {
return model;
} else {
var radNoise = model.angNoise + 5.0e-3;
Expand All @@ -8547,7 +8572,6 @@ var author$project$WaveClock$Update$tick = F2(
_Utils_Tuple3(radNoise * model.modifiers.radNoise, 0, 0),
model.seed) * 550) * model.modifiers.radius) + 1;
var imageWidth = model.window.width - 200;
var colorVal = model.colorVal + model.colorChange;
var baseAngleStep = 6 * model.modifiers.step;
var baseAngle = (model.angle + (A2(
author$project$Perlin$noise,
Expand Down Expand Up @@ -8576,15 +8600,13 @@ var author$project$WaveClock$Update$tick = F2(
{
angNoise: angNoise,
angle: angle,
colorChange: (colorVal > 254) ? (-1) : ((colorVal < 0) ? 1 : model.colorChange),
colorVal: colorVal,
lastTick: timeInt,
lines: _Utils_ap(
model.lines,
_List_fromArray(
[
{
color: A4(avh4$elm_color$Color$rgba, colorVal / 255, colorVal / 255, colorVal / 255, 60 / 255),
color: A4(avh4$elm_color$Color$hsla, model.modifiers.hue, model.modifiers.saturation, model.modifiers.lightness, 60 / 255),
x1: centerX + (radius * elm$core$Basics$cos(rad)),
x2: centerX + (radius * elm$core$Basics$cos(oppRad)),
y1: centerY + (radius * elm$core$Basics$sin(rad)),
Expand Down Expand Up @@ -8836,6 +8858,39 @@ var author$project$Model$init = function (flags) {
},
function ($) {
return $.delay;
})),
_Utils_Tuple3(
author$project$WaveClock$Update$Hue,
'hue',
A2(
elm$core$Basics$composeR,
function ($) {
return $.modifiers;
},
function ($) {
return $.hue;
})),
_Utils_Tuple3(
author$project$WaveClock$Update$Saturation,
'saturation',
A2(
elm$core$Basics$composeR,
function ($) {
return $.modifiers;
},
function ($) {
return $.saturation;
})),
_Utils_Tuple3(
author$project$WaveClock$Update$Lightness,
'lightness',
A2(
elm$core$Basics$composeR,
function ($) {
return $.modifiers;
},
function ($) {
return $.lightness;
}))
]),
name: 'Wave Clock Redux',
Expand Down
3 changes: 3 additions & 0 deletions src/Model.elm
Expand Up @@ -139,6 +139,9 @@ init flags =
, ( Radius, "rad", .modifiers >> .radius >> (\n -> n / 2) )
, ( Step, "step", .modifiers >> .step >> (\n -> n / 2) )
, ( Delay, "delay", .modifiers >> .delay )
, ( Hue, "hue", .modifiers >> .hue )
, ( Saturation, "saturation", .modifiers >> .saturation )
, ( Lightness, "lightness", .modifiers >> .lightness )
]
, model = WaveClock.Model.init flags
, tick = WaveClock.Update.tick
Expand Down
10 changes: 6 additions & 4 deletions src/WaveClock/Model.elm
Expand Up @@ -14,15 +14,16 @@ type alias Model =
, xNoise : Float
, yNoise : Float
, angle : Float
, colorChange : Float
, colorVal : Float
, lines : List Line
, modifiers :
{ radNoise : Float
, angNoise : Float
, radius : Float
, step : Float
, delay : Float
, hue : Float
, saturation : Float
, lightness : Float
}
, lastTick : Int
}
Expand Down Expand Up @@ -67,15 +68,16 @@ init flags =
, xNoise = xNoise
, yNoise = yNoise
, angle = -pi / 2
, colorVal = 254
, colorChange = -1
, lines = []
, modifiers =
{ angNoise = 1
, radNoise = 1
, radius = 1
, step = 1
, delay = 0
, hue = 0
, saturation = 0
, lightness = 0.5
}
, lastTick = flags.time
}
31 changes: 15 additions & 16 deletions src/WaveClock/Update.elm
@@ -1,6 +1,6 @@
module WaveClock.Update exposing (Modifier(..), modify, tick)

import Color exposing (rgba)
import Color exposing (hsla)
import Perlin exposing (noise)
import Time exposing (Posix)
import WaveClock.Model exposing (Model)
Expand All @@ -12,6 +12,9 @@ type Modifier
| Radius
| Step
| Delay
| Hue
| Saturation
| Lightness


tick : Posix -> Model -> Model
Expand All @@ -20,7 +23,7 @@ tick time model =
timeInt =
Time.posixToMillis time
in
if timeInt - (round <| model.modifiers.delay * 1000) < model.lastTick then
if model.modifiers.delay == 1 || timeInt - (round <| model.modifiers.delay * 1000) < model.lastTick then
model

else
Expand Down Expand Up @@ -70,33 +73,20 @@ tick time model =

oppRad =
rad + pi

colorVal =
model.colorVal + model.colorChange
in
{ model
| angle = angle
, angNoise = angNoise
, radNoise = radNoise
, xNoise = xNoise
, yNoise = yNoise
, colorVal = colorVal
, colorChange =
if colorVal > 254 then
-1

else if colorVal < 0 then
1

else
model.colorChange
, lines =
model.lines
++ [ { x1 = centerX + (radius * cos rad)
, y1 = centerY + (radius * sin rad)
, x2 = centerX + (radius * cos oppRad)
, y2 = centerY + (radius * sin oppRad)
, color = rgba (colorVal / 255) (colorVal / 255) (colorVal / 255) (60 / 255)
, color = hsla model.modifiers.hue model.modifiers.saturation model.modifiers.lightness (60 / 255)
}
]
, lastTick = timeInt
Expand Down Expand Up @@ -124,3 +114,12 @@ modify model mod val =

Delay ->
{ model | modifiers = { modifiers | delay = val } }

Hue ->
{ model | modifiers = { modifiers | hue = val } }

Saturation ->
{ model | modifiers = { modifiers | saturation = val } }

Lightness ->
{ model | modifiers = { modifiers | lightness = val } }

0 comments on commit abf2951

Please sign in to comment.