-
Notifications
You must be signed in to change notification settings - Fork 0
/
Isometric-Master.lua
232 lines (205 loc) · 6.8 KB
/
Isometric-Master.lua
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
-- Version 0.1.0
-- Created by: Callum Brezden
-- Description: A script to create isometric shapes in Aseprite
-- Github: github.com/brezden
-- License: MIT
local dlg = Dialog("Isometric Master")
local maxSize = {
x = math.floor(app.activeSprite.width/4),
y = math.floor(app.activeSprite.width/4),
z = math.floor(app.activeSprite.height/2)
}
local Shapes = {
CUBE = "Cube",
CIRCLE = "Circle",
STAIR = "Stair"
}
local centerX = math.floor(app.activeSprite.width/2)
local centerY = math.floor(app.activeSprite.height/2)
local selected_shape = Shapes.CUBE
local leftMiddle = true
local createdLayers = {}
local offset = 0
local data = {}
local function drawStraightLine(x, y, len, color, direction)
local drawFuncs = {
vertical = function(i) app.activeImage:putPixel(x, y+i, color) end,
horizontal = function(i) app.activeImage:putPixel(x+i, y, color) end
}
local drawFunc = drawFuncs[direction]
for i=1,len do
drawFunc(i)
end
end
local function fillSquare(x, y, color)
local fillPoint = Point{ x, y }
app.useTool{
tool="paint_bucket",
color=color,
points={ fillPoint },
cel=app.activeCel,
layer=app.activeLayer,
frame=app.activeFrame,
}
end
local function colorCube(x, y, z)
fillSquare(centerX, centerY - 1, data.topColor) -- Top
fillSquare((centerX-y*2-1) + 1, (centerY-y) + 1, data.frontColor) -- Left
fillSquare(centerX+x*2-1, centerY-x + 1, data.shadeColor) -- Right
end
local function isoLine(x, y, len, color, direction)
local step = direction == "upRight" and 1 or -1
for i=0,len do
local baseX = x + i*2*step
app.activeImage:putPixel(baseX, y-i, color)
app.activeImage:putPixel(baseX + step, y-i, color)
end
end
local function drawCube(x, y, z, color)
offset = leftMiddle and -1 or 0
--- Straight lines
drawStraightLine(centerX + offset, centerY, z, middleStrokeEnabled and data.middleStrokeColor or color, "vertical") -- Middle
drawStraightLine(centerX-y*2-1, centerY-y, z, color, "vertical") -- Left
drawStraightLine(centerX+x*2, centerY-x, z, color, "vertical") -- Right
--- Diagonal lines
isoLine(centerX - 1, centerY, x, middleStrokeEnabled and data.middleStrokeColor or color, "upRight") -- Middle Right
isoLine(centerX, centerY, y, middleStrokeEnabled and data.middleStrokeColor or color, "upLeft") -- Middle Left
isoLine(centerX-y*2-1, centerY-y, x, color, "upRight") -- Top Left
isoLine(centerX+x*2, centerY-x, y, color, "upLeft") -- Top Right
isoLine(centerX, centerY + z, y, color, "upLeft") -- Bottom Left
isoLine(centerX - 1, centerY + z, x, color, "upRight") -- Bottom Right
-- Highlight
if highlightEnabled then
app.activeImage:putPixel(centerX + offset, centerY, data.highlightColor)
end
end
local function newLayer(name)
sprite = app.activeSprite
layer = sprite:newLayer()
layer.name = name
sprite:newCel(layer, 1)
table.insert(createdLayers, layer)
return layer
end
local function undoLastLayerCreation()
if #createdLayers > 0 then
local lastLayer = table.remove(createdLayers)
sprite:deleteLayer(lastLayer)
end
end
dlg:separator{ text="Shapes" }
:button { id="cube", text="Cube", selected=true, onclick=function() selected_shape = Shapes.CUBE dlg:modify{id="cube", selected=true} dlg:modify{id="circle", selected=false} dlg:modify{id="stair", selected=false} end }
:button { id="circle", text="Circle", selected=false, onclick=function() selected_shape = Shapes.CIRCLE dlg:modify{id="circle", selected=true} dlg:modify{id="cube", selected=false} dlg:modify{id="stair", selected=false} end }
:button { id="stair", text="Stair", selected=false, onclick=function() selected_shape = Shapes.STAIR dlg:modify{id="stair", selected=true} dlg:modify{id="circle", selected=false} dlg:modify{id="cube", selected=false} end }
dlg:separator{ text="Dimensions" }
:slider {id="ySize", label="Left:", min=1, max=maxSize.y, value=5}
:slider {id="xSize", label="Right:", min=1, max=maxSize.x, value=5}
:slider {id="zSize", label="Height:", min=3, max=maxSize.z, value=10}
dlg:separator{ text="Colors:" }
:color {id="topColor", label="Top:", color = Color{ r=99, g=155, b=255 }} -- Sky Blue
:color {id="shadeColor", label="Shade:", color = Color{ r=13, g=64, b=153 }} -- Steel Blue
:color {id="frontColor", label="Front:", color = Color{ r=20, g=95, b=230 }} -- Blue
dlg:separator{ text="Strokes:" }
:color {
id="strokeColor",
label="Stroke:",
color = Color{ r=0, g=0, b=0 } -- Black
}
:color {
id="middleStrokeColor",
label="Middle Stroke:",
color = Color{ r=150, g=188, b=255 }, -- Navy
visible=function()
return middleStrokeEnabled -- The color picker is visible if the middle stroke is enabled
end
}
:radio {
id="middleStrokeOn",
text="On",
selected=true,
onclick=function()
middleStrokeEnabled = true
dlg:modify{id="middleStrokeColor", visible=true} -- Show the color picker
end
}
:radio {
id="middleStrokeOff",
text="Off",
selected=false,
onclick=function()
middleStrokeEnabled = false
dlg:modify{id="middleStrokeColor", visible=false} -- Hide the color picker
end
}
dlg:separator{ text="Highlight" }
:color {
id="highlightColor",
label="Highlight:",
color = Color{ r=255, g=255, b=255 }, -- White
visible=function()
return highlightEnabled -- The color picker is visible if the highlight is enabled
end
}
:radio {
id="highlightOn",
text="On",
selected=true,
onclick=function()
highlightEnabled = true
dlg:modify{id="highlightColor", visible=true} -- Show the color picker
end
}
:radio {
id="highlightOff",
text="Off",
selected=false,
onclick=function()
highlightEnabled = false
dlg:modify{id="highlightColor", visible=false} -- Hide the color picker
end
}
dlg:separator{ text="Actions" }
:radio {
id="left",
label="Middle Line: ",
text="Left",
selected=leftMiddle,
onclick=function() leftMiddle = true end
}
:radio {
id="right",
text="Right",
selected=not leftMiddle,
onclick=function() leftMiddle = false end
}
:button {
id="undo",
text="Undo",
onclick=function()
undoLastLayerCreation()
app.refresh()
end,
enabled=function()
return #createdLayers > 0
end
}
:button {
id="submit",
text="Add Shape",
onclick=function()
data = dlg.data
app.transaction(function()
if selected_shape == Shapes.CUBE then
newLayer("Cube("..data.xSize.." "..data.ySize.." "..data.zSize..")")
drawCube(data.xSize, data.ySize, data.zSize, data.strokeColor)
colorCube(data.xSize, data.ySize)
elseif selected_shape == Shapes.STAIR then
print("Stair not implemented yet.")
elseif selected_shape == Shapes.CIRCLE then
print("Circle not implemented yet.")
end
end)
app.refresh()
end
}
dlg:show()