Message Boards Message Boards

[GIF] Random Lines (8 frames of 20,000 random lines each)

20,000 random lines

Random Lines

This animation consists of 8 frames, each of which contains 20,000 randomly chosen lines. The frames are completely independent of each other, but they're each generated by the same basic process, so they look fairly similar.

In each case I generate 20,000 independent random points in the unit disk and 20,000 independent random directions, and then draw a line through each point parallel to the corresponding direction. The lines are colored according to the distance of the point to the origin: those passing through a chosen point close to the origin are nearly black, and then as the chosen point gets further out the color cycles through a reddish-pink, a turquoise, and then finally a light gray.

In order to generate the points, I choose the radius $r$ uniformly on $[0,1]$ and the angle $\theta$ uniformly on $[0,2\pi]$; then the point is $(r \cos \theta, r \sin \theta)$. (Note that these points are not uniform in the unit disk: they are concentrated near the origin. I'm choosing $r$ in this way just because I like how the resulting image looks better than for uniform points in the disk.)

The frames in the animation are independent, so I just generated 8 of them and then concatenated them into a single GIF. Here's the code to generate a single frame with width and height dimensions both doubled, followed by an example frame:

RandomAngle[] := RandomVariate[UniformDistribution[{0, 2 Pi}]];
RandomDirection[] := With[{θ = RandomAngle[]},
   {Cos[θ], Sin[θ]}
   ];

Module[{r, θ, v, p, cols = RGBColor /@ {"#252A34", "#FF2E63", "#08D9D6", "#EAEAEA"}},
 Graphics[{Thickness[.0002],
   Table[{
     r = RandomVariate[UniformDistribution[]];
     θ = RandomAngle[];
     v = RandomDirection[];
     p = {r Cos[θ], r Sin[θ]};
     {Blend[cols, r], InfiniteLine[p, v]}},
    {20000}]},
  PlotRange -> 1, ImageSize -> 1080]
 ]

20,000 lines

5 Replies

How did you create the GIF, I see the code and it outputs only one image... did you use Wolfram too to export a GIF consisting of 8 evaluations of that cell?

POSTED BY: Claudio Mora

I think it is as simple as generating 8 random images, putting them in a list and exporting, something like this probably:

Export["animation.gif",{img1, img2, ...}]
POSTED BY: Sam Carrettie

Yes, that will do it. For example, here's code that will do the whole thing (notice that I'm creating a $540 \times 540$ GIF, whereas the code in the original post creates a single $1080 \times 1080$ image):

RandomAngle[] := RandomVariate[UniformDistribution[{0, 2 Pi}]];
RandomDirection[] := 
  With[{\[Theta] = RandomAngle[]}, {Cos[\[Theta]], Sin[\[Theta]]}];

img = Block[{r, \[Theta], v, p, 
   cols = RGBColor /@ {"#252A34", "#FF2E63", "#08D9D6", "#EAEAEA"}},
  Table[
   Graphics[{Thickness[.0002], 
     Table[{r = RandomVariate[UniformDistribution[]];
       \[Theta] = RandomAngle[];
       v = RandomDirection[];
       p = {r Cos[\[Theta]], r Sin[\[Theta]]};
       {Blend[cols, r], InfiniteLine[p, v]}}, {20000}]}, 
    PlotRange -> 1, ImageSize -> 540],
   {8}]
  ];

Export["animation.gif", img, "DisplayDurations" -> 1/25, 
 "AnimationRepetitions" -> Infinity]

I really like that you are taking advantage of "DisplayDurations" in Export. I think that option influences a lot the visual perception of animation.

POSTED BY: Sam Carrettie

enter image description here -- you have earned Featured Contributor Badge enter image description here Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

POSTED BY: Moderation Team
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract