Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- frames0 = Import["http://i.imgur.com/Uak4YU3.gif"];
- w = 600; h = 470;
- frames = Map[ImageCrop[#, {w, h}, {Right, Bottom}] &, frames0];
- frames = Delete[frames, 4];
- frames = Delete[frames, 18];
- frames = Delete[frames, 18];
- solutions = {};
- i = 6;
- Do[
- path = Thinning[
- DeleteSmallComponents[Binarize[frames[[i]], 0.36], 1000]];
- pathCoords = Position[ImageData[path], 1];
- f[p_] := {p[[2]], h - p[[1]]};
- g[p_] := {h - p[[2]], p[[1]]};
- pathCoords = f /@ pathCoords;
- pathCoords = SortBy[pathCoords, w #[[2]] + #[[1]] &];
- start = First[pathCoords];
- end = Last[pathCoords];
- pointNeighbours[{x_, y_}] := (
- Intersection[pathCoords,
- {{x + 1, y}, {x, y + 1}, {x - 1, y}, {x, y - 1},
- {x + 1, y + 1}, {x + 1, y - 1}, {x - 1, y + 1}, {x - 1, y - 1}
- }]
- );
- graphEdges[{x_, y_}] :=
- UndirectedEdge[{x, y}, #] & /@ pointNeighbours[{x, y}];
- riverGraph =
- Graph[Union[Map[Sort, Flatten[graphEdges /@ pathCoords]]]];
- solution = FindShortestPath[riverGraph, start, end];
- AppendTo[solutions, solution];
- ,
- {i, Length@frames}];
- frameI[i_] := Show[
- frames[[i]],
- Graphics[{Thick, Lighter@Blue, Opacity[1.0],
- Arrowheads[{-.05, .05}], Line[solutions[[i]]], Lighter@Red,
- Arrow[{solutions[[i, 1]], solutions[[i, -1]]}],
- Inset[
- ListPlot[s[[;; i]], Joined -> True,
- PlotRange -> {{0, 35}, {0, Pi}}, Axes -> {False, True},
- AxesStyle -> White, PlotStyle -> Directive[Thick, White]],
- {10, 10}, {Left, Bottom}, 300
- ]
- }]
- , ImageSize -> 300];
- Manipulate[
- frameI[i]
- , {i, 1, Length@frames, 1}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement