# Untitled

a guest
Dec 10th, 2019
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. PixelPos[] :=
2. Replace[MousePosition["Graphics"], {{i_, j_} :> Round[{64 - j, i}],
3. _ :> None}]
4.
5. Attributes[PaintDot] = {HoldFirst};
6. PaintDot[data_Symbol, p : {i1_, j1_}] := Block[{dim = Length[data]},
7. Do[
8. If[EuclideanDistance[N[{i, j}], N[p]] < 2.5, data[[i, j]] = 0.],
9. {i, Max[i1 - 3, 1], Min[i1 + 3, dim]}, {j, Max[j1 - 3, 1],
10. Min[j1 + 3, dim]}]]
11.
12. Attributes[PaintLine] = {HoldFirst};
13. PaintLine[data_Symbol, {i1_, j1_},
14. {i2_, j2_}] := Block[{dim, indices, ib, ie, jb, je},
15. indices = InterpolatePoints[N[{i1, j1}], N[{i2, j2}], 2.5];
16. {ib, ie} = Sort[{i1, i2}]; {jb, je} =
17. Sort[{j1, j2}]; {{ib, jb}, {ie, je}} =
18. Clip[{{ib, jb} - 3, {ie, je} + 3}, {1, Length[data]}];
19. Quiet[
20. Do[If[Min[(EuclideanDistance[N[{i, j}], #1] & ) /@ indices] <
21. 2.5,
22. data[[i, j]] = 0.], {i, ib, ie}, {j, jb, je}]]; ]
23.
24. InterpolatePoints[start\$_, stop\$_] := Module[{dist\$, unit\$},
25. dist\$ = N[EuclideanDistance[start\$, stop\$]];
26. If[dist\$ < 3,
27. Return[{start\$, stop\$}]
28. ];
29. unit\$ = Normalize[stop\$ - N[start\$]];
30. Append[stop\$][Table[start\$ + i*unit\$, {i, 0, dist\$, 3}]]
31. ]
32.
33. InterpolatePoints[p1_, p2_, r_] :=
34. Module[{d, v}, d = EuclideanDistance[p1, p2];
35. If[d < 2*r, Return[{p1, p2}]]; v = Normalize[p2 - p1];
36. Developer`ToPackedArray[
37. Append[p2][Table[p1 + i*v, {i, 0., d, r}]], Real]]
RAW Paste Data