-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.gd
More file actions
29 lines (24 loc) · 935 Bytes
/
utility.gd
File metadata and controls
29 lines (24 loc) · 935 Bytes
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
static func make_triangle(side: float, up: bool) -> PackedVector2Array:
var h = side * sqrt(3) / 2.0
if up:
return PackedVector2Array([Vector2(-side/2, h/2), Vector2(side/2, h/2), Vector2(0, -h/2)])
else:
return PackedVector2Array([Vector2(-side/2, -h/2), Vector2(side/2, -h/2), Vector2(0, h/2)])
static func make_triangle_border(side: float, up: bool, inset: float) -> PackedVector2Array:
var points = make_triangle(side, up)
# compute centroid
var center = Vector2()
for p in points:
center += p
center /= points.size()
# shrink each vertex toward center
var inset_points = PackedVector2Array()
for p in points:
var dir = (p - center).normalized()
inset_points.append(p - dir * inset)
# close the loop
inset_points.append(inset_points[0])
return inset_points
static func read_json_file(path: String):
var content_string = FileAccess.get_file_as_string(path)
return JSON.parse_string(content_string)