Advertisement
Guest User

connecting midpoints

a guest
Apr 15th, 2020
808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. smoothstep[t_, t0_, t1_] :=
  2. With[{tt = (t - t0)/(t1 - t0)},
  3. If[tt < 0, 0,
  4. If[tt > 1, 1, 6 tt^5 - 15 tt^4 + 10 tt^3]]]; numPoints = 20;
  5. numIter = 200;
  6. p0 = RandomReal[{-1, 1}, {numPoints, 2}];
  7. next[p_] := Map[
  8. With[{w = 0.5}, w #[[1]] + (1 - w) #[[2]]] &
  9. , Transpose[{p, RotateLeft[p]}]];
  10. ps = NestList[next, p0, numIter];
  11. offset[t_] := smoothstep[t, 1, 2] Mean[ps[[-1]]];
  12. zoom[t_] := 1.2 (1 - smoothstep[t, 1, 2]) + smoothstep[t, 1, 2] 0.3;
  13. frame[t_, t2_, t3_] := (With[{j = Floor[t], tt = t - Floor[t]},
  14. Graphics[{
  15. White,
  16. Thickness[0.003],
  17. PointSize[0.02],
  18. {
  19. Opacity[1 - smoothstep[tt, 0.66, 1.]],
  20. Point[ps[[j, ;; Clip[Floor[numPoints t3], {0, numPoints}]]]],
  21. Line[
  22. Join[ps[[j]], {ps[[j, 1]]}][[;;
  23. Clip[Floor[(numPoints + 1) (t3 - 1)], {0, numPoints + 1}]]]]
  24. },
  25. {
  26. Blend[{RGBColor[0.25, 0.85, 1.], White},
  27. smoothstep[tt, 0.66, 1]],
  28. {Opacity[smoothstep[tt, 0, 0.33]], Point[ps[[j + 1]]]},
  29. {Opacity[smoothstep[tt, 0.33, 0.66]],
  30. Line[Join[ps[[j + 1]], {ps[[j + 1, 1]]}]]}
  31. },
  32. If[t2 <= 0, {},
  33. {
  34. White,
  35. Module[{x, y, z},
  36. {x, y} = offset[2];
  37. z = 1.05 zoom[2];
  38. {
  39.  
  40. Line[{
  41. {x - z, y + z}, {x - z + 2 smoothstep[t2, 0, 0.25] z,
  42. y + z}}],
  43. If[t2 <= 0.25, {},
  44. Line[{
  45. {x + z, y + z}, {x + z,
  46. y + z - 2 z smoothstep[t2, 0.25, 0.5]}}]
  47. ],
  48. If[t2 <= 0.5, {},
  49. Line[{
  50. {x + z, y - z}, {x + z - 2 z smoothstep[t2, 0.5, 0.75],
  51. y - z}}]
  52. ],
  53. If[t2 <= 0.75, {},
  54. Line[{
  55. {x - z, y - z}, {x - z,
  56. y - z + 2 z smoothstep[t2, 0.75, 1.]}}]
  57. ]
  58. }
  59. ]
  60. }
  61. ]
  62. },
  63. PlotRange -> Transpose[{
  64. offset[t2] + zoom[t2] {1, 1},
  65. offset[t2] - zoom[t2] {1, 1}
  66. }],
  67. Background -> Black, ImageSize -> 500
  68. ]
  69. ]);
  70. Manipulate[
  71. frame[t, t2, t3],
  72. {{t, 1}, 1, 120},
  73. {t2, 0, 2},
  74. {t3, 0, 2}
  75. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement