下雪的动画模拟

ARM 277浏览

下雪了

代码:

Clear["`*"]
flake := Module[{arm},
   arm = Accumulate[{{0, 0.1}}~Join~RandomReal[{-1, 1}, {5, 2}]];
   arm = arm.Transpose@RotationMatrix[{arm[[-1]], {0, 1}}];
   arm = arm~Join~Rest@Reverse[arm.{{-1, 0}, {0, 1}}];
   Polygon[Flatten[arm.RotationMatrix[# [Pi]/3] & /@ Range[6], 1]]];

snowfield[flakesize_, size_, num_] :=
  Module[{x = 100/flakesize},
   ImageData@
    Image[Graphics[{White,
       Table[Translate[
         Rotate[flake, RandomReal[{0, [Pi]/6}]], {RandomReal[{0, x}],
           RandomReal[{0, 5 x}]}], {num}]}, Background -> Blue,
      PlotRange -> {{0, x}, {0, 5 x}}], ImageSize -> {size, 5 size}]];

size = 250;

r = snowfield @@@ {{1, size, 500}, {1.5, size, 250}, {2, size, 50}};
Dynamic[Image[(r[[#]] = RotateRight[r[[#]], #]) & /@ {1, 2, 3};
  Total[r[[All, ;; size]]]]]

URL: 点击打开链接