Skip to content

Commit

Permalink
Pentagon modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
noahzgordon committed Jun 25, 2019
1 parent 6a3732e commit 4beb56b
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 21 deletions.
57 changes: 48 additions & 9 deletions elm.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}))
Expand Down
7 changes: 5 additions & 2 deletions src/Model.elm
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/Sutcliffe/Model.elm
Expand Up @@ -25,6 +25,9 @@ type alias Model =
, scale : Float
, rotation : Float
, pentCount : Int
, strutMod : Float
, offsetMod : Float
, zoomSpeed : Float
}


Expand Down Expand Up @@ -103,6 +106,9 @@ init flags =
, scale = 1
, rotation = 0
, pentCount = 0
, strutMod = 0.5
, offsetMod = 0.5
, zoomSpeed = 0.5
}


Expand Down
30 changes: 20 additions & 10 deletions 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
Expand All @@ -11,16 +11,18 @@ 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
tick time model =
let
newModel =
{ model
| scale = model.scale * 0.9995
| scale = model.scale / (model.zoomSpeed / 1000 + 1)
, rotation = model.rotation + 0.11
}

Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 4beb56b

Please sign in to comment.