Advertisement
Matthen

Pixelating Line Art

Jun 30th, 2013
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. Arc[a_] :=
  2. Module[{xs = Accumulate[Join[{0}, First /@ a]],
  3. ys = Accumulate[Join[{0}, Last /@ a]]},
  4. Table[
  5. {{xs[[i]], ys[[i]]}, {xs[[i]], ys[[i]]} + a[[i]]}
  6. , {i, Length[a]}
  7. ]
  8. ];
  9. ArcArray[a_] :=
  10. Module[{xs = Accumulate[Join[{0}, First /@ a]],
  11. ys = Accumulate[Join[{0}, Last /@ a]], out},
  12. out = Table[0, {j, Last[xs]}, {i, Last[ys]}];
  13. Do[
  14. out[[1 + xs[[i]] ;; xs[[i]] + a[[i, 1]],
  15. 1 + ys[[i]] ;; ys[[i]] + a[[i, 2]]]] = 1;
  16. , {i, Length[a]}
  17. ];
  18. out
  19. ];
  20. InterpolateArcs[a1_, a2_, order_, t_] := (
  21. Table[
  22. a1[[order[[i]]]] (1 - t) + a2[[i]] t
  23. , {i, Length[a1]}]
  24. );
  25. Tmax = 5;
  26. arc = {{1, 9}, {1, 7}, {1, 3}, {1, 4}, {1, 3}, {1, 2}, {1, 2}, {1,
  27. 2}, {1, 3}, {1, 1}, {1, 2}, {1, 1}, {1, 2}, {1, 1}, {1, 2}, {1,
  28. 1}, {1, 1}, {1, 1}, {1, 1}, {1, 2}, {1, 1}, {1, 1}, {1, 1}, {2,
  29. 1}, {1, 1}, {1, 1}, {1, 1}, {2, 1}, {1, 1}, {1, 1}, {2, 1}, {2,
  30. 1}, {1, 1}, {2, 1}, {2, 1}, {3, 1}, {2, 1}, {3, 1}, {3, 1}, {4,
  31. 1}, {5, 1}, {6, 1}};
  32. arc = {{1, 7}, {1, 2}, {1, 3}, {1, 4}, {1, 3}, {1, 2}, {1, 2}, {1,
  33. 2}, {1, 1}, {1, 1}, {1, 2}, {1, 1}, {2, 1}, {1, 1}, {3, 1}, {2,
  34. 1}, {3, 1}, {3, 1}, {2, 1}, {7, 1}};
  35. arcsorteds = Table[
  36. LocalSort[-#[[2]]/#[[1]] &, arc, i],
  37. {i, Tmax}];
  38. o = {LocalSort[-#[[2]]/#[[1]] &, arc, True]};
  39. Do[
  40. AppendTo[o,
  41. LocalSort[-#[[2]]/#[[1]] &, arcsorteds[[i]], True]
  42. ];
  43. , {i, Tmax - 1}];
  44. arcs = Join[{arc}, arcsorteds];
  45. step[\[Tau]_] := Sum[(0.5 + 0.5 Tanh[5 (\[Tau] - i)]), {i, Tmax}];
  46. Clear[frame];
  47. frame[\[Tau]_] := Module[{t = step[\[Tau]], recs},
  48. recs =
  49. InterpolateArcs[Arc[arcs[[Floor[t] + 1]]],
  50. Arc[arcs[[Floor[t] + 2]]], o[[Floor[t] + 1]], t - Floor[t]];
  51. Graphics[
  52. Table[Rotate[{
  53. White, EdgeForm[White],
  54. (Rectangle @@ #) & /@ recs,
  55. Black,
  56. Line /@ recs
  57. }, i Pi/2, {1, 1} 19],
  58. {i, 8}]
  59. , ImageSize -> 400, PlotRange -> All, Background -> Black]
  60. ];
  61. Manipulate[
  62. frame[\[Tau]]
  63. ,
  64. {\[Tau], 0, Tmax - 1}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement