Advertisement
Matthen

Triangle Wave Patterns

Aug 15th, 2015
881
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. x[t_] := {t, TriangleWave[t]};
  2. dt = 0.01;
  3. {tmin, tmax} = {0, 2};
  4. ds = 1/50.0;
  5.  
  6. pts = Table[x[t], {t, tmin, tmax, dt}];
  7. dists = Round[
  8. Accumulate[Map[Norm, (pts - RotateRight[pts])[[2 ;;]]]]/ds];
  9. posns = Table[Flatten[Position[dists, i]][[1]], {i, Union[dists]}];
  10. frame[n_] := Module[{imax},
  11. imax = Length[posns] - n;
  12. Graphics[{
  13. Table[
  14. {ColorData["DarkRainbow"][i/imax],
  15. Line[{pts[[posns[[i]]]], pts[[posns[[i + n]]]]}]}
  16. , {i, 1, imax}],
  17. {Thickness[0.005], RGBColor[0.0, 0.2, 0.4], Line[pts]}
  18. }, ImageSize -> 400, ImagePadding -> 10]];
  19. Manipulate[frame[n],{n,1,200}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement