ListPlot@ReIm@NestList[(# + RandomChoice@{0, 1, Exp[I Pi/3]})/2 &, 0., 10^4]
ArrayPlot@CellularAutomaton[{Mod[#[[1]] + #[[3]], 2] &, {}, 1}, {{1}, 0}, 100]
这两个图从结果上看好像很像,但是至少目前我的水平没看出来两者之间的联系。
第一句话有点类似于随机游走(带限定条件),但是除了游走,每次还要距离折半。可以类似的产生一些有意思的图片,例如:
data = ReIm@
NestList[(# + RandomChoice@{0, 1, Exp[I Pi/4], Exp[I Pi/3]})/2 &, 0., 10000];
ListPlot[data, PlotStyle -> {Blue, PlotPoints[0.0001]}]
第二句话是元胞自动机,通俗的说就是有一个初始状态,有确定的局部规则,然后根据规则作同步更新。例如下面这个例子,根据相邻三个格子的状态,对中间格子进行状态更新。
CellularAutomaton[{f, {}, 1}, {a, b, c, d}, 2]
强行用CellularAutomaton画那个图,也不是不行,但是麻烦。首先参考下面这个语句。
CellularAutomaton[{f, {}, 1/2}, {a, b}, 2]
(*{{a, b}, {f[{b, a}, 1], f[{a, b}, 1]}, {f[{f[{a, b}, 1], f[{b, a}, 1]}, 2],
f[{f[{b, a}, 1], f[{a, b}, 1]}, 2]}}*)
然后就可以改成相应的代码了。
getRand := RandomChoice[{0.85, 0.06, 0.08, 0.01} -> {
{{0.83, 0.03}, {-0.03, 0.86}}.# + {0, 1.5} &,
{{0.2, -0.25}, {0.21, 0.23}}.# + {0, 1.5} &,
{{-0.15, 0.27}, {0.25, 0.26}}.# + {0, 0.45} &,
{{0, 0}, {0, 0.17}}.# &
}];
n = 0;
getPos[{x_, y_}, a_] := If[EvenQ@n,
rand = getRand; n++; First@rand[{y, x}],
n++; Last@rand[{x, y}]
]
ListPlot@CellularAutomaton[{getPos, {}, 1/2}, {0., 0.}, 10000]