Repository navigation
Expand file tree
/
Copy pathDrawNodeTL.lua
More file actions
118 lines (102 loc) · 2.58 KB
/
Copy pathDrawNodeTL.lua
File metadata and controls
118 lines (102 loc) · 2.58 KB
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
108
109
110
111
112
113
114
115
116
117
118
local Vec2 <const> = require("Vec2")
local threadLoop <const> = require("threadLoop")
local Node <const> = require("Node")
local DrawNode <const> = require("DrawNode")
local Color <const> = require("Color")
local App <const> = require("App")
local Line <const> = require("Line")
local function CircleVertices(radius, verts)
if verts == nil then
verts = 20
end
local function newV(index, r)
local angle = 2 * math.pi * index / verts
return Vec2(r * math.cos(angle), radius * math.sin(angle)) + Vec2(r, radius)
end
local vs = {}
local count = 1
for index = 0, verts do
vs[count] = newV(index, radius)
count = count + 1
end
return vs
end
local function StarVertices(radius)
local a = math.rad(36)
local c = math.rad(72)
local f = math.sin(a) * math.tan(c) + math.cos(a)
local R = radius
local r = R / f
local vs = {}
local count = 1
for i = 9, 0, -1 do
local angle = i * a
local cr = i % 2 == 1 and r or R
vs[count] = Vec2(cr * math.sin(angle), cr * math.cos(angle))
count = count + 1
end
return vs
end
local node = Node()
local star = DrawNode()
star.position = Vec2(200, 200)
star:drawPolygon(StarVertices(60), Color(0x80ff0080), 1, Color(0xffff0080))
star:addTo(node)
local themeColor = App.themeColor
local circle = Line(CircleVertices(60), themeColor)
circle.position = Vec2(-200, 200)
circle:addTo(node)
local camera = Node()
camera.color = themeColor
camera.scaleX = 2
camera.scaleY = 2
camera:addTo(node)
local cameraFill = DrawNode()
cameraFill.opacity = 0.5
cameraFill:drawPolygon({
Vec2(-20, -10),
Vec2(20, -10),
Vec2(20, 10),
Vec2(-20, 10),
})
cameraFill:drawPolygon({
Vec2(20, 3),
Vec2(32, 10),
Vec2(32, -10),
Vec2(20, -3),
})
cameraFill:drawDot(Vec2(-11, 20), 10)
cameraFill:drawDot(Vec2(11, 20), 10)
cameraFill:addTo(camera)
local cameraLine = Line(CircleVertices(10))
cameraLine.position = Vec2(-21, 10)
cameraLine:addTo(camera)
cameraLine = Line(CircleVertices(10))
cameraLine.position = Vec2(1, 10)
cameraLine:addTo(camera)
cameraLine = Line({
Vec2(20, 3),
Vec2(32, 10),
Vec2(32, -10),
Vec2(20, -3),
})
cameraLine:addTo(camera)
local ImGui <const> = require("ImGui")
local windowFlags = {
"NoDecoration",
"AlwaysAutoResize",
"NoSavedSettings",
"NoFocusOnAppearing",
"NoMove",
}
threadLoop(function()
local width = App.visualSize.width
ImGui.SetNextWindowBgAlpha(0.35)
ImGui.SetNextWindowPos(Vec2(width - 10, 10), "Always", Vec2(1, 0))
ImGui.SetNextWindowSize(Vec2(240, 0), "FirstUseEver")
ImGui.Begin("Draw Node", windowFlags, function()
ImGui.Text("Draw Node (Teal)")
ImGui.Separator()
ImGui.TextWrapped("Draw shapes and lines!")
end)
end)