3 ms·
Yes, it's a pretty simple example. Something fun along the same lines, plotting pink noise (random walk is Brownian, or brown noise) in two lines of BQN: https:
by mlochbaum 4y ago
Yes, it's a pretty simple example. Something fun along the same lines, plotting pink noise (random walk is Brownian, or brown noise) in two lines of BQN: https://mlochbaum.github.io/BQN/try.html#code=UmFuZCDihpAgLeKfnMKsIOKAonJhbmQuUmFuZ2Xin5wwCuKAolBsb3QgeytgIPCdlakg4oaRIOKliuKImOKNieKImOKJjcK04oy9IC3in5zCq+KImFJhbmTCqCAoMeKMiOKGleKImOKMiCnijL4oMuKLhuKBvOKKoiky4oyI8J2VqX0gNTAw https://mlochbaum.github.io/BQN/try.html#code=UmFuZCDihpAgLe...
Rand ← -⟜¬ •rand.Range⟜0
•Plot {+` 𝕩 ↑ ⥊∘⍉∘≍´⌽ -⟜«∘Rand¨ (1⌈↕∘⌈)⌾(2⋆⁼⊢)2⌈𝕩} 500
A slightly spread out translation of the function to J below. The idea is to take lengths 2 2 4 8 16... up to the required length, and then repeatedly interleave the two smallest ones to get a fractal pattern. The interleaved values are differences of white noise, and a final sum undoes these differences to leave a sum of white noise at several different frequencies.
pink =: {{
len =. (1>.i.@>.)&.:(2&^.) 2>.y
diffs =. (2-~/\0,[:(--.)?@$&0)&.> len
+/\ y {. >,@,.&.>/|. diffs
}}
Adapted from [0], which I was able to simplify some when I ported it from an earlier J version [1]. I think having the whole algorithm there at once was definitely helpful in figuring out what I meant to do and writing it more cleanly.
[0] https://github.com/mlochbaum/BQNoise/blob/master/tracker.bqn#L56-L58 https://github.com/mlochbaum/BQNoise/blob/master/tracker.bqn...
[1] https://github.com/mlochbaum/JSound/blob/master/makedrums.ijs#L32-L33 https://github.com/mlochbaum/JSound/blob/master/makedrums.ij...
- jonahx 4y agoAlso worth pointing the example from the problem can be written more succintly: plot+/\_1+2*?100#2
- raydiatian 4y agoI now remember what code looks like to somebody who has never coded. What an awful looking language. Laughing my ass off.
- razetime 4y agoSeeing this snide and shallow comment, I think you could benefit from expanding your mind by learning J: http://www.jsoftware.com/help/learning/contents.htm http://www.jsoftware.com/help/learning/contents.htm
- raydiatian 4y agoPass