I'd like to be able to better mimic the graphics at earth.nullschool.net using Mathematica and I'm looking for suggestions for either improving my code or getting directed to some other approach.
Below is code to create an animated gif that shows the StreamPlot
of {-1 - x^2 + y, 1 + x - y^2}
.
(* Set appearance of line segments in stream lines *)
(* Line segment plus blank space length *)
s = 0.25;
(* Number of shifts - larger integer values of k result in smoother transitions *)
k = 5;
(* Ratio of line segment length to blank space length *)
ratio = 20;
(* Maximum number of line seqments expected in a single stream line *)
maxSegments = 20;
(* Number of figures to create: n0 leading with a space and n1 leading with a line segment *)
n0 = k
n1 = k*ratio
delta = s/(n0 + n1) (* Amount of shift for each segment *)
s0 = s n0/(n0 + n1) (* Length of blank space *)
s1 = s n1/(n0 + n1) (* Length of line segment *)
(* Figures with stream lines leading with a line segment *)
g1 = Table[
StreamPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3},
StreamScale -> {Flatten[{{j delta, s0}, Table[{s1, s0}, {i, maxSegments}]}], 0, 0.0001},
ImageSize -> Medium],
{j, 1, n1}];
(* Figures with stream lines leading with a blank space *)
g0 = Table[
StreamPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3},
StreamScale -> {Flatten[{{0, j delta}, Table[{s1, s0}, {i, maxSegments}]}], 0, 0.0001},
ImageSize -> Medium],
{j, 1, n0}];
(* Combine figures *)
g = Flatten[{g0, g1}];
(* Export to an animated gif *)
Export["StreamPlot.gif", g]
I suspect I'll need to make a series of random starts for the stream lines to make it look less klunky but if there's another way to go about this, I'd appreciate learning about that.