15
$\begingroup$

Inspired by this (please use Chrome or Firefox), I tried to simulate it, but I couldn't do it. I'm not familiar with Dynamic. Here is my simple code:

Dynamic[
 Graphics[{Hue[Random[]], PointSize@Large, 
   Point[{0, Dynamic[Clock[{0, 5, 0.5}]]}]}, Axes -> 1, PlotRange -> 5]
 ]
$\endgroup$
2

2 Answers 2

30
$\begingroup$

Here you have a toy to start playing with:

Edit preventing the animation running at different speeds in different machines by using Clock[] and DynamicWrapper[] (due credit to @jVincent)

n = 500; (*number of managed  particles*)
x[i_][t_] := (vx0[i] (t - delay[i])) UnitStep[t - delay[i]];
y[i_][t_] := Module[{k},  If[(k = (-#^2 + vy0@i #) UnitStep@#) < 0 &[t - delay@i], 
                              delay[i] = t + RandomReal[{0, 5}], k]];
vcols = RandomReal[{0, 1}, n];
Table[vx0@i = RandomReal[{-1, 1}]; vy0@i = RandomReal[{10, 12}]; 
                                 delay@i = RandomReal[{0, 12}], {i, n}];

points[s_] := Table[{x[i][s], y[i][s]}, {i, n}];

DynamicModule[{t}, DynamicWrapper[
     Framed@Graphics[Dynamic@Point[points[t], VertexColors -> Hue /@ vcols], 
                     PlotRange -> {{-10, 10}, {0, 40}}, ImageSize -> 200], 
  t = Clock[10^6]]]

belisarius's x-rated effusion

enter image description here

$\endgroup$
16
  • 2
    $\begingroup$ Wow!.. this is cool.. +1 $\endgroup$
    – Murta
    Jan 26, 2013 at 13:34
  • 1
    $\begingroup$ GroosooooooooOO $\endgroup$
    – Rojo
    Jan 26, 2013 at 14:25
  • 1
    $\begingroup$ hm, I should have been faster :) +1 $\endgroup$
    – acl
    Jan 26, 2013 at 17:00
  • 1
    $\begingroup$ @Mr.Wizard, sure $\endgroup$
    – Rojo
    Jan 26, 2013 at 19:41
  • 1
    $\begingroup$ @cormullion - you mean "if you don't like" ;-). $\endgroup$
    – stevenvh
    Jan 26, 2013 at 20:00
21
$\begingroup$

Here is a modification @belisarius asked me to post. I was playing around and made a 3D version. Putting Dynamic inside Graphics3D lets you rotate the fountain.

n = 100;
width = 10;
x[i_][t_] := (x0[i] + vx0[i] (t - delay[i])) UnitStep[t - delay[i]];
y[i_][t_] := (y0[i] + vy0[i] (t - delay[i])) UnitStep[t - delay[i]];
z[i_][t_] := (k \[Function] 
     If[k < 0, 
      If[Abs[x[i][t]] > width || Abs[y[i][t]] > width, (* wait until over the edge *)
       delay[i] = t + RandomReal[{0, 12}], 0.01], 
      k])[(-#^2 + vz0@i # + z0[i]) UnitStep@# &@(t - delay[i])];
Table[x0@i = y0@i = z0@i = 0;
  vx0@i = RandomReal[{-1, 1}];
  vy0@i = RandomReal[{-1, 1}];
  vz0@i = RandomReal[{10, 12}];
  delay@i = RandomReal[{0, 12}], {i, n}];
points[s_] := 
  Table[{x[i][s], y[i][s], z[i][s]}, {i, n}]~Join~
   Table[{x[i][s], y[i][s], 0}, {i, n}];
{Graphics3D[
  GraphicsComplex[
   Dynamic@points[Clock[\[Infinity]]], {Point[Range[n], 
     VertexColors -> Hue /@ (Range[n]/n)], LightGray, 
    Point@Range[n + 1, 2 n]}], 
  PlotRange -> {{-width, width}, {-width, width}, {0, 40}}], 
 Dynamic[Clock[\[Infinity]]]}

Some output

Edit: Garden Hose

Here's a variation that uses ViewPoint and ViewVector to keep gravity pointing screen-down no matter how the graphics are rotated. The hose is gratuitous; but I ran into a bug with BezierCurve, so I used BezierFunction instead. The hose droops, too, according to the current gravity.

droplets = 200;
dist = 25;
hoseHeight = 5 - dist;

pos[t_, p0_, v0_, gravity_, delay_, droplets_] := 
  Table[p0[[i]] + (gravity #^2 + v0 [[i]] #) UnitStep@# &@(t - delay[[i]]), {i, droplets}];
p0 = ConstantArray[{0., 0., hoseHeight + 3.}, droplets];
v0 = MapThread[{#1 Cos[#2], #1 Sin[#2], #3} &,
      {RandomReal[{0, 1}, droplets], RandomReal[{0, 2 \[Pi]}, droplets], RandomReal[{10, 12}, droplets]}];
delay = RandomReal[{0, 13}, droplets];
points[s_] := (gravity = Normalize[(vv\[Cross]vp)\[Cross]vp]; 
   MapIndexed[(If[Max[Abs[#]] > dist, 
       delay[[First[#2]]] = s + RandomReal[{0, 4}]]; #) &,
    pos[s, p0, v0, gravity, delay, droplets]]);
hoseFn := 
  With[{offset = 
     5 Normalize[{gravity[[1]], gravity[[2]] + 1.`*^-6, 0}]},
   BezierFunction[{offset + {0, 0, hoseHeight - 5} + 2 dist gravity, 
     offset + {0, 0, hoseHeight - 5}, {0, 0, hoseHeight - 5}, {0, 0, 
      hoseHeight}}]];
vp = {1.8, -2.8, 0}; vv = {0., 0., 1.}; (* ViewPoint, ViewVertical *)

Graphics3D[{
  GraphicsComplex[
   Dynamic@points[Clock[\[Infinity]]], {Specularity[White, 10],
     {Hue[0.45 + #/(4 droplets), 0.7, 1], Sphere[#, 0.25]} & /@ Range[droplets]
    }],
  {Thickness[0.0075], LightGray, 
   Line[{{0, 0, hoseHeight}, {0, 0, hoseHeight + 3.1}}], Darker@Green,
    Dynamic@Line[Table[hoseFn[t], {t, 0, 1, 0.05}]]}
  },
 PlotRange -> dist, PlotRangePadding -> {{0, 0}, {0, 0}, {0, 0}}, 
 ViewPoint -> Dynamic@vp, ViewVertical -> Dynamic@vv, 
 SphericalRegion -> True, ImageSize -> 400, Background -> Black]

Sprinkling hose animation

In one respect it is not like a garden hose. When the graphics are rotated, the water droplets change their trajectories. In real life, you could only rotate the hose.

$\endgroup$
2
  • 1
    $\begingroup$ Nice use of GraphicsComplex! $\endgroup$ Jan 27, 2013 at 2:50
  • $\begingroup$ mmmm... skittles! $\endgroup$
    – rm -rf
    Jan 27, 2013 at 4:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.