-
Notifications
You must be signed in to change notification settings - Fork 0
/
glazed_teracotta_editor.lua
76 lines (60 loc) · 2.58 KB
/
glazed_teracotta_editor.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
--[[
Glazed Terracotta Editor
Author: memopemo
An Aseprite script that alows the user to draw with an 45 degree mirroring.
It also will copy the result and rotates it into the other 4 quadrants to previewview it in context.
you may also copy/paste the upper right quadrant into the lower right quadrant to view the alternate rotation of the block.
]]--
local sprite = app.sprite
if sprite.width ~= sprite.height then
print("sprite must be square. exiting.")
return
end
if(sprite.width % 2 == 1) then
print("sprite must be even. exiting.")
return
end
local fullsize = sprite.width
local quadSize = sprite.width/2;
print("~~~Glazed Terracotta Editor~~~")
print(" by memopemo ")
print("To use, draw in the lower right quadrant of the sprite.")
print("Have fun making beautiful shapes and designs!")
print("Please make sure sprite takes up entire canvas before using. Else you may see white lines appear.")
sprite.events:on('change', function (ev)
-- prevent operation on absence of an image.
if(app.image == nil) then
return
end
clone = app.image:clone()
-- 45 degree flip from upper wedge of bottom right quadrant to lower wedge
for x = 0, quadSize, 1 do
for y = 0, x, 1 do
pixel = clone:getPixel(x - app.cel.position.x + quadSize, y - app.cel.position.y + quadSize)
clone:drawPixel(y - (app.cel.position.x) + quadSize, x - (app.cel.position.y) + quadSize, pixel)
end
end
-- rotate to bottom left quadrant
for y = 0, quadSize, 1 do
for x = 0, quadSize, 1 do
pixel = clone:getPixel(x - app.cel.position.x + quadSize, y - app.cel.position.y + quadSize)
clone:drawPixel((quadSize - y) - (app.cel.position.x+1), x - app.cel.position.y + quadSize, pixel)
end
end
-- rotate to top left quadrant
for y = 0, quadSize, 1 do
for x = 0, quadSize, 1 do
pixel = clone:getPixel(x - app.cel.position.x + quadSize, y - app.cel.position.y + quadSize)
clone:drawPixel((quadSize - x) - (app.cel.position.x+1), (quadSize - y) - (app.cel.position.y+1), pixel)
end
end
-- rotate to top right quadrant
for y = 0, quadSize, 1 do
for x = 0, quadSize, 1 do
pixel = clone:getPixel(x - app.cel.position.x + quadSize, y - app.cel.position.y + quadSize)
clone:drawPixel(y - app.cel.position.x + quadSize, (quadSize - x) - (app.cel.position.y+1), pixel)
end
end
app.cel.image = clone
app.refresh()
end)