From 4beb56b2dbcf5fe5ddb054440a295d48a7eaeedf Mon Sep 17 00:00:00 2001 From: Noah Gordon Date: Tue, 25 Jun 2019 20:52:52 +0200 Subject: [PATCH] Pentagon modifiers --- elm.js | 57 +++++++++++++++++++++++++++++++++------- src/Model.elm | 7 +++-- src/Sutcliffe/Model.elm | 6 +++++ src/Sutcliffe/Update.elm | 30 ++++++++++++++------- 4 files changed, 79 insertions(+), 21 deletions(-) diff --git a/elm.js b/elm.js index 4e1d5ed..fc2567a 100644 --- a/elm.js +++ b/elm.js @@ -8160,18 +8160,37 @@ var author$project$Sutcliffe$Model$init = function (flags) { groups: author$project$Sutcliffe$Model$spawnGroups(initialStruts), pentNum: 0 }, + offsetMod: 0.5, pentCount: 0, phase: author$project$Sutcliffe$Model$Struts, rotation: 0, scale: 1, strutLength: 10, + strutMod: 0.5, time: elm$time$Time$millisToPosix(flags.time), - window: flags.window + window: flags.window, + zoomSpeed: 0.5 }; }; +var author$project$Sutcliffe$Update$OffsetMod = {$: 'OffsetMod'}; +var author$project$Sutcliffe$Update$StrutMod = {$: 'StrutMod'}; +var author$project$Sutcliffe$Update$ZoomSpeed = {$: 'ZoomSpeed'}; var author$project$Sutcliffe$Update$modify = F3( function (model, mod, val) { - return model; + switch (mod.$) { + case 'StrutMod': + return _Utils_update( + model, + {strutMod: val}); + case 'OffsetMod': + return _Utils_update( + model, + {offsetMod: val}); + default: + return _Utils_update( + model, + {zoomSpeed: val}); + } }); var author$project$Sutcliffe$Model$Sides = {$: 'Sides'}; var author$project$Sutcliffe$Update$grow = function (growable) { @@ -8261,8 +8280,8 @@ var ianmackenzie$elm_geometry$Point2d$translateIn = F3( return ianmackenzie$elm_geometry$Point2d$fromCoordinates( _Utils_Tuple2(px + (distance * dx), py + (distance * dy))); }); -var author$project$Sutcliffe$Update$newGroups = F3( - function (seed, length, groups) { +var author$project$Sutcliffe$Update$newGroups = F4( + function (seed, length, offsetMod, groups) { var _n0 = A2( elm$random$Random$step, A2( @@ -8279,7 +8298,7 @@ var author$project$Sutcliffe$Update$newGroups = F3( var group = _n1.b; var side = author$project$Sutcliffe$Model$lineSegment(group.sides.a); var startPoint = ianmackenzie$elm_geometry$LineSegment2d$endPoint(side); - var offset = ((prob - 0.5) / 3) * length; + var offset = ((((prob - 0.5) / 3) * length) * 2) * offsetMod; var direction = A2( elm$core$Maybe$withDefault, ianmackenzie$elm_geometry$Direction2d$x, @@ -8305,7 +8324,7 @@ var author$project$Sutcliffe$Update$tick = F2( function (time, model) { var newModel = _Utils_update( model, - {rotation: model.rotation + 0.11, scale: model.scale * 0.9995}); + {rotation: model.rotation + 0.11, scale: model.scale / ((model.zoomSpeed / 1000) + 1)}); var growing = model.growing; var growingSides = A2( elm$core$List$map, @@ -8328,7 +8347,7 @@ var author$project$Sutcliffe$Update$tick = F2( }, growingStruts) ? _Utils_update( newModel, - {phase: author$project$Sutcliffe$Model$Sides, strutLength: model.strutLength * 1.5}) : _Utils_update( + {phase: author$project$Sutcliffe$Model$Sides, strutLength: (model.strutLength * 3) * model.strutMod}) : _Utils_update( newModel, { growing: _Utils_update( @@ -8366,7 +8385,7 @@ var author$project$Sutcliffe$Update$tick = F2( model.finished), growing: { color: newColor, - groups: A3(author$project$Sutcliffe$Update$newGroups, seed1, model.strutLength, growing.groups), + groups: A4(author$project$Sutcliffe$Update$newGroups, seed1, model.strutLength, model.offsetMod, growing.groups), pentNum: model.pentCount + 1 }, pentCount: model.pentCount + 1, @@ -8830,7 +8849,27 @@ var author$project$Model$init = function (flags) { id: 'sutcliffe', modConstructor: author$project$Messages$SutcliffeMod, model: author$project$Sutcliffe$Model$init(flags), - mods: _List_Nil, + mods: _List_fromArray( + [ + _Utils_Tuple3( + author$project$Sutcliffe$Update$StrutMod, + 'strutgrowth', + function ($) { + return $.strutMod; + }), + _Utils_Tuple3( + author$project$Sutcliffe$Update$OffsetMod, + 'offset', + function ($) { + return $.offsetMod; + }), + _Utils_Tuple3( + author$project$Sutcliffe$Update$ZoomSpeed, + 'zoom speed', + function ($) { + return $.zoomSpeed; + }) + ]), name: 'Sutcliffe Pentagons', tick: author$project$Sutcliffe$Update$tick })) diff --git a/src/Model.elm b/src/Model.elm index 384cbae..c54e4fa 100644 --- a/src/Model.elm +++ b/src/Model.elm @@ -18,7 +18,7 @@ import NoiseOverTime.EffectView import NoiseOverTime.Model import Sutcliffe.EffectView import Sutcliffe.Model -import Sutcliffe.Update exposing (Modifier) +import Sutcliffe.Update exposing (Modifier(..)) import Time exposing (Posix) import WaveClock.EffectView import WaveClock.Model @@ -151,7 +151,10 @@ init flags = , id = "sutcliffe" , draw = Sutcliffe.EffectView.draw , mods = - [] + [ ( StrutMod, "strutgrowth", .strutMod ) + , ( OffsetMod, "offset", .offsetMod ) + , ( ZoomSpeed, "zoom speed", .zoomSpeed ) + ] , model = Sutcliffe.Model.init flags , tick = Sutcliffe.Update.tick , modConstructor = SutcliffeMod diff --git a/src/Sutcliffe/Model.elm b/src/Sutcliffe/Model.elm index bade4e1..598b73d 100644 --- a/src/Sutcliffe/Model.elm +++ b/src/Sutcliffe/Model.elm @@ -25,6 +25,9 @@ type alias Model = , scale : Float , rotation : Float , pentCount : Int + , strutMod : Float + , offsetMod : Float + , zoomSpeed : Float } @@ -103,6 +106,9 @@ init flags = , scale = 1 , rotation = 0 , pentCount = 0 + , strutMod = 0.5 + , offsetMod = 0.5 + , zoomSpeed = 0.5 } diff --git a/src/Sutcliffe/Update.elm b/src/Sutcliffe/Update.elm index 403a931..b55291b 100644 --- a/src/Sutcliffe/Update.elm +++ b/src/Sutcliffe/Update.elm @@ -1,4 +1,4 @@ -module Sutcliffe.Update exposing (Modifier, modify, tick) +module Sutcliffe.Update exposing (Modifier(..), modify, tick) import Color exposing (hsl) import Direction2d as Direction @@ -11,8 +11,10 @@ import Sutcliffe.Model as Model exposing (Line, Model, Phase(..), StrutGroup) import Time exposing (Posix) -type alias Modifier = - () +type Modifier + = StrutMod + | OffsetMod + | ZoomSpeed tick : Posix -> Model -> Model @@ -20,7 +22,7 @@ tick time model = let newModel = { model - | scale = model.scale * 0.9995 + | scale = model.scale / (model.zoomSpeed / 1000 + 1) , rotation = model.rotation + 0.11 } @@ -38,7 +40,7 @@ tick time model = if List.all (\line -> line.growth >= 1) growingStruts then { newModel | phase = Sides - , strutLength = model.strutLength * 1.5 + , strutLength = model.strutLength * 3 * model.strutMod } else @@ -66,7 +68,7 @@ tick time model = [ growing ] ++ model.finished , growing = - { groups = newGroups seed1 model.strutLength growing.groups + { groups = newGroups seed1 model.strutLength model.offsetMod growing.groups , color = newColor , pentNum = model.pentCount + 1 } @@ -82,7 +84,15 @@ tick time model = modify : Model -> Modifier -> Float -> Model modify model mod val = - model + case mod of + StrutMod -> + { model | strutMod = val } + + OffsetMod -> + { model | offsetMod = val } + + ZoomSpeed -> + { model | zoomSpeed = val } growStruts : StrutGroup -> StrutGroup @@ -114,8 +124,8 @@ grow growable = growable -newGroups : Random.Seed -> Float -> List StrutGroup -> List StrutGroup -newGroups seed length groups = +newGroups : Random.Seed -> Float -> Float -> List StrutGroup -> List StrutGroup +newGroups seed length offsetMod groups = let ( probs, _ ) = Random.step (Random.list 5 <| Random.float 0 1) seed @@ -125,7 +135,7 @@ newGroups seed length groups = (\( prob, group ) -> let offset = - (prob - 0.5) / 3 * length + (prob - 0.5) / 3 * length * 2 * offsetMod side = Model.lineSegment (Tuple.first group.sides)