-
Notifications
You must be signed in to change notification settings - Fork 6
/
square to isometric-front.lua
59 lines (50 loc) · 1.6 KB
/
square to isometric-front.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
--right side(front)
--the pixels will go up diagonally
local originPoint
-- bail if there's no active sprite
local sprite = app.activeSprite
local currentCel = app.activeCel
if not sprite then
print("No sprite")
return
end
-- bail if nothing's selected
local selection = sprite.selection
if selection.isEmpty then
print("Missing selection")
return
end
if selection.bounds.width % 2 ~= 0 then
print("The width must be an even number")
end
function CopyImage(fromImage, rect)
local pixelsFromSelection = fromImage:pixels(rect)
local selectedImage = Image(rect.width, rect.height + rect.width/2)
local yStartOffset = rect.width / 2
local yOffset = yStartOffset
for it in pixelsFromSelection do
local pixelValue = it()
local newX = it.x - rect.x
local newY = it.y - rect.y
if(newX % 2 == 0) then
yOffset = yOffset - 1
end
if(newX == 0) then
yOffset = yStartOffset
end
selectedImage:putPixel(newX, newY + yOffset, pixelValue)
end
return selectedImage
end
originPoint = selection.origin
local currentImage = Image(sprite.width, sprite.height)
currentImage:drawSprite(sprite, currentCel.frameNumber)
local selectedImage = CopyImage(currentImage, selection.bounds)
local outputLayer = sprite:newLayer()
outputLayer.name = "IsometricFront"
local outputSprite = outputLayer.sprite
local cel = sprite:newCel(outputLayer, currentCel.frameNumber)
local backToOriginImage = Image(outputSprite.width,outputSprite.height)
--backToOriginImage:drawImage(newIso, originPoint)
backToOriginImage:drawImage(selectedImage, originPoint)
cel.image = backToOriginImage