SHOW:
|
|
- or go back to the newest paste.
1 | data = Import["http://mi.eng.cam.ac.uk/~mh521/js/data.js", "Text"]; | |
2 | x = Select[ToExpression /@ (StringSplit[data, ","][[8 ;; -2]]), | |
3 | NumberQ]; | |
4 | ps = Transpose[{Range[Length[x]], x}]; | |
5 | Needs["ComputationalGeometry`"]; | |
6 | ps = Table[ps[[i]], {i, 1, Length[ps], Floor[Length[ps]/500]}]; | |
7 | dt = DelaunayTriangulation[ps]; | |
8 | toEdges[{m_, ns_List}] := Map[{m, ns[[#]]} &, Range[Length[ns]]]; | |
9 | AdjToTriangles[adj_List] := | |
10 | - | With[{p = poly[[j]], |
10 | + | Module[{verts = Union[Flatten[adj]], sides, Side}, |
11 | SetAttributes[Side, Orderless]; | |
12 | sides = | |
13 | Union[Side @@@ | |
14 | Flatten[Distribute[#, List] & /@ Transpose[{verts, adj}], 1]]; | |
15 | - | Mod[RandomVariate[NormalDistribution[j/Length@poly, 0.1]], |
15 | + | ReplaceList[ |
16 | - | 1]], |
16 | + | sides, {___, Side[i_, j_], ___, Side[i_, k_], ___, |
17 | - | Darker@col, |
17 | + | Side[j_, k_], ___} -> {i, j, k}]]; |
18 | - | If[j < Length[poly], Line[{First[p], poly[[j + 1, 1]]}], {}], |
18 | + | edges = Union[Sort /@ Flatten[toEdges /@ dt, 1]]; |
19 | triangles = AdjToTriangles[edges]; | |
20 | - | Table[ |
20 | + | |
21 | - | Polygon[{First[p], p[[-1, i]], |
21 | + | toTriangles[{m_, ns_List}] := |
22 | - | p[[-1, Mod[i + 1, Length@Last[p], 1]]]}] |
22 | + | Map[{m, ns[[#]], ns[[Mod[# + 1, Length[ns], 1]]]} &, |
23 | - | , {i, Length@Last[p]}]} |
23 | + | Range[Length[ns]]]; |
24 | triangles = Union[Sort /@ Flatten[toTriangles /@ poly, 1]]; | |
25 | Graphics[{ | |
26 | - | {j, Length@poly}] |
26 | + | |
27 | Table[ | |
28 | With[{p = triangles[[j]], | |
29 | col = ColorData["StarryNightColors"][(*j/Length[poly]*) | |
30 | RandomReal[]]}, | |
31 | { | |
32 | Opacity[ | |
33 | Mod[RandomVariate[NormalDistribution[j/Length@triangles, 0.1]], | |
34 | 1]], | |
35 | col, | |
36 | Polygon[p] | |
37 | } | |
38 | ] | |
39 | , | |
40 | {j, Length@triangles}] | |
41 | ] | |
42 | }, PlotRange -> All, AspectRatio -> 0.618] |