generated from raysan5/raylib-gamejam-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStarryFrogTools.wl
107 lines (98 loc) · 2.43 KB
/
StarryFrogTools.wl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
(* ::Package:: *)
BeginPackage["StarryFrogTool`"];
StarryFrogConstellationDraw;
Begin["`Private`"];
$width = 11;
$height = 15;
$maxEdgeCount = 20;
toCString[data_] :=
MapApply[
Function[{p1, p2, bool},
" " <> StringRiffle[
ToString /@ {p1[[1]], $height - 1 - p1[[2]], p2[[1]], $height - 1 - p2[[2]], If[bool, "BRIDGE_ON_DEFAULT", "BRIDGE_OFF_DEFAULT", "BRIDGE_DISABLED"]},
{"{ ", ", ", " }"}
]
],
PadRight[data, $maxEdgeCount, {{{-1, 15}, {-1, 15}, -1}}]
] // StringRiffle[
#,
{" {\n", ",\n", "\n }"}
] & // StringJoin[
"{\n",
" " <> ToString[Length[data]] <> ",\n",
" " <> ToString[Length[Select[data, TrueQ[#[[3]]] &]]] <> ",\n",
#,
"\n}"
] &;
StarryFrogConstellationDraw[dataIn_ : {}] :=
DynamicModule[{data, p1, p2, mouseDraggedQ, undoValues, stars, nb},
data = dataIn;
p1 = p2 = {0, 0};
mouseDraggedQ = False;
undoValues = {};
stars = Table[Tooltip[Point[{x, y}], {x, $height - 1 - y}], {x, 0, $width - 1, 1}, {y, 0, $height - 1, 1}];
DialogInput[
Column[{
Row[{
Button[
"Print C structure",
Print[toCString[data]]
],
Button[
"Clear",
data = {}
],
Button[
"Reset",
data = dataIn
]
}],
Row[{
Row[{"Number of vertices: ", Dynamic @ Length[Union[Catenate[data[[All, {1, 2}]]]]]}],
Row[{"Number of edges: ", Dynamic @ Length[data], " (max. ", $maxEdgeCount, ")"}]
}, " | "],
EventHandler[
Pane @ Graphics[{
{Thick, Dynamic @ MapApply[{If[#3, Yellow, Red], Line[{#1, #2}]} &, data]},
{Opacity[.5, White], PointSize[Large], stars}
},
Background -> Black
],
{
"MouseDragged" :> (
If[!mouseDraggedQ,
p1 = Round @ MousePosition["Graphics"];
mouseDraggedQ=True
,
p2 = Round @ MousePosition["Graphics"]
]
),
"MouseUp" :> (
mouseDraggedQ = False;
AppendTo[data, {p1, p2, CurrentValue["ShiftKey"]}]
)
}]
}],
NotebookEventActions -> {
"EscapeKeyDown" :> DialogReturn[data],
{"MenuCommand", "Undo"} :>
If[data =!= {},
AppendTo[undoValues, Last[data]];
data = Most[data];
,
Beep[]
],
{"MenuCommand", "Redo"} :>
If[undoValues =!= {},
AppendTo[data, Last[undoValues]];
undoValues = Most[undoValues];
,
Beep[]
]
},
WindowTitle -> "StarryFrogConstellationDraw",
WindowElements -> {"StatusArea"}
]
]
End[]
EndPackage[];