fastmath.fields

Vector field functions.

Vector fields are functions R^2->R^2.

Names are taken from fractal flames world where such fields are call variations. Most implementations are taken from JWildfire software.

Creation

To create vector field call field multimethod with name of the field as keyword.

Some of the vector fields require additional configuration as a map of parameters as keywords and values. Call parametrization to create random one or to merge with provided.

Additionally you can provide amount parameter which is scaling factor for vector field (default: 1.0).

Derived fields

You can use several method to derive new vector field from the other one(s). Possible options are:

Scalar fields

You can derive scalar fields from given vector field(s):

  • jacobian - determinant of jacobian matrix
  • divergence - divergence of the field
  • cross - cross product of the fields (as a determinant of the 2x2 matrix of vectors)
  • dot - dot product
  • angle-between - angle between vectors from fields.

Combinations

The other option is to create vector field using some of the above possibilities. Combination is a tree of field operations with parametrizations. Functions:

*skip-random-fields*

dynamic

When random configuration for combine is used. Skip vector fields which are random.

angle-between

Angle between input vector and result of the vector field.

In case when two vector fields are given, cross product is taken from result of vector fields.

Resulting value is from range [-PI,PI].

Examples

Usage

(let [f (angle-between (field :swirl))] (f (v/vec2 1 1)))
;;=> 0.42920367320510344

Usage (two fields)

(let [f (angle-between (field :sinusoidal) (field :swirl))]
  (f (v/vec2 1 1)))
;;=> 0.42920367320510255

combine

(combine {:keys [type name amount config var step var1 var2]})(combine)

Create composite vector field function based on configuration

Call without argument to get random vector field.

Configuration is a tree structure where nodes are one of the following

  • {:type :variation :name NAME :amount AMOUNT :config CONFIG} where
    • NAME is variation name (keyword)
    • AMOUNT is scaling factor
    • CONFIG is variation parametrization
  • {:type :operation :name OPERATION :amount AMOUNT :var1 VAR1 :var2 VAR2} where
    • OPERATION is one of the operations (see below)
    • AMOUNT is scaling factor
    • VAR1 and VAR2 two variations to combine
  • {:type :operation :name :derivative :amount AMOUNT :var VAR :step STEP} where
    • AMOUNT is scaling factor
    • VAR variation, subject to calculate derivative
    • STEP dx and dy value

Possible OPERATIONs are:

  • :add - sum of two variations
  • :mult - multiplication
  • :comp - composition
  • :angles - vector field from angles

See random-configuration for example.

Examples

Create random combination

(let [f (combine)] (f (v/vec2 -0.5 0.5)))
;;=> [0.8455870816838638 -0.7449686841386719]

Create combination for given configuration

(let [conf {:type :operation,
            :name :comp,
            :var1 {:type :variation,
                   :name :blocky,
                   :amount 1.0,
                   :config {:x -1.4, :y 0.9, :mp 2.6}},
            :var2
            {:type :variation, :name :secant, :amount 1.0, :config {}},
            :amount 1.0}
      f (combine conf)]
  (f (v/vec2 -0.5 0.5)))
;;=> [0.18532823300678739 0.437177284257253]

composition

(composition f1 f2 amount)(composition f1 f2)

Compose two vector fields.

Examples

Usage

(let [field-1 (field :sinusoidal)
      field-2 (field :swirl)
      field-comp (composition field-1 field-2)]
  (field-comp (v/vec2 0.5 0.3)))
;;=> [-0.11582232201566794 0.5408299143217236]

cross

2d cross product (det of the 2x2 matrix) of the input vector and result of the vector field.

In case when two vector fields are given, cross product is taken from results of vector fields.

Examples

Usage

(let [f (cross (field :swirl))] (f (v/vec2 1 1)))
;;=> 0.8322936730942845

Usage (two fields)

(let [f (cross (field :sinusoidal) (field :swirl))] (f (v/vec2 1 1)))
;;=> -0.7003509767480289

curl

(curl f)(curl f h)

Curl (2d version) of the field.

See: https://youtu.be/rB83DpBJQsE?t=855

Examples

Usage

(let [f (curl (field :swirl) 1.0E-8)] (f (v/vec2 0.0 0.0)))
;;=> -2.0

derivative

(derivative f amount h)(derivative f h)(derivative f)

Calculate directional derivative of fn. Derivative is calculated along 1,1 vector with h as a step (default 1.0e-6).

Examples

Usage

(let [f (derivative (field :sinusoidal) 1.0E-8)] (f (v/vec2 0.0 0.0)))
;;=> [1.0 1.0]

divergence

(divergence f)(divergence f h)

Divergence of the field.

See: https://youtu.be/rB83DpBJQsE?t=855

Examples

Usage

(let [f (divergence (field :sinusoidal) 1.0E-8)] (f (v/vec2 0.0 0.0)))
;;=> 2.0

dot

Dot product of the input vector and result of the vector field.

In case when two vector fields are given, cross product is taken from result of vector fields.

Examples

Usage

(let [f (dot (field :swirl))] (f (v/vec2 1 1)))
;;=> 1.8185948536513636

Usage (two fields)

(let [f (dot (field :sinusoidal) (field :swirl))] (f (v/vec2 1 1)))
;;=> 1.5302948024685854

field

multimethod

Return vector field for given name and options: amount (scaling factor) and parametrization.

Default scaling factor is 1.0, default parametrization is random.

Resulting function operates on Vec2 type.

Examples

Get vector field by name

(field :sinusoidal)
;;=> fastmath.fields.s$sinusoidal$fn__33343@5bd1867b
((field :sinusoidal) (v/vec2 m/HALF_PI m/HALF_PI))
;;=> [1.0 1.0]

Get vector field by name and scale

(field :sinusoidal 0.5)
;;=> fastmath.fields.s$sinusoidal$fn__33343@3b44b63a
((field :sinusoidal 0.5) (v/vec2 m/HALF_PI m/HALF_PI))
;;=> [0.5 0.5]

Apply parametrization

(let [params (parametrization :cpow3)
      f (field :cpow3 1.0 params)]
  {:parametrization params, :value (f (v/vec2 -1.0 1.0))})
;;=> {:parametrization {:d 16.94539494189486,
;;=>                    :divisor -0.5399828282844649,
;;=>                    :r 0.9006226694653078,
;;=>                    :spread 2.3617427122795807},
;;=>  :value [3.8819224693104786E-4 0.0023073556073289615]}

fields-list

Examples

List of all vector field names.

(sort fields-list)
;;=> (:acosech
;;=>  :acosh
;;=>  :acoth :anamorphcyl
;;=>  :apocarpet :apollony
;;=>  :arch :arcsech2
;;=>  :arcsinh :arctanh
;;=>  :arctruchet :asinh
;;=>  :asteria :atan
;;=>  :atan2spirals :atanh
;;=>  :auger :barycentroid
;;=>  :bcollide :bent
;;=>  :bent2 :besselj
;;=>  :beta :bilinear
;;=>  :bipolar :bipolar2
;;=>  :blade :blade2
;;=>  :blob :blocky
;;=>  :blur :blurcircle
;;=>  :blurlinear :blurpixelize
;;=>  :blurzoom :bmod
;;=>  :boarders :boarders2
;;=>  :brownian :bsplit
;;=>  :bswirl :btransform
;;=>  :bubble :bulge
;;=>  :butterfly :butterflyfay
;;=>  :bwrands :bwraps7
;;=>  :cannabiswf :cardioid
;;=>  :cayley :cell
;;=>  :checks :chrysantemum
;;=>  :chunk :circle-inverse
;;=>  :circleblur :circlecrop
;;=>  :circlelinear :circlerand
;;=>  :circlesplit :circletrans1
;;=>  :circlize :circlize2
;;=>  :circular :circular2
;;=>  :circus :clifford
;;=>  :cloverleafwf :collideoscope
;;=>  :conic :corners
;;=>  :cos :cos2bs
;;=>  :cosh :cosh2bs
;;=>  :cosine :cot
;;=>  :cot2bs :coth
;;=>  :coth2bs :cpow
;;=>  :cpow2 :cpow3
;;=>  :cpow3wf :crackle
;;=>  :crob :cross
;;=>  :csc :csc2bs
;;=>  :csch :csch2bs
;;=>  :cscsquared :csin
;;=>  :curl :curve
;;=>  :cylinder :cylinder2
;;=>  :deltaa :devilwarp
;;=>  :diamond :disc
;;=>  :disc2 :disc3
;;=>  :dlawf :dspherical
;;=>  :dustpoint :eclipse
;;=>  :ecollide :edisc
;;=>  :ejulia :elliptic
;;=>  :elliptic2 :ellipticapo
;;=>  :ellipticprecision :emod
;;=>  :emotion :ennepers
;;=>  :epispiral :epispiralwf
;;=>  :epush :erf
;;=>  :erf2 :erotate
;;=>  :escale :escher
;;=>  :eswirl :ex
;;=>  :exp :exp2bs
;;=>  :expmulti :exponential
;;=>  :eyefish :fan
;;=>  :fan2 :fdisc
;;=>  :fibonacci2 :fisheye
;;=>  :flipcircle :flipy
;;=>  :flower :flux
;;=>  :foci :foucaut
;;=>  :fourth :funnel
;;=>  :gamma :gaussianblur
;;=>  :gdoffs :general-noise
;;=>  :general-noise2 :glitchy2
;;=>  :glynnia :glynnia3
;;=>  :glynnlissa :glynnsim1
;;=>  :glynnsim2 :glynnsim3
;;=>  :glynnsupershape :gridout
;;=>  :gridout2 :hadamard
;;=>  :hamid :handkerchief
;;=>  :heart :heartwf
;;=>  :hemisphere :hexes
;;=>  :hexmodulus :hole
;;=>  :hole2 :holesq
;;=>  :horseshoe :hyperbolic
;;=>  :hyperbolicellipse :hypershift
;;=>  :hypershift2 :hypertile
;;=>  :hypertile1 :hypertile2
;;=>  :idisc :intersection
;;=>  :inverted-julia :invpolar
;;=>  :invsquircular :invtree
;;=>  :jacasn :jaccn
;;=>  :jacdn :jacelk
;;=>  :jacsn :joukowski
;;=>  :julia :julia2
;;=>  :juliac :julian
;;=>  :julian2 :juliaoutside
;;=>  :juliaq :juliascope
;;=>  :kaleidoscope :kleingroup
;;=>  :lace :layeredspiral
;;=>  :lazyjess :lazysusan
;;=>  :lazytravis :lineart
;;=>  :lissajous :log
;;=>  :logapo :logdb
;;=>  :loonie :loonie2
;;=>  :loonie3 :lozi
;;=>  :mask :mcarpet
;;=>  :miller :millerrev
;;=>  :minkowskope :minkqm
;;=>  :mobius :mobiusn
;;=>  :modulus :murl
;;=>  :murl2 :ngon
;;=>  :noise :npolar
;;=>  :octapol :ortho
;;=>  :oscilloscope :oscilloscope2
;;=>  :ovoid :panorama1
;;=>  :panorama2 :parabola
;;=>  :parallel :pdj
;;=>  :perlin :perlin2
;;=>  :perspective :petal
;;=>  :phoenix-julia :pie
;;=>  :pixelflow :plusrecip
;;=>  :plusrecip2 :polar
;;=>  :polar2 :polylogarithm
;;=>  :popcorn :popcorn2
;;=>  :powblock :power
;;=>  :pressure-wave :projective
;;=>  :ptransform :pulse
;;=>  :q-ode :r-circleblur
;;=>  :radialblur :rational3
;;=>  :rays :rays1
;;=>  :rays2 :rays3
;;=>  :rectangles :rhodonea
;;=>  :rings :rings2
;;=>  :ripple :rippled
;;=>  :rosewf :rosoni
;;=>  :roundspher :sattractor
;;=>  :scrambly :scry
;;=>  :scry2 :sec
;;=>  :sec2bs :secant
;;=>  :secant2 :sech
;;=>  :sech2bs :separation
;;=>  :shift :shredlin
;;=>  :shredrad :sigmoid
;;=>  :sin :sin2bs
;;=>  :sineblur :sinh
;;=>  :sinh2bs :sintrange
;;=>  :sinusgrid :sinusoidal
;;=>  :spherical :sphericaln
;;=>  :spiral :spiralwing
;;=>  :spligon :splipticbs
;;=>  :split :splitbrdr
;;=>  :splits :sqrt-acosech
;;=>  :sqrt-acosh :sqrt-acoth
;;=>  :sqrt-asech :sqrt-asinh
;;=>  :sqrt-atanh :square
;;=>  :squarize :squircular
;;=>  :squirrel :squish
;;=>  :starblur :stripes
;;=>  :stripfit :stwin
;;=>  :stwin-jw :supershape
;;=>  :svensson :swirl
;;=>  :swirl3 :symband
;;=>  :symnet :tan
;;=>  :tan2bs :tancos
;;=>  :tangent :tanh
;;=>  :tanh2bs :target
;;=>  :targetsp :taurus
;;=>  :threepointifs :tile-log
;;=>  :tile-reverse :tilehlp
;;=>  :tqmirror :trade
;;=>  :triantruchet :truchet2
;;=>  :truchetfill :truchetflow
;;=>  :truchethexcrop :truchethexfill
;;=>  :twintrian :twoface
;;=>  :unpolar :vibration
;;=>  :vibration2 :vogel
;;=>  :voron :w
;;=>  :wallpaper :waves
;;=>  :waves2 :waves22
;;=>  :waves23 :waves2b
;;=>  :waves2radial :waves2wf
;;=>  :waves3 :waves3wf
;;=>  :waves4 :waves42
;;=>  :waves4wf :wdisk
;;=>  :wedge :wedgejulia
;;=>  :wedgesph :whorl
;;=>  :woggle :x
;;=>  :xheart :xtrb
;;=>  :y :yinyang
;;=>  :z :zsymmetry)

fields-list-not-random

Examples

List of all vector fields which are not random.

(sort fields-list-not-random)
;;=> (:acoth
;;=>  :anamorphcyl :arcsech2
;;=>  :arcsinh :arctanh
;;=>  :asinh :atan
;;=>  :atan2spirals :atanh
;;=>  :auger :barycentroid
;;=>  :bcollide :bent
;;=>  :bent2 :besselj
;;=>  :beta :bilinear
;;=>  :bipolar :bipolar2
;;=>  :blob :blocky
;;=>  :bmod :bsplit
;;=>  :bswirl :bubble
;;=>  :bulge :butterfly
;;=>  :bwraps7 :cardioid
;;=>  :cayley :cell
;;=>  :chunk :circle-inverse
;;=>  :circlelinear :circlesplit
;;=>  :circlize :circlize2
;;=>  :circus :clifford
;;=>  :collideoscope :corners
;;=>  :cos :cos2bs
;;=>  :cosh :cosh2bs
;;=>  :cosine :cot
;;=>  :cot2bs :coth
;;=>  :coth2bs :cross
;;=>  :csc :csc2bs
;;=>  :csch :csch2bs
;;=>  :cscsquared :csin
;;=>  :curl :curve
;;=>  :cylinder :cylinder2
;;=>  :deltaa :devilwarp
;;=>  :diamond :disc
;;=>  :disc2 :disc3
;;=>  :eclipse :ecollide
;;=>  :edisc :ellipticapo
;;=>  :ellipticprecision :emod
;;=>  :emotion :ennepers
;;=>  :epispiralwf :epush
;;=>  :erf :erf2
;;=>  :erotate :escale
;;=>  :escher :eswirl
;;=>  :ex :exp
;;=>  :exp2bs :exponential
;;=>  :eyefish :fan
;;=>  :fan2 :fdisc
;;=>  :fibonacci2 :fisheye
;;=>  :flipcircle :flipy
;;=>  :flux :foci
;;=>  :foucaut :fourth
;;=>  :funnel :gamma
;;=>  :gdoffs :general-noise
;;=>  :general-noise2 :glitchy2
;;=>  :gridout :gridout2
;;=>  :handkerchief :heart
;;=>  :heartwf :hemisphere
;;=>  :hexes :hexmodulus
;;=>  :hole :hole2
;;=>  :holesq :horseshoe
;;=>  :hyperbolic :hyperbolicellipse
;;=>  :hypershift :idisc
;;=>  :invpolar :invsquircular
;;=>  :jacasn :jaccn
;;=>  :jacdn :jacelk
;;=>  :jacsn :joukowski
;;=>  :kaleidoscope :layeredspiral
;;=>  :lazyjess :lazysusan
;;=>  :lazytravis :lineart
;;=>  :log :logapo
;;=>  :loonie :loonie2
;;=>  :loonie3 :lozi
;;=>  :mask :mcarpet
;;=>  :miller :millerrev
;;=>  :minkowskope :minkqm
;;=>  :mobius :modulus
;;=>  :murl :murl2
;;=>  :ngon :octapol
;;=>  :ortho :oscilloscope
;;=>  :oscilloscope2 :ovoid
;;=>  :panorama1 :panorama2
;;=>  :pdj :perlin
;;=>  :perlin2 :perspective
;;=>  :petal :plusrecip
;;=>  :plusrecip2 :polar
;;=>  :polar2 :polylogarithm
;;=>  :popcorn :popcorn2
;;=>  :power :pressure-wave
;;=>  :projective :ptransform
;;=>  :pulse :q-ode
;;=>  :rational3 :rays1
;;=>  :rays2 :rays3
;;=>  :rectangles :rings
;;=>  :rings2 :ripple
;;=>  :rippled :rosoni
;;=>  :roundspher :scrambly
;;=>  :scry :scry2
;;=>  :sec :sec2bs
;;=>  :secant :secant2
;;=>  :sech :sech2bs
;;=>  :separation :shift
;;=>  :shredlin :shredrad
;;=>  :sigmoid :sin
;;=>  :sin2bs :sinh
;;=>  :sinh2bs :sintrange
;;=>  :sinusgrid :sinusoidal
;;=>  :spherical :spiral
;;=>  :spiralwing :spligon
;;=>  :split :splits
;;=>  :squarize :squircular
;;=>  :squirrel :stripes
;;=>  :stripfit :stwin
;;=>  :stwin-jw :svensson
;;=>  :swirl :swirl3
;;=>  :tan :tan2bs
;;=>  :tancos :tangent
;;=>  :tanh :tanh2bs
;;=>  :target :targetsp
;;=>  :taurus :tqmirror
;;=>  :trade :truchet2
;;=>  :truchetfill :twoface
;;=>  :unpolar :vibration
;;=>  :vibration2 :voron
;;=>  :w :waves
;;=>  :waves2 :waves22
;;=>  :waves23 :waves2b
;;=>  :waves2radial :waves2wf
;;=>  :waves3 :waves3wf
;;=>  :waves4 :waves42
;;=>  :waves4wf :wdisk
;;=>  :wedge :wedgesph
;;=>  :whorl :x
;;=>  :xheart :y
;;=>  :z :zsymmetry)

fields-list-random

Examples

List of all vector fields which give random results.

(sort fields-list-random)
;;=> (:acosech
;;=>  :acosh :apocarpet
;;=>  :apollony :arch
;;=>  :arctruchet :asteria
;;=>  :blade :blade2
;;=>  :blur :blurcircle
;;=>  :blurlinear :blurpixelize
;;=>  :blurzoom :boarders
;;=>  :boarders2 :brownian
;;=>  :btransform :butterflyfay
;;=>  :bwrands :cannabiswf
;;=>  :checks :chrysantemum
;;=>  :circleblur :circlecrop
;;=>  :circlerand :circletrans1
;;=>  :circular :circular2
;;=>  :cloverleafwf :conic
;;=>  :cpow :cpow2
;;=>  :cpow3 :cpow3wf
;;=>  :crackle :crob
;;=>  :dlawf :dspherical
;;=>  :dustpoint :ejulia
;;=>  :elliptic :elliptic2
;;=>  :epispiral :expmulti
;;=>  :flower :gaussianblur
;;=>  :glynnia :glynnia3
;;=>  :glynnlissa :glynnsim1
;;=>  :glynnsim2 :glynnsim3
;;=>  :glynnsupershape :hadamard
;;=>  :hamid :hypershift2
;;=>  :hypertile :hypertile1
;;=>  :hypertile2 :intersection
;;=>  :inverted-julia :invtree
;;=>  :julia :julia2
;;=>  :juliac :julian
;;=>  :julian2 :juliaoutside
;;=>  :juliaq :juliascope
;;=>  :kleingroup :lace
;;=>  :lissajous :logdb
;;=>  :mobiusn :noise
;;=>  :npolar :parabola
;;=>  :parallel :phoenix-julia
;;=>  :pie :pixelflow
;;=>  :powblock :r-circleblur
;;=>  :radialblur :rays
;;=>  :rhodonea :rosewf
;;=>  :sattractor :sineblur
;;=>  :sphericaln :splipticbs
;;=>  :splitbrdr :sqrt-acosech
;;=>  :sqrt-acosh :sqrt-acoth
;;=>  :sqrt-asech :sqrt-asinh
;;=>  :sqrt-atanh :square
;;=>  :squish :starblur
;;=>  :supershape :symband
;;=>  :symnet :threepointifs
;;=>  :tile-log :tile-reverse
;;=>  :tilehlp :triantruchet
;;=>  :truchetflow :truchethexcrop
;;=>  :truchethexfill :twintrian
;;=>  :vogel :wallpaper
;;=>  :wedgejulia :woggle
;;=>  :xtrb :yinyang)

fields-map

grad-x

(grad-x f amount h)(grad-x f h)(grad-x f)

Calculate gradient along x axis.

Examples

Usage

(let [f (grad-x (field :sinusoidal) 1.0E-8)] (f (v/vec2 0.0 0.0)))
;;=> [1.0 0.0]

grad-y

(grad-y f amount h)(grad-y f h)(grad-y f)

Calculate gradient along y axis.

Examples

Usage

(let [f (grad-y (field :sinusoidal) 1.0E-8)] (f (v/vec2 0.0 0.0)))
;;=> [0.0 1.0]

heading

(heading f)

Angle of the vectors from field.

Examples

Usage

(let [f (heading (field :sinusoidal))]
  (m/degrees (f (v/vec2 m/HALF_PI m/HALF_PI))))
;;=> 45.0

jacobian

(jacobian f)(jacobian f h)

Det of Jacobian of the field

Examples

Usage

(let [f (jacobian (field :sinusoidal) 1.0E-8)] (f (v/vec2 0.0 0.0)))
;;=> 1.0

magnitude

(magnitude f)

Magnitude of the vectors from field.

Examples

Usage

(let [f (magnitude (field :sinusoidal))]
  (f (v/vec2 m/HALF_PI m/HALF_PI)))
;;=> 1.4142135623730951

multiplication

(multiplication f1 f2 amount)(multiplication f1 f2)

Multiply two vector fields (as a element-wise multiplication of results).

Examples

Usage

(let [field-1 (field :sinusoidal)
      field-2 (field :swirl)
      field-multiplication (multiplication field-1 field-2)]
  (field-multiplication (v/vec2 0.5 0.3)))
;;=> [-0.05565308460418609 0.1688671791104423]

parametrization

multimethod

Return random parametrization map for given field.

Optinally you can pass part of the parametrization. In this case function will add remaining keys with randomly generated values.

If field doesn’t have parametrization, empty map will be returned.

See field.

Examples

Get random parametrization for given field

(parametrization :auger)
;;=> {:freq 3.16505011583482,
;;=>  :scale 1.5170466745707274,
;;=>  :sym -1.716787322506934,
;;=>  :weight -0.8629533521137822}

Add lacking fields

(parametrization :auger {:scale 1.0, :freq 1.0})
;;=> {:freq 1.0,
;;=>  :scale 1.0,
;;=>  :sym -1.38858073027647,
;;=>  :weight 0.9814630787716512}

Returns empty map when field doesn’t have parametrization

(parametrization :sinusoidal)
;;=> {}

random-configuration

(random-configuration)(random-configuration depth)(random-configuration depth f)

Create random configuration for combine function. Optionally with depth (0 = only root is created).

See combine for structure.

Bind *skip-random-fields* to true to exclude fields which are random.

Examples

Generate random configuration

(random-configuration)
;;=> {:amount 1.0,
;;=>  :config
;;=>  {:circle 0.7057027970247225, :sides -2, :star 0.9921284812049164},
;;=>  :name :scry2,
;;=>  :type :variation}

One node configuration

(random-configuration 0)
;;=> {:amount 1.0, :config {}, :name :erf, :type :variation}

Configuration with depth 2

(random-configuration 2)
;;=> {:amount 1.0,
;;=>  :name :comp,
;;=>  :type :operation,
;;=>  :var1 {:amount 1.0,
;;=>         :name :mult,
;;=>         :type :operation,
;;=>         :var1 {:amount 1.3082732524571026,
;;=>                :config {:dist -0.9484102913388704,
;;=>                         :power -9.757219205512945},
;;=>                :name :juliascope,
;;=>                :type :variation},
;;=>         :var2 {:amount -0.3072739321010314,
;;=>                :config {},
;;=>                :name :squarize,
;;=>                :type :variation}},
;;=>  :var2 {:amount 1.0,
;;=>         :config {:cos-div -0.6717814677851464,
;;=>                  :csc-add 0.25662687920677774,
;;=>                  :csc-div 1.1887038533239715,
;;=>                  :csc-pow -1.950675557561302,
;;=>                  :pi-mult 0.8620640630007579,
;;=>                  :scale-y -0.7365648797310094,
;;=>                  :tan-div -1.576222466628806},
;;=>         :name :cscsquared,
;;=>         :type :variation}}

random-field

(random-field)(random-field depth)

Create randomized field (optional depth can be provided).

randomize-configuration

(randomize-configuration f)

Randomize values for given configuration. Keeps structure untouched.

Examples

Usage

(let [conf {:type :variation,
            :name :blocky,
            :amount 1.0,
            :config {:x -1.4, :y 0.9, :mp 2.6}}]
  [(randomize-configuration conf) (randomize-configuration conf)])
;;=> [{:amount 1.0,
;;=>   :config {:mp 0.2612802951814419,
;;=>            :x -1.4325664625964587,
;;=>            :y 1.3338931808349739},
;;=>   :name :blocky,
;;=>   :type :variation}
;;=>  {:amount 1.0,
;;=>   :config {:mp -5.640478064062036,
;;=>            :x -1.0729886948296983,
;;=>            :y 0.7951644041228678},
;;=>   :name :blocky,
;;=>   :type :variation}]

scalar->vector-field

(scalar->vector-field scalar f)(scalar->vector-field scalar f1 f2)

Returns vector field build from scalar fields of the input vector and result of the vector field.

Examples

Usage

(let [f (scalar->vector-field v/heading (field :sinusoidal))]
  (v/applyf (f (v/vec2 m/HALF_PI m/HALF_PI)) m/degrees))
;;=> [45.0 45.0]

Usage (two fields)

(let [f (scalar->vector-field v/heading
                              (field :sinusoidal)
                              (field :julia))]
  (v/applyf (f (v/vec2 m/HALF_PI m/HALF_PI)) m/degrees))
;;=> [45.0 -157.50000000000003]

sum

(sum f1 f2 amount)(sum f1 f2)

Add two vector fields.

Examples

Usage

(let [field-1 (field :sinusoidal)
      field-2 (field :swirl)
      field-sum (sum field-1 field-2)]
  (field-sum (v/vec2 0.5 0.3)))
;;=> [0.3633426850161062 0.866943667067757]