Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
My second attempt at creating a pixel drawing app. Used for drawing sprites and sprite sheets for animation.
--# Main
-- Sprite Creator 2.0
-- Project by Eddie McConkie (Dwins)
--[[
TO-DO LIST
Glitches
- Fix the Tolerance Glitch
- Possible Glitch with the Sprite List
- Figure Out Blending Transparent Colors
Important
- Select stuff
- Copy/Cut/Paste
- Graphics Effects (Shaders?)
- Saving
- Importing
- Dialog Boxes
- Image Transformations
Cool Stuff
- Rounded Buttons (Zoom Highlight)
- Text Entry
- Save/Save As
- Autosave
- Screen Animations
- Undo/Redo complex changes
- Grid
- Rulers
]]
-- displayMode(OVERLAY)
-- displayMode(FULLSCREEN)
displayMode(FULLSCREEN_NO_BUTTONS)
supportedOrientations(LANDSCAPE_ANY)
-----------------------------------Setup-----------------------------------
function setup()
parameter.watch("editor.selectedImg")
-- print(WIDTH*2/3,HEIGHT-100)
font("HelveticaNeue-Light")
fontSize(24)
theme = "dark"
if theme == "light" then
lightGray = color(210,210,215,255)
medGray = color(200)
darkGray = color(255)
else
lightGray = color(34, 38, 48, 255)
medGray = color(52, 57, 70, 255)
darkGray = color(51, 53, 61, 255)
end
saveAlert = Alert(300,130,"Load auto save data?","Cancel",function() end,"Load",loadAutoSave)
blue = color(0, 255, 225, 255)
blue = color(0, 100, 255, 255)
blueTransparent = color(blue.r, blue.g, blue.b, 127)
red = color(255, 100, 30, 255)
iconDraw()
drawTab = {"Free Draw","Line","Rectangle","Circle","Paint Bucket","Color Fill","Erase"}
drawIcons = {icons.free,icons.line,icons.rect,icons.circle,icons.paint,icons.fill,icons.erase}
transTab = {"Select","Cut","Copy","Paste",
"Flip Horizontal","Flip Vertical","Translate","Resize","Rotate"}
transIcons = {icons.select,icons.cut,icons.copy,icons.paste,
icons.hor,icons.vert,icons.trans,icons.size,icons.rotate}
effectsTab = {"Invert","Blur","Tint","Saturation","Gradient"}
effectsIcons = {}
drawMenu = false
transMenu = false
effectsMenu = false
drawButtons()
editor = Editor(32,32)
drawPens()
lineSize = 1
colorpicker = ColorPicker()
animator = Animator()
save = Save()
sprites = Button(280,HEIGHT-25,100,"Sprites",function()
animator.open = true
animator.closing = false
end)
colorBut = Button(WIDTH/3+25,25,50,nil,
function()
if colorpicker.open == false and editTouch == nil then
colorpicker.open = true
colorpicker.closing = false
elseif editTouch == nil then
-- colorpicker.open = false
colorpicker.closing = true
editor.pan = false
for i,d in pairs(drawTab) do
if tool == d then Draw.selected = i end
end
end
end)
eyeDropper = Button(WIDTH/3+75,25,50,eyeDrop,function()
if tool ~= "Eye Dropper" then
colorpicker.open = false
tool = "Eye Dropper"
editor.pan = false
else
tool = nil
for i,d in pairs(drawTab) do
if i == drawTab.selected then tool = d end
end
end
end)
eyeDropFrame = buttonFrame(35,35)
gridEnabled = false
gridBut = Button(WIDTH/3+125,25,50,grid,function()
if gridEnabled == true then
gridEnabled = false
else
gridEnabled = true
end
end)
gridButFrame = buttonFrame(35,35)
Add = Button(WIDTH-125,25,50,add,function() animator:addSprite(false) end)
Copy = Button(WIDTH-75,25,50,copy,function() animator:addSprite(true) end)
Delete = Button(WIDTH-25,25,50,delete,function() animator:deleteSprite() end)
Exit = Button(25,HEIGHT-25,50,exit,function() close() end)
saveBut = Button(WIDTH-130,HEIGHT-25,50,"Save",function() save.open = true; save.closing = false end)
Draw = Menu(drawTab,drawIcons,"Draw",50,25,100)
Transform = Menu(transTab,transIcons,"Transform",160,25,120)
Effects = Menu(effectsTab,effectsIcons,"Effects",280,25,120)
menus = {Draw,Transform,Effects}
Draw.open = true
Draw.selected = 1
tool = "Free Draw"
editor.pan = false
-- dialog = vec2(2*WIDTH/3,HEIGHT/2)
dialog = vec2(WIDTH/6,HEIGHT/2+150)
dialogSize = vec2(150,75)
Rotate = Dialog({},{
-- Slider(dialog.x-dialogSize.x,dialog.y,dialogSize.x*2,0,-360,360)
Slider(30,dialog.y,WIDTH/3-60,0,-360,360,true)
},{
Boolean(dialog.x,dialog.y+100,true,"All Images")
},"Rotate")
drawLine = image(10,10)
setContext(drawLine)
noSmooth()
stroke(0, 10, 255, 255)
strokeWidth(1)
line(1,1,10,10)
smooth()
setContext()
mainButtons = {Add,Copy,Delete,Exit,sprites,colorBut,eyeDropper,gridBut,saveBut}
autosave = image(animator.tab[1].width*10,animator.tab[1].height*10)
xCounter = 1
yCounter = 1
alertTab = {saveAlert}
if readImage("Documents:SpriteCreatorAutoSave") then tween.delay(2.5,function() saveAlert.open = true end) end
parameter.watch("#editor.undoTab")
end
-----------------------------------Draw-----------------------------------
function draw()
-- if math.floor(ElapsedTime)%60 == 0 then collectgarbage() end
-- noSmooth()
background(darkGray)
if save.slidePos > 1 then
noSmooth()
editor:draw()
-- editor:draw()
fill(darkGray)
-- fill(51, 53, 61, 255)
noStroke()
rect(0,0,WIDTH/3,HEIGHT)
--[[
if drawMenu == true then Draw:draw() end
if transMenu == true then Transform:draw() end
if effectsMenu == true then Effects:draw() end
if colorpicker.open == true then colorpicker:draw() end
]]
fill(lightGray)
noStroke()
rect(0,0,WIDTH,50)
rect(0,HEIGHT-50,WIDTH,50)
stroke(medGray)
strokeWidth(2)
line(0,50,WIDTH,50)
line(0,HEIGHT-50,WIDTH,HEIGHT-50)
line(WIDTH/3,50,WIDTH/3,HEIGHT-50)
fill(blue)
-- text("Exit",75,HEIGHT-25)
-- text("Sprites",280,HEIGHT-25)
-- sprites:draw()
text("New",WIDTH-50,HEIGHT-25)
-- text("Save",WIDTH-130,HEIGHT-25)
text("Import",WIDTH-220,HEIGHT-25)
stroke(blue)
pushMatrix()
translate(25,HEIGHT-25)
-- line(-10,-10,10,10)
-- line(-10,10,10,-10)
popMatrix()
-- Add:draw()
-- Copy:draw()
-- Delete:draw()
sprite(colorpicker.samplegrid,WIDTH/3+25,25,25,25)
-- colorBut:draw()
-- eyeDropper:draw()
if tool == "Eye Dropper" then sprite(eyeDropFrame,eyeDropper.x,eyeDropper.y) end
if gridEnabled == true then sprite(gridButFrame,gridBut.x,gridBut.y) end
stroke(medGray)
strokeWidth(4)
fill(colorpicker.r,colorpicker.g,colorpicker.b,colorpicker.a)
rect(WIDTH/3+10,10,30)
noSmooth()
-- if save then sprite("Dropbox:Save",WIDTH/6,HEIGHT/2,320) end
fill(blue)
noStroke()
-- if tool == "Rotate" then Rotate:draw() end
if drawMenu == true then Draw:draw() end
if transMenu == true then Transform:draw() end
if effectsMenu == true then Effects:draw() end
smooth()
if colorpicker.open == true then colorpicker:draw() end
if animator.open == true then
animator:draw()
fill(lightGray)
rect(0,HEIGHT-50,WIDTH,50)
else
for i,m in pairs(menus) do m:draw() end
end
noStroke()
for i,m in pairs(menus) do m.but:draw() end
for i,b in pairs(mainButtons) do b:draw() end
end
noStroke()
pushMatrix()
smooth()
pushStyle()
stroke(blue)
translate(25,HEIGHT-25)
-- line(-10,-10,10,10)
-- line(-10,10,10,-10)
popStyle()
popMatrix()
if tool == nil then tool = "Free Draw" end
for i,d in pairs(drawTab) do
if tool == d then Draw.selected = i end
end
if save.open == true then save:draw() end
--[[
pushStyle()
spriteMode(CORNER)
strokeWidth(2)
stroke(blue)
sprite(topL,50,500)
sprite(topR,100,500)
sprite(botL,50,450)
sprite(botR,100,450)
line(55,505,100,505)
popStyle()
]]
-- sprite(button,100,500)
-- sprite(buttonFrame(150,75),100,500)
strokeWidth(2)
if runAutoSave == true then autoSaveUpdate() end
-- saveAlert:draw()
for i,a in pairs(alertTab) do if a.open == true then a:draw() end end
if animator.tab[99] then sprite(animator.tab[99],100,500,200) end
end
-----------------------------------Touch-----------------------------------
function touched(touch)
-- animator:touched(touch)
local alertTest = 0
for i,a in pairs(alertTab) do if a.open == true then a:touched(touch); alertTest = alertTest + 1 end end
if alertTest == 0 then
if save.open == true then save:touched(touch) else
if tool == "Rotate" then
Rotate:touched(touch)
else
if touch.state == BEGAN then
if touch.y > HEIGHT-50 then topMenuTouch = touch.id
elseif touch.y < 50 then botMenuTouch = touch.id
elseif touch.x <= WIDTH/3 then leftMenuTouch = touch.id
elseif touch.x > WIDTH/3 then editTouch = touch.id
end
editor.prevTouch = vec2(0,0)
end
if editTouch == touch.id and colorpicker.open == true then
colorpicker:touched(touch)
elseif editTouch == touch.id and colorpicker.open == false then
editor:touched(touch)
end
if topMenuTouch == touch.id and editTouch == nil then
sprites:touched(touch)
end
if leftMenuTouch == touch.id and editTouch == nil then
if animator.open == true then
animator:touched(touch)
else
for i,m in pairs(menus) do m:touched(touch) end
end
end
if botMenuTouch == touch.id and editTouch == nil then
for i,m in pairs(menus) do m.but:touched(touch) end
colorBut:touched(touch)
eyeDropper:touched(touch)
gridBut:touched(touch)
Add:touched(touch)
Copy:touched(touch)
Delete:touched(touch)
end
if touch.state == ENDED and touch.x < 50 and touch.y > HEIGHT-50
and touch.id == topMenuTouch and editTouch == nil then close() end
if touch.state == ENDED then
if editTouch == touch.id then editTouch = nil end
end
--[[
if touch.state == BEGAN and touch.y > HEIGHT-50 then
save = image(editor.w,editor.h)
setContext(save)
noSmooth()
editor.mesh:draw()
setContext()
saveImage("Dropbox:Save",save)
end
]]
end
saveBut:touched(touch)
if touch.state == ENDED then
runAutoSave = true
else
runAutoSave = false
end
saveAlert:touched(touch)
end
end
end
-----------------------------------Buttons-----------------------------------
function drawButtons()
upArrow = image(40,40)
downArrow = image(40,40)
leftArrow = image(40,40)
rightArrow = image(40,40)
fill(blue)
stroke(blue)
smooth()
strokeWidth(6)
local arrows = mesh()
arrows.vertices = {vec2(10,10),vec2(30,10),vec2(20,10*math.sqrt(3)+10)}
setContext(upArrow)
arrows:draw()
line(10,10,30,10)
line(30,10,20,10*math.sqrt(3)+10)
line(20,10*math.sqrt(3)+10,10,10)
arrows.vertices = {vec2(10,30),vec2(30,30),vec2(20,30-10*math.sqrt(3))}
setContext(downArrow)
arrows:draw()
line(10,30,30,30)
line(30,30,20,30-10*math.sqrt(3))
line(20,30-10*math.sqrt(3),10,30)
arrows.vertices = {vec2(30,10),vec2(30,30),vec2(30-10*math.sqrt(3),20)}
setContext(leftArrow)
arrows:draw()
line(30,10,30,30)
line(30,30,30-10*math.sqrt(3),20)
line(30-10*math.sqrt(3),20,30,10)
arrows.vertices = {vec2(10,10),vec2(10,30),vec2(10*math.sqrt(3)+10,20)}
setContext(rightArrow)
arrows:draw()
line(10,10,10,30)
line(10,30,10*math.sqrt(3)+10,20)
line(10*math.sqrt(3)+10,20,10,10)
add = image(30,30)
setContext(add)
strokeWidth(2)
line(2,15,28,15)
line(15,2,15,28)
copy = image(36,36)
setContext(copy)
noFill()
line(5,5,5,25)
line(5,25,25,25)
line(25,25,25,5)
line(25,5,5,5)
line(30,30,10,30)
line(30,30,30,10)
delete = image(50,50)
setContext(delete)
stroke(blue)
strokeWidth(1.6)
line(15,10,14,35)
line(35,10,36,35)
line(15,10,35,10)
line(12,35,38,35)
line(20,35,20,40)
line(30,35,30,40)
line(20,40,30,40)
line(20,15,19,30)
line(25,15,25,30)
line(30,15,31,30)
pause = image(40,40)
setContext(pause)
pushStyle()
noStroke()
noSmooth()
fill(blue)
rect(5,8,8,24)
rect(20,8,8,24)
smooth()
popStyle()
zoomIn = image(50,50)
zoomOut = image(50,50)
setContext(zoomIn)
stroke(blue)
noFill()
ellipse(20,30,30)
line(45,5,30,20)
line(44,5,29,20)
line(20,20,20,40)
line(10,30,30,30)
setContext(zoomOut)
ellipse(20,30,30)
line(45,5,30,20)
line(44,5,29,20)
line(10,30,30,30)
undo = image(50,50)
redo = image(50,50)
noFill()
stroke(blue)
strokeWidth(2)
setContext(undo)
line(12,20,5,30)
line(12,20,21,30)
ellipse(25,25,30)
for i = 1,30 do
for j = 1,20 do
undo:set(i,j,color(0,0))
end
end
setContext(redo)
line(38,20,45,30)
line(38,20,29,30)
ellipse(25,25,30)
for i = 21,50 do
for j = 1,20 do
redo:set(i,j,color(0,0))
end
end
eyeDrop = image(40,40)
setContext(eyeDrop)
line(10,10,15,10)
line(15,10,26,21)
line(10,10,10,15)
line(10,15,21,26)
line(15,20,20,15)
line(21,29,29,21)
line(27,31,31,27)
line(27,31,24,28)
line(31,27,28,24)
grid = image(40,40)
setContext(grid)
line(12,8,12,32)
line(20,8,20,32)
line(28,8,28,32)
line(8,12,32,12)
line(8,20,32,20)
line(8,28,32,28)
exit = image(50,50)
setContext(exit)
line(15,15,35,35)
line(15,35,35,15)
stroke(blue)
strokeWidth(2)
noFill()
topL = image(5,5)
setContext(topL)
ellipse(5,0,10)
topR = image(5,5)
setContext(topR)
ellipse(0,0,10)
botL = image(5,5)
setContext(botL)
ellipse(5,5,10)
botR = image(5,5)
setContext(botR)
ellipse(0,5,10)
setContext()
button = buttonFrame(100,50)
end
function buttonFrame(w,h)
local img = image(w,h)
local rad = 10
pushStyle()
stroke(0,255)
fill(0,255)
strokeWidth(rad*2)
setContext(img)
line(rad,rad,rad,h-rad)
line(rad,h-rad,w-rad,h-rad)
line(w-rad,h-rad,w-rad,rad)
line(w-rad,rad,rad,rad)
rect(rad,rad,w-rad*2,h-rad*2)
local but = image(w,h)
fill(blue)
stroke(blue)
setContext(but)
rect(0,0,w,h)
for i = 3,w-2 do
for j = 3,h-2 do
local _,_,_,lef = img:get(i-1,j)
local _,_,_,rig = img:get(i+1,j)
local _,_,_,bot = img:get(i,j-1)
local _,_,_,top = img:get(i,j+1)
if lef > 0 and rig > 0 and bot > 0 and top > 0 then
but:set(i,j,color(0,0))
end
end
end
for i = 1,w do
for j = 1,h do
local _,_,_,alpha = img:get(i,j)
if alpha == 0 then but:set(i,j,color(0,0)) end
end
end
popStyle()
return but
end
-----------------------------------Auto Save-----------------------------------
function autoSaveUpdate()
setContext(autosave)
pushStyle()
spriteMode(CORNER)
local i = animator.tab[(yCounter-1)*10+xCounter]
if i then sprite(i,(xCounter-1)*i.width,(yCounter-1)*i.height,i.width,i.height) end
popStyle()
setContext()
xCounter = xCounter + 1
if xCounter > 10 then
xCounter = 1
yCounter = yCounter + 1
if yCounter > 10 then
yCounter = 1
autoSaveImage()
end
end
end
function autoSaveImage()
saveImage("Documents:SpriteCreatorAutoSave",autosave)
-- loadImg = readImage("Documents:AutoSave")
autosave = image(animator.tab[1].width*10,animator.tab[1].height*10)
collectgarbage()
end
function loadAutoSave()
animator:resize()
local img = readImage("Documents:SpriteCreatorAutoSave")
editor:resize(img.width/10,img.height/10)
local w,h =img.width/10,img.height/10
animator.tab = {}
for x = 1,10 do
for y = 1,10 do
animator.tab[(y-1)*10+x] = img:copy((x-1)*w+1,(y-1)*h+1,w,h)
end
end
local test = 0
for t = 100,2,-1 do
for i = 1,w do
for j = 1,h do
local _,_,_,alpha = animator.tab[t]:get(i,j)
if alpha > 2 then test = test + alpha end
end
end
if test == 0 then
table.remove(animator.tab,t)
else
break
end
end
for i = 1,editor.w do
for j = 1, editor.h do
local r,g,b,a = animator.tab[1]:get(i,j)
if a < 1 then a = 1 end
local v = 255/a
-- self.mesh:setRectColor(self.meshTab[i][j],color(r,g,b,a))
editor.mesh:setRectColor(editor.meshTab[i][j],color(r*v,g*v,b*v,a))
end
end
editor.undoId = 0
editor:updateImg()
editor.undoTab = {animator.tab[1]}
collectgarbage()
animator.selected = 1
animator.scrollMax = math.max(0,math.ceil(#animator.tab/3)*(animator.h+50)-300)
end
--# Menu
Menu = class()
function Menu:init(m,i,n,x,y,s)
self.menu = m
self.icons = i
self.name = n
self.x = x
self.y = y
self.size = s
self.length = #m*50+70
self.open = false
self.but = Button(x,y,s,n,function()
self.open = true
animator.closing = true
for i,m in pairs(menus) do
if m ~= self then
m.open = false
if m ~= Draw then m.selected = nil end
end
end
end)
end
function Menu:draw()
noStroke()
pushStyle()
fill(blue)
fontSize(24)
textMode(CORNER)
if self.open == true then
for i,m in pairs(menus) do
if m ~= self then
m.open = false
if m ~= Draw then m.selected = nil end
end
end
for i,m in pairs(self.menu) do
if self.selected == i then
pushStyle()
fill(lightGray)
rect(0,self.length-i*50-25/2,WIDTH/3,50)
popStyle()
elseif self.selected == nil then
pushStyle()
fill(0, 0, 0, 1)
noStroke()
-- rect(WIDTH/3,50,WIDTH*2/3,HEIGHT-100)
popStyle()
end
text(m,20,self.length-i*50)
noSmooth()
if self.icons[i] then sprite(self.icons[i],WIDTH/3-30,self.length-i*50+12,30) end
if self == Draw and self.open == true then
for i,m in pairs(self.menu) do
if i == self.selected and tool ~= "Eye Dropper" then tool = m end
end
end
end
end
popStyle()
-- if self.hover == true then fill(0, 100, 255, 100) end
-- text(self.name,self.x,self.y)
fill(blue)
noStroke()
end
function Menu:touched(touch)
--[[
if touch.state == ENDED and touch.tapCount > 0 and touch.y < 50 and self.open == false then
if vec2(touch.x,touch.y):dist(vec2(self.x,self.y)) < self.size/2 then
self.open = true
animator.open = false
for i,m in pairs(menus) do
if m ~= self then
m.open = false
if m ~= Draw then m.selected = nil end
end
end
end
end
]]
if self.open == true and touch.state == ENDED and touch.tapCount > 0
and touch.y < self.length and touch.y > 50 then
local pos = (self.length-touch.y)/50
pos = math.ceil(pos)
self.selected = pos
editor.pan = false
tool = self.menu[self.selected]
end
--[[
if touch.state ~= ENDED then
if vec2(touch.x,touch.y-50):dist(vec2(self.x,self.y)) < self.size/2 then
self.hover = true
else
self.hover = false
end
else
self.hover = false
end
]]
end
--# Button
Button = class()
function Button:init(x,y,s,i,f)
self.x = x
self.y = y
self.size = s
self.img = i
self.pressed = false
self.active = true
self.func = f
end
function Button:draw()
pushStyle()
if self.active == false then
tint(127,127,127)
fill(127,127,127)
elseif self.pressed == true and self.selected == true then
tint(255, 255, 255, 127)
fill(blueTransparent)
else
tint(255, 255, 255, 255)
fill(blue)
end
if type(self.img) == "userdata" then
sprite(self.img,self.x,self.y)
elseif type(self.img) == "string" then
text(self.img,self.x,self.y)
end
popStyle()
end
function Button:touched(touch)
if self == save.dropbox then
if touch.x > WIDTH*2/3 and touch.x < WIDTH and touch.y > 150 and touch.y < 250 then
self:processTouch(touch)
else
self.pressed = false
end
elseif self == save.documents then
if touch.x > WIDTH*2/3 and touch.x < WIDTH and touch.y > 50 and touch.y < 150 then
self:processTouch(touch)
else
self.pressed = false
end
else
if vec2(touch.x,touch.y):dist(vec2(self.x,self.y)) < self.size/2 then
self:processTouch(touch)
else
self.pressed = false
end
end
if touch.state == ENDED then self.selected = false end
end
function Button:processTouch(touch)
if touch.state == ENDED then
self.pressed = false
if self.selected == true then self.func() end
else
if touch.state == BEGAN then self.selected = true end
self.pressed = true
end
end
--# Slider
Slider = class()
function Slider:init(x,y,s,v,n,m,b)
self.x = x
self.y = y
self.size = s
self.val = v
self.min = n
self.max = m
if b == true then
self.left = Button(x+s/2-50,y+50,50,leftArrow,function() self.val = self.val - 1 end)
self.right = Button(x+s/2+50,y+50,50,rightArrow,function() self.val = self.val + 1 end)
end
end
function Slider:draw()
self.pos = self.size/(self.max-self.min)*(self.val-self.min)
strokeWidth(7)
stroke(blue)
line(self.x,self.y,self.x+self.pos,self.y)
if theme == "light" then stroke(100) else stroke(109, 114, 129, 255) end
line(self.x+self.pos,self.y,self.x+self.size,self.y)
strokeWidth(5)
stroke(200)
-- ellipse(self.x+self.val-1,self.y-1,30)
stroke(darkGray)
fill(blue)
ellipse(self.x+self.pos,self.y,30)
if self.left then self.left:draw() end
if self.right then self.right:draw() end
end
function Slider:touched(touch)
if self.left then self.left:touched(touch) end
if self.right then self.right:touched(touch) end
if touch.state == BEGAN then
if vec2(touch.x,touch.y):dist(vec2(self.x+self.pos,self.y)) < 20 then
self.grab = true
end
end
if self.grab == true then
self.val = (touch.x-self.x)*(self.max-self.min)/self.size+self.min
self.val = math.ceil(self.val)
end
if touch.state == ENDED then
self.grab = false
end
if self.val > self.max then self.val = self.max end
if self.val < self.min then self.val = self.min end
end
--# Boolean
Boolean = class()
function Boolean:init(x,y,v,t)
-- you can accept and set parameters here
self.x = x
self.y = y
self.val = v
self.text = t or nil
self.img = image(50,30)
setContext(self.img)
noStroke()
fill(blue)
ellipse(15,15,30)
if theme == "light" then fill(100) else fill(109, 114, 129, 255) end
ellipse(35,15,30)
fill(blue)
rect(15,1,10,28)
if theme == "light" then fill(100) else fill(109, 114, 129, 255) end
rect(25,1,10,28)
setContext()
self.pos = self.x
end
function Boolean:draw()
if self.val == true then
self.pos = self.pos + (self.x+10-self.pos)/5
else
self.pos = self.pos + (self.x-10-self.pos)/5
end
sprite(self.img,self.x,self.y)
stroke(darkGray)
strokeWidth(5)
fill(blue)
if self.hover == true then
ellipse(self.pos,self.y,40)
else
ellipse(self.pos,self.y,37)
end
if self.text then
text(self.text,self.x-string.len(self.text)*5-40,self.y)
end
end
function Boolean:touched(touch)
local d = vec2(touch.x,touch.y):dist(vec2(self.x,self.y))
if touch.state == BEGAN then
if d < 30 then self.press = true end
end
if touch.state == ENDED and d < 30 and self.press == true then
if self.val == true then self.val = false else self.val = true end
end
if d < 30 then self.hover = true else self.hover = false end
if touch.state == ENDED then
self.hover = false
self.press = false
end
end
--# Save
Save = class()
function Save:init()
self.open = false
self.closing = false
self:drawButtons()
self.selected = "Dropbox"
self.sheet = {x = 50, y = HEIGHT-100, size = HEIGHT-200}
self.columns = Slider(self.sheet.x,25,self.sheet.size,50,1,100,false)
self.cancel = Button(50,HEIGHT-25,50,"Cancel",function() self.closing = true end)
self.dropbox = Button(WIDTH*5/6,200,100,self.dropButPress,function() save.selected = "Dropbox" end)
self.documents = Button(WIDTH*5/6,100,100,self.docBut,function() save.selected = "Documents" end)
self.gridMesh = mesh()
self.gridMeshTab = {}
for i = 1,16 do
self.gridMeshTab[i] = {}
for j = 1,16 do
self.gridMeshTab[i][j] =
self.gridMesh:addRect(i-1/2,j-1/2,1,1)
if (i+j)%2 == 1 then
self.gridMesh:setRectColor(self.gridMeshTab[i][j],color(110, 110, 120, 255))
else
self.gridMesh:setRectColor(self.gridMeshTab[i][j],color(180, 180, 190, 255))
end
end
end
self.slidePos = HEIGHT
end
function Save:draw()
if self.closing == false then
self.slidePos = self.slidePos * 0.8
else
self.slidePos = HEIGHT - (HEIGHT-self.slidePos) * 0.8
end
if self.slidePos < 1 then self.slidePos = 0 end
if self.slidePos > HEIGHT-1 then self.slidePos = HEIGHT; self.open = false end
if self.selected == "Dropbox" then
self.dropbox.img = self.dropButPress
self.documents.img = self.docBut
else
self.documents.img = self.docButPress
self.dropbox.img = self.dropBut
end
pushMatrix()
translate(0,self.slidePos)
noStroke()
fill(darkGray)
rect(0,0,WIDTH,HEIGHT)
fill(lightGray)
rect(0,0,WIDTH,50)
rect(0,HEIGHT-50,WIDTH,50)
stroke(medGray)
line(0,50,WIDTH,50)
line(0,HEIGHT-50,WIDTH,HEIGHT-50)
stroke(darkGray)
strokeWidth(1.5)
if theme == "light" then stroke(medGray) else stroke(lightGray) end
line(self.sheet.size+100,50,self.sheet.size+100,HEIGHT-50)
self.columns:draw()
self.cancel:draw()
local size = 101/#animator.tab
for i = 1,#animator.tab do
if self.columns.val <= size*i and self.columns.val >= size*(i-1) then
self.col = i
end
end
--[[
if self.columns.left.selected == true and self.col > 1 then self.col = self.col - 1 end
if self.columns.right.selected == true and self.col < #animator.tab then self.col = self.col + 1 end
if self.col ~= math.ceil(self.columns.size/#animator.tab*self.col) then
self.columns.val = math.ceil(self.columns.size/#animator.tab*self.col)
end
]]
self.row = math.ceil(#animator.tab/self.col)
if animator.tab[1].width*self.col > animator.tab[1].height*self.row then
self.fit = "hor"
else
self.fit = "ver"
end
local size = self.columns.size
if self.fit == "hor" then
self.width = size/self.col
self.height = self.width*animator.tab[1].height/animator.tab[1].width
else
self.height = size/self.row
self.width = self.height*animator.tab[1].width/animator.tab[1].height
end
pushStyle()
pushMatrix()
translate(50,100)
pushStyle()
strokeWidth(8)
smooth()
if theme == "light" then stroke(121, 124, 133, 255) else stroke(lightGray) end
local lef = 0
local rig = self.col*self.width
local bot = self.sheet.size-self.row*self.height
local top = self.sheet.size
line(lef,bot,rig,bot)
line(rig,bot,rig,top)
line(rig,top,lef,top)
line(lef,top,lef,bot)
noSmooth()
popStyle()
clip(50,101+self.slidePos+self.sheet.size-self.row*self.height,self.col*self.width,self.row*self.height)
scale(self.sheet.size/16)
self.gridMesh:draw()
clip()
popMatrix()
if self.col == 1 then
text(self.col.." Sprite per Row",self.sheet.size/2+50,75)
else
text(self.col.." Sprites per Row",self.sheet.size/2+50,75)
end
pushStyle()
textMode(CORNER)
if self.col*animator.tab[1].width > 2048 then fill(red) else fill(blue) end
text("Width: "..math.ceil(self.col*animator.tab[1].width).."px",50,HEIGHT-90)
if self.row*animator.tab[1].height > 2048 then fill(red) else fill(blue) end
text("Height: "..math.ceil(self.row*animator.tab[1].height).."px",self.sheet.size/2+50,HEIGHT-90)
popStyle()
for i = 1,#animator.tab do
local x = (i-1)%self.col
local y = math.floor((i-1)/self.col)+1
local img = animator.tab[i]
local s = self.sheet
spriteMode(CORNER)
sprite(img,s.x+self.width*x,s.y-self.height*y,self.width,self.height)
end
popStyle()
-- text(self.slidePos,WIDTH-200,400)
-- text(1/DeltaTime,WIDTH-200,300)
-- sprite(icons.dropbox,WIDTH*2/3+48,240,64)
-- sprite(icons.folder,WIDTH*2/3+48,120,64)
pushStyle()
textMode(CORNER)
fontSize(30)
-- text("Dropbox",WIDTH*2/3+128,224)
-- text("Documents",WIDTH*2/3+128,104)
if self.selected == "Dropbox" then
sprite(self.dropButPress,WIDTH*5/6,200)
else
sprite(self.docButPress,WIDTH*5/6,100)
end
-- sprite(self.dropBut,WIDTH*5/6,200)
-- sprite(self.docBut,WIDTH*5/6,100)
self.dropbox:draw()
self.documents:draw()
popStyle()
popMatrix()
end
function Save:touched(touch)
self.columns:touched(touch)
self.cancel:touched(touch)
self.dropbox:touched(touch)
self.documents:touched(touch)
end
function Save:drawButtons()
local w,h = 300,80
local frame = buttonFrame(w,h)
pushStyle()
-- textMode(CORNER)
noSmooth()
fontSize(32)
fill(blue)
self.dropBut = image(w,h)
setContext(self.dropBut)
sprite(frame,w/2,h/2)
sprite(icons.dropbox,h/2,h/2,64)
text("Dropbox",w/2+h/2,h/2)
self.docBut = image(w,h)
setContext(self.docBut)
sprite(frame,w/2,h/2)
sprite(icons.folder,h/2,h/2,64)
text("Documents",w/2+h/2,h/2)
setContext()
popStyle()
self.dropButPress = self.dropBut:copy(1,1,w,h)
self.docButPress = self.docBut:copy(1,1,w,h)
for i = 3,w-2 do
for j = 3,h-2 do
local _,_,_,drop = self.dropBut:get(i,j)
self.dropButPress:set(i,j,color(blue.r,blue.g,blue.b,255-drop))
local _,_,_,doc = self.docBut:get(i,j)
self.docButPress:set(i,j,color(blue.r,blue.g,blue.b,255-doc))
end
end
end
--# Alert
Alert = class()
function Alert:init(w,h,message,left,leftFunc,right,rightFunc)
local w = w or 350
local h = h or 250
self.w = w
self.h = h
self.r = 25
self.message = message
self.open = false
self.closing = false
self.size = 0
self.leftBut = Button(WIDTH/2-self.w/4,HEIGHT/2+25-self.h/2,100,left,
function() leftFunc(); self.closing = true end)
self.rightBut = Button(WIDTH/2+self.w/4,HEIGHT/2+25-self.h/2,100,right,
function() rightFunc(); self.closing = true end)
self.box = image(w,h)
self.left = image(w/2,50)
self.right = image(w/2,50)
setContext(self.box)
pushStyle()
stroke(darkGray)
fill(darkGray)
stroke(lightGray)
fill(lightGray)
strokeWidth(self.r*2)
line(self.r,self.r,w-self.r,self.r)
line(w-self.r,self.r,w-self.r,h-self.r)
line(w-self.r,h-self.r,self.r,h-self.r)
line(self.r,h-self.r,self.r,self.r)
rectMode(CENTER)
rect(w/2,h/2,w-self.r*2,h-self.r*2)
local col = color(lightGray.r+15,lightGray.g+15,lightGray.b+15,255)
stroke(col)
fill(col)
rectMode(CORNER)
setContext(self.left)
line(self.r,self.r,w/2,self.r)
line(self.r,self.r,self.r,50)
rect(self.r,self.r,w/2-self.r,50)
setContext(self.right)
line(0,self.r,w/2-self.r,self.r)
line(w/2-self.r,self.r,w/2-self.r,50)
rect(0,self.r,w/2-self.r,50)
popStyle()
setContext()
end
function Alert:draw()
if self.closing == true then
self.size = self.size * 0.8
else
self.size = 1 - (1-self.size) * 0.8
end
if self.size < 0.05 then self.size = 0; self.open = false; self.closing = false end
if self.size > 0.95 then self.size = 1 end
fill(lightGray.r+15,lightGray.g+15,lightGray.b+15,self.size*100)
rect(0,0,WIDTH,HEIGHT)
pushMatrix()
translate(WIDTH/2,HEIGHT/2)
scale(self.size)
pushStyle()
-- spriteMode(CORNER)
tint(210, 210, 220, self.size*255)
sprite(self.box,0,0,self.box.width+2,self.box.height+2)
tint(255, 255, 255, self.size*255)
sprite(self.box,0,0)
if self.leftBut.pressed == true and self.leftBut.selected == true then
sprite(self.left,-self.w/4,25-self.h/2) end
if self.rightBut.pressed == true and self.rightBut.selected == true then
sprite(self.right,self.w/4,25-self.h/2) end
stroke(lightGray.r-15,lightGray.g-15,lightGray.b-15,self.size*127)
line(1-self.w/2,50-self.h/2,self.w/2-1,50-self.h/2)
line(0,1-self.h/2,0,49-self.h/2)
textMode(CENTER)
textAlign(CENTER)
fill(blue)
text(self.message,0,25)
popStyle()
popMatrix()
pushMatrix()
translate(WIDTH/2,HEIGHT/2)
scale(self.size)
translate(-WIDTH/2,-HEIGHT/2)
self.leftBut:draw()
self.rightBut:draw()
popMatrix()
end
function Alert:touched(touch)
self.leftBut:touched(touch)
self.rightBut:touched(touch)
end
--# Dialog
Dialog = class()
function Dialog:init(but,sli,bol,action)
self.buttons = but
self.sliders = sli
self.booleans = bol
self.action = action
self.box = image(dialogSize.x*2+50,dialogSize.y*2+50)
local d = dialog
local s = dialogSize
setContext(self.box)
pushStyle()
noStroke()
fill(255)
rect(25,25,s.x*2,s.y*2)
stroke(255)
strokeWidth(50)
line(25,25,25+s.x*2,25)
line(25+s.x*2,25,25+s.x*2,25+s.y*2)
line(25+s.x*2,25+s.y*2,25,25+s.y*2)
line(25,25,25,25+s.y*2)
stroke(lightGray)
strokeWidth(3)
line(0,50,50+s.x*2,50)
line(25+s.x,0,25+s.x,50)
popStyle()
setContext()
self.cancel = Button(d.x-(s.x+25)/2,d.y-s.y,75,"Cancel",function()
tool = "Free Draw"
Draw.open = true
Draw.selected = 1
end)
self.action = Button(d.x+(s.x+25)/2,d.y-s.y,75,self.action,function()
tool = "Free Draw"
Draw.open = true
Draw.selected = 1
end)
end
function Dialog:draw()
pushStyle()
tint(255,240)
-- sprite(self.box,dialog.x,dialog.y)
popStyle()
self.cancel:draw()
self.action:draw()
for i,b in pairs(self.buttons) do b:draw() end
for i,s in pairs(self.sliders) do
s:draw()
text(s.val,s.x+s.size/2,s.y+50)
end
for i,b in pairs(self.booleans) do b:draw() end
end
function Dialog:touched(touch)
self.cancel:touched(touch)
self.action:touched(touch)
for i,b in pairs(self.buttons) do b:touched(touch) end
for i,s in pairs(self.sliders) do s:touched(touch) end
for i,b in pairs(self.booleans) do b:touched(touch) end
end
--# Editor
-- Editor = class()
Editor = class()
function Editor:init(w,h)
self.mesh = mesh()
self.preview = mesh()
self.zoom = 1
self.prevTouch = vec2(0,0)
self:resize(w,h)
self.undoTab = {image(self.w,self.h)}
self.checkImg = image(self.w,self.h)
self.ZoomIn = Button(WIDTH/3+self.x+self.width/2+100,75,50,zoomIn,
function() if self.zoom < math.min(w,h)/8 then
self.zoom = self.zoom*2
self:zoomInOut("in")
if tool == "Eye Dropper" then tool = nil end
self.tch = nil
end end)
self.ZoomOut = Button(WIDTH/3+self.x+self.width/2-100,75,50,zoomOut,
function() if self.zoom > 1 then
self.zoom = math.ceil(self.zoom/2)
self:zoomInOut("out")
if self.zoom == 1 then
-- tool = nil
self.pan = false
end
if tool == "Eye Dropper" then tool = nil end
self.tch = nil
end end)
self.ZoomBut = Button(WIDTH/3+self.x+self.width/2,75,100,"Zoom x 1",
function()
if self.pan == false then
if self.zoom > 1 then self.pan = true end
for i,m in pairs(menus) do m.selected = false end
if tool == "Eye Dropper" then tool = nil end
self.tch = nil
else
self.pan = false
tool = "Free Draw"
Draw.selected = 1
end
end)
self.zoomFrame = buttonFrame(140,40)
self.leftSprite = Button(WIDTH/3+25,HEIGHT/2,50,leftArrow,function()
if animator.selected > 1 then
-- animator:update(animator.selected,animator.selected–1)
animator:update(animator.selected,animator.selected-1,true)
-- animator.selected = animator.selected - 1
end
-- tool = nil
-- for i,m in pairs(menus) do m.selected = nil end
end)
self.rightSprite = Button(WIDTH-25,HEIGHT/2,50,rightArrow,function()
if animator.selected < #animator.tab then
animator:update(animator.selected,animator.selected+1,true)
-- animator.selected = animator.selected + 1
end
-- tool = nil
-- for i,m in pairs(menus) do m.selected = nil end
end)
self.blendImg = image(self.w,self.h)
setContext(self.blendImg)
noSmooth()
self.mesh:draw()
setContext()
self.undoBut = Button(WIDTH/3+30,HEIGHT-75,60,undo,function()
self:undo()
animator:update(animator.selected,animator.selected,false)
end)
self.redoBut = Button(WIDTH/3+75,HEIGHT-75,60,redo,function()
self:redo()
animator:update(animator.selected,animator.selected,false)
end)
self.undoId = 0
self.undoMax = 51
self:updateImg()
self.buttons = {self.ZoomIn,self.ZoomOut,self.ZoomBut,
self.leftSprite,self.rightSprite,self.undoBut,self.redoBut}
self.circle = image(WIDTH,WIDTH)
self.circ = image(10,10)
setContext(self.circle)
ellipse(WIDTH/2,WIDTH/2,WIDTH)
setContext(self.circ)
sprite(self.circle,5,5,10)
setContext()
self.checkEye = false
end
function Editor:draw()
if self.selectPos and tool == "Select" then
self.prevTest = true
self:selectPreview(self.selectPos.x+self.selectedImg.width-1,
self.selectPos.y+self.selectedImg.height-1,self.selectPos)
-- self.prevTest = false
end
noTint()
pushMatrix()
fill(70,70,80)
noStroke()
translate(WIDTH/3,50)
rect(0,0,WIDTH*2/3+1,HEIGHT-100)
fill(200)
pushMatrix()
translate(self.x,self.y)
pushMatrix()
-- scale(self.w)
scale(math.max(self.width/16,self.height/16))
self.gridMesh:draw()
popMatrix()
translate(-self.panX,-self.panY)
scale(self.zoom*self.pixel)
self.mesh:draw()
if self.prevTest == true then self.preview:draw() end
popMatrix()
fill(70,70,80)
rect(0,0,WIDTH*2/3+1,self.y)
rect(0,HEIGHT-101-self.y,WIDTH*2/3+1,self.y+1)
rect(0,0,self.x,HEIGHT-100)
rect(WIDTH*2/3-self.x,0,self.x+1,HEIGHT-100)
popMatrix()
--[[
self.ZoomIn:draw()
self.ZoomOut:draw()
self.ZoomBut:draw()
self.undoBut:draw()
self.redoBut:draw()
self.leftSprite:draw()
self.rightSprite:draw()
]]
for i,b in pairs(self.buttons) do
if b == self.leftSprite and animator.selected > 1
or b == self.rightSprite and animator.selected < #animator.tab
or b == self.undoBut and self.undoId > 1
or b == self.redoBut and self.undoId < #self.undoTab
or b == self.ZoomIn and self.zoom < math.min(self.w,self.h)/8
or b == self.ZoomOut and self.zoom > 1
or b == self.ZoomBut
then
b.active = true
b:draw()
else
b.active = false
b:draw()
end
end
fill(blue)
noSmooth()
-- if self.paintImg then sprite(self.paintImg,500,400,256) end
smooth()
for i = 1,#self.undoTab do
-- sprite(self.undoTab[i],500+i*self.width*2,400,self.w*2)
end
if tool == "Eye Dropper" and self.tch then
pushStyle()
strokeWidth(5)
noFill()
stroke(lightGray)
ellipse(self.tch.x,self.tch.y+50,80)
local r,g,b,a = self.undoTab[self.undoId]:get(self.eyeX,self.eyeY)
fill(r,g,b,a)
stroke(darkGray)
ellipse(self.tch.x,self.tch.y+50,75)
popStyle()
end
pushStyle()
-- textMode(CORNER)
fill(blue)
-- text(animator.selected.."/"..#animator.tab,WIDTH-100,HEIGHT-90)
text(animator.selected.."/"..#animator.tab,WIDTH-55,HEIGHT-75)
popStyle()
clip(WIDTH/3+self.x,50+self.y,self.width,self.height)
if gridEnabled == true and math.max(self.w,self.h)/self.zoom <= 128 then
pushStyle()
stroke(50, 50, 55,225)
strokeWidth(2)
local s = self.pixel*self.zoom
for w = 1,self.w-1 do
local x = s*w
local y = self.height*self.zoom
pushMatrix()
translate(WIDTH/3+self.x-self.panX,50+self.y-self.panY)
line(x,0,x,y)
popMatrix()
end
for h = 1,self.h-1 do
local x = self.width*self.zoom
local y = s*h
pushMatrix()
translate(WIDTH/3+self.x-self.panX,50+self.y-self.panY)
line(0,y,x,y)
popMatrix()
end
popStyle()
end
clip()
if self.pan == true then sprite(self.zoomFrame,self.ZoomBut.x,self.ZoomBut.y) end
-- noSmooth()
-- sprite(self.circ,500,300,150)
-- if self.paintImg then sprite(self.paintImg,500,200) end
-- if self.fillImg then sprite(self.fillImg,500,250) end
end
function Editor:touched(touch)
self.prevTest = false
local test = 0
for i,b in pairs(self.buttons) do
if b.selected == true then test = test + 1 end
end
if test == 0 then
self:processTouch(touch)
self.prevTest = true
else
self.prevTouch = vec2()
self.startTouch = nil
self.prevTest = false
end
for i,b in pairs(self.buttons) do
if b == self.leftSprite and animator.selected > 1
or b == self.rightSprite and animator.selected < #animator.tab
or b == self.undoBut and self.undoId > 1
or b == self.redoBut and self.undoId < #self.undoTab
or b == self.ZoomIn and self.zoom < math.min(self.w,self.h)/8
or b == self.ZoomOut and self.zoom > 1
or b == self.ZoomBut and touch.y < 100
then
b:touched(touch)
self.prevTest = false
elseif b == self.ZoomBut then
if touch.y < 100 then
b:touched(touch)
self.prevTest = true
end
else
b:touched(touch)
self.prevTest = true
end
end
if touch.state == ENDED then for i,b in pairs(self.buttons) do b.selected = false end end
if touch.state == ENDED then
self.prevTest = false
else
self.prevTest = true
end
end
function Editor:processTouch(touch)
if touch.state == BEGAN then self.checkImg = image(self.w,self.h) end
if self.pan == true then
self.panX = self.panX - touch.deltaX
self.panY = self.panY - touch.deltaY
if self.panX < 0 then self.panX = 0 end
if self.panY < 0 then self.panY = 0 end
if self.panX > self.maxX then self.panX = self.maxX end
if self.panY > self.maxY then self.panY = self.maxY end
elseif self.pan == false then
local x = (touch.x-self.x-WIDTH/3+self.panX)/self.zoom/self.pixel
x = math.ceil(x)
if x < 1 then x = 1 end
if x > self.w then x = self.w end
local y = (touch.y-self.y-50+self.panY)/self.zoom/self.pixel
y = math.ceil(y)
if y < 1 then y = 1 end
if y > self.h then y = self.h end
if tool == "Free Draw" then self:smoothLines(x,y,self.prevTouch) end
if tool == "Erase" then self:smoothLines(x,y,self.prevTouch) end
if tool == "Eye Dropper" and touch.state ~= ENDED then
self.tch = vec2(touch.x,touch.y)
self.eyeX = x
self.eyeY = y
self.checkEye = true
else
self.tch = nil
-- checkEye = true
end
if self.startTouch == nil then self.startTouch = vec2(x,y) end
self:previewImg(x,y,self.prevTouch,self.startTouch)
if touch.state == ENDED then
if tool == "Line" then self:smoothLines(x,y,self.startTouch) end
if tool == "Rectangle" then self:drawRect(x,y,self.startTouch) end
if tool == "Circle" then self:drawEllipse(x,y,self.prevTouch,self.startTouch) end
if tool == "Paint Bucket" then self:paint(x,y) end
if tool == "Color Fill" then self:fill(x,y) end
if tool == "Eye Dropper" then
local r,g,b,a = self.undoTab[self.undoId]:get(x,y)
if a < 1 then a = 1 end
local v = 255/a
-- colorpicker.r,colorpicker.g,colorpicker.b,colorpicker.a = r,g,b,a
colorpicker.r,colorpicker.g,colorpicker.b,colorpicker.a = r*v,g*v,b*v,a
colorpicker:setColors()
for i,d in pairs(drawTab) do
if i == drawTab.selected then tool = d end
end
tool = "Free Draw"
end
if tool == "Select" then
local X = math.min(x,self.startTouch.x)
local Y = math.min(y,self.startTouch.y)
local W = math.abs(x-self.startTouch.x)+1
local H = math.abs(y-self.startTouch.y)+1
self.selectedImg = self.undoTab[self.undoId]:copy(X,Y,W,H)
self.selectPos = vec2(math.min(x,self.startTouch.x),math.min(y,self.startTouch.y))
end
self.startTouch = nil
end
self.prevTouch = vec2(x,y)
if touch.state == ENDED then
self.prevTouch = vec2()
self.startTouch = nil
local m = self.preview
local t = self.prevTab
for i = 1,#t do
for j = 1,#t[i] do
m:setRectColor(t[i][j],color(0,0))
end
end
self.blendImg = image(self.w,self.h)
setContext(self.blendImg)
noSmooth()
self.mesh:draw()
setContext()
collectgarbage()
-- if tool ~= "Eye Dropper" then
if self.checkEye == true then
self.checkEye = false
else
self:updateImg()
animator:update(animator.selected,animator.selected,false)
end
-- if tool == "Eye Dropper" then tool = nil end
end
end
--[[
if touch.tapCount > 1 then
if touch.x > WIDTH/3+self.x and touch.x < WIDTH-self.x
and touch.y > 50+self.y and touch.y < HEIGHT-50-self.y then
self.pan = false
if tool == nil then
tool = "Free Draw"
Draw.selected = 1
Draw.open = true
end
end
end
]]
end
function Editor:resize(w,h)
self.w = w
self.h = h
self.gridSize = 16
if w > h then
self.width = WIDTH*2/3-100
self.height = self.width*h/w
self.gridHor = self.gridSize
self.gridVer = self.gridSize*h/w
else
self.height = HEIGHT - 200
self.width = self.height*w/h
self.gridVer = self.gridSize
self.gridHor = self.gridSize*w/h
end
self.x = (WIDTH*2/3-self.width)/2
self.y = (HEIGHT-100-self.height)/2
self.pixel = self.width/w
self.gridPixel = self.width/self.gridHor
self.grid = image(self.width,self.height)
setContext(self.grid)
noStroke()
noSmooth()
for i = 1,self.gridHor+1 do
for j = 1,self.gridVer+1 do
if (i+j)%2 == 1 then
fill(110, 110, 120, 255)
else
fill(180, 180, 190, 255)
end
rect((i-1)*self.gridPixel,(j-1)*self.gridPixel,self.gridPixel,self.gridPixel)
end
end
smooth()
setContext()
self.gridMesh = mesh()
self.gridMeshTab = {}
for i = 1,self.gridHor+1 do
self.gridMeshTab[i] = {}
for j = 1,self.gridVer+1 do
self.gridMeshTab[i][j] =
self.gridMesh:addRect(i-1/2,j-1/2,1,1)
if (i+j)%2 == 1 then
self.gridMesh:setRectColor(self.gridMeshTab[i][j],color(110, 110, 120, 255))
else
self.gridMesh:setRectColor(self.gridMeshTab[i][j],color(180, 180, 190, 255))
end
end
end
self.meshTab = {}
for i = 1,w do
self.meshTab[i] = {}
for j = 1,h do
self.meshTab[i][j] =
self.mesh:addRect(i-1/2,j-1/2,1,1)
self.mesh:setRectColor(self.meshTab[i][j],color(0,0))
end
end
self.prevTab = {}
for i = 1,w do
self.prevTab[i] = {}
for j = 1,h do
self.prevTab[i][j] =
self.preview:addRect(i-1/2,j-1/2,1,1)
self.preview:setRectColor(self.prevTab[i][j],color(0,0))
end
end
collectgarbage()
self.zoom = 1
self.maxX = 0
self.maxY = 0
self.panX = 0
self.panY = 0
end
function Editor:zoomInOut(z)
if z == "in" then
self.panX = self.panX*2
self.panY = self.panY*2
end
if z == "out" then
self.panX = self.panX/2
self.panY = self.panY/2
end
self.maxX = (self.zoom-1)*self.width
self.maxY = (self.zoom-1)*self.height
if self.zoom == 1 then
self.panX = 0
self.panY = 0
self.pan = false
-- Draw.open = true
-- Draw.selected = 1
-- tool = "Free Draw"
end
if self.panX < 0 then self.panX = 0 end
if self.panY < 0 then self.panY = 0 end
if self.panX > self.maxX then self.panX = self.maxX end
if self.panY > self.maxY then self.panY = self.maxY end
self.pan = true
for i,m in pairs(menus) do
m.selected = nil
end
self.ZoomBut.img = "Zoom x "..self.zoom
end
--# ColorPicker
ColorPicker = class()
function ColorPicker:init()
self:drawGraphics()
self.tolerance = Slider(WIDTH/3+100,HEIGHT-150,300,21,1,256,false)
self.blend = Boolean(WIDTH/3+190,HEIGHT-220,true,"Blend")
self.fillShape = Boolean(WIDTH/3+390,HEIGHT-220,false,"Fill Shapes")
self.w = 400
self.x = (WIDTH*2/3-self.w)/2+WIDTH/3
self.y = self.x-WIDTH/3
self.open = false
self.closing = true
self.slidePos = WIDTH
self.r = 0
self.g = 0
self.b = 0
self.a = 255
self.red = mesh()
self.red.vertices = {vec2(0,0),vec2(0,25),vec2(self.w,25),vec2(self.w,25),vec2(self.w,0),vec2(0,0)}
self.green = mesh()
self.green.vertices = {vec2(0,0),vec2(0,25),vec2(self.w,25),vec2(self.w,25),vec2(self.w,0),vec2(0,0)}
self.blue = mesh()
self.blue.vertices = {vec2(0,0),vec2(0,25),vec2(self.w,25),vec2(self.w,25),vec2(self.w,0),vec2(0,0)}
self.alpha = mesh()
self.alpha.vertices = {vec2(0,0),vec2(0,25),vec2(self.w,25),vec2(self.w,25),vec2(self.w,0),vec2(0,0)}
self:setColors()
self.grabR = false
self.grabG = false
self.grabB = false
self.grabA = false
self.sizeUp = Button(WIDTH-100,HEIGHT-150,50,upArrow,function()
if lineSize < 16 then lineSize = lineSize + 1 end
end)
self.sizeDown = Button(WIDTH-100,HEIGHT-200,50,downArrow,function()
if lineSize > 1 then lineSize = lineSize - 1 end
end)
self.sizeDrag = vec2(WIDTH-125,HEIGHT-175)
self.sizeDragBool = false
self.rLeft = Button(self.x-40,self.y+150+25/2,40,"",function()
if self.r > 0 then self.r = self.r - 1 end; self:setColors() end)
self.rRight = Button(self.x+self.w+45,self.y+150+25/2,40,"",function()
if self.r < 255 then self.r = self.r + 1 end; self:setColors() end)
self.gLeft = Button(self.x-40,self.y+100+25/2,40,"",function()
if self.g > 0 then self.g = self.g - 1 end; self:setColors() end)
self.gRight = Button(self.x+self.w+45,self.y+100+25/2,40,"",function()
if self.g < 255 then self.g = self.g + 1 end; self:setColors() end)
self.bLeft = Button(self.x-40,self.y+50+25/2,40,"",function()
if self.b > 0 then self.b = self.b - 1 end; self:setColors() end)
self.bRight = Button(self.x+self.w+45,self.y+50+25/2,40,"",function()
if self.b < 255 then self.b = self.b + 1 end; self:setColors() end)
self.aLeft = Button(self.x-40,self.y+25/2,40,"",function()
if self.a > 0 then self.a = self.a - 255/100 end; self:setColors() end)
self.aRight = Button(self.x+self.w+45,self.y+25/2,40,"",function()
if self.a < 255 then self.a = self.a + 255/100 end; self:setColors() end)
self.buttons = {self.rLeft,self.rRight,self.gLeft,self.gRight,
self.bLeft,self.bRight,self.aLeft,self.aRight}
-- parameter.watch("1/DeltaTime")
end
function ColorPicker:draw()
if self.closing == false then
self.slidePos = self.slidePos * 0.7
else
self.slidePos = WIDTH - (WIDTH-self.slidePos) * 0.8
end
if self.slidePos < 1 then self.slidePos = 0 end
if self.slidePos > WIDTH-10 then self.slidePos = WIDTH; self.open = false end
pushMatrix()
translate(self.slidePos,0)
pushMatrix()
pushStyle()
if theme == "light" then
fill(255,240)
else
fill(70, 72, 86, 240)
end
rect(WIDTH/3,50,WIDTH*2/3+1,HEIGHT-100)
fill(lightGray)
stroke(lightGray)
translate(self.x,self.y)
rect(-50,0,self.w+100,175)
strokeWidth(50)
line(-50,0,self.w+50,0)
line(self.w+50,0,self.w+50,175)
line(self.w+50,175,-50,175)
line(-50,175,-50,0)
sprite(self.alphagrid,self.w/2,25/2,self.w,25)
self.alpha:draw()
sprite(self.left,25/4-1,25/2)
sprite(self.right,self.w-25/4+1,25/2)
strokeWidth(5)
stroke(darkGray)
-- fill(self.r,self.g,self.b,self.a)
noFill()
ellipse(self.a*self.w/255,25/2,40)
fill(blue)
text("A",-40,25/2)
text(math.ceil(self.a*100/255),self.w+45,25/2)
translate(0,50)
self.blue:draw()
sprite(self.left,25/4-1,25/2)
sprite(self.right,self.w-25/4+1,25/2)
strokeWidth(5)
stroke(darkGray)
fill(self.r,self.g,self.b)
ellipse(self.b*self.w/255,25/2,40)
fill(blue)
text("B",-40,25/2)
text(math.ceil(self.b),self.w+45,25/2)
translate(0,50)
self.green:draw()
sprite(self.left,25/4-1,25/2)
sprite(self.right,self.w-25/4+1,25/2)
fill(self.r,self.g,self.b)
ellipse(self.g*self.w/255,25/2,40)
fill(blue)
text("G",-40,25/2)
text(math.ceil(self.g),self.w+45,25/2)
translate(0,50)
self.red:draw()
sprite(self.left,25/4-1,25/2)
sprite(self.right,self.w-25/4+1,25/2)
fill(self.r,self.g,self.b)
ellipse(self.r*self.w/255,25/2,40)
fill(blue)
text("R",-40,25/2)
text(math.ceil(self.r),self.w+45,25/2)
popStyle()
pushStyle()
translate(0,150)
sprite(self.samplegrid,0,0,90)
fill(self.r,self.g,self.b,self.a)
stroke(lightGray)
strokeWidth(7)
rectMode(CENTER)
rect(0,0,100)
strokeWidth(10)
line(-50,-50,50,-50)
line(50,-50,50,50)
line(50,50,-50,50)
line(-50,50,-50,-50)
strokeWidth(30)
sprite(self.topleft,-40,40)
sprite(self.topright,40,40)
sprite(self.botleft,-40,-40)
sprite(self.botright,40,-40)
translate(150,0)
strokeWidth(6)
for i,s in pairs(self.saved) do
fill(s.r,s.g,s.b,s.a)
sprite(self.savedgrid,(5-i)%5*75,math.ceil(i/5)*75-112,30)
rect((5-i)%5*75,math.ceil(i/5)*75-112,35)
end
popStyle()
popMatrix()
self.sizeUp:draw()
self.sizeDown:draw()
pushStyle()
fill(blue)
fontSize(36)
noSmooth()
text(math.ceil(lineSize),WIDTH-150,HEIGHT-175)
popStyle()
if self.swatch == true and self.tch ~= vec2(0,0) then
fill(self.r,self.g,self.b,self.a)
stroke(lightGray)
pushMatrix()
translate(self.tch.x,self.tch.y)
ellipse(0,0,75)
popMatrix()
end
pushStyle()
textMode(CORNER)
fill(blue)
fontSize(25)
text("Tolerance "..self.tolerance.val-1,self.tolerance.x,self.tolerance.y+25)
self.tolerance:draw()
textMode(CENTER)
-- text("Blend",self.blend.x-75,self.blend.y)
self.blend:draw()
-- text("Fill Shapes",self.fillShape.x-95,self.fillShape.y)
self.fillShape:draw()
popStyle()
popMatrix()
for i,b in pairs(self.buttons) do b:draw() end
end
function ColorPicker:touched(touch)
for i,b in pairs(self.buttons) do b:touched(touch) end
-- self.rLeft:touched(touch)
-- self.rRight:touched(touch)
self.sizeUp:touched(touch)
self.sizeDown:touched(touch)
self.tolerance:touched(touch)
self.blend:touched(touch)
self.fillShape:touched(touch)
if touch.state ~= ENDED then
self.tch = vec2(touch.x,touch.y)
else
self.tch = vec2(0,0)
end
if touch.state == BEGAN then
if vec2(touch.x-self.x,touch.y-self.y-150):dist(vec2(self.r*self.w/255,0)) <= 25 then
self.grabR = true; self.grabG = false; self.grabB = false; self.grabA = false end
if vec2(touch.x-self.x,touch.y-self.y-100):dist(vec2(self.g*self.w/255,0)) <= 25 then
self.grabG = true; self.grabR = false; self.grabB = false; self.grabA = false end
if vec2(touch.x-self.x,touch.y-self.y-50):dist(vec2(self.b*self.w/255,0)) <= 25 then
self.grabB = true; self.grabR = false; self.grabG = false; self.grabA = false end
if vec2(touch.x-self.x,touch.y-self.y):dist(vec2(self.a*self.w/255,0)) <= 25 then
self.grabA = true; self.grabR = false; self.grabG = false; self.grabB = false end
if vec2(touch.x,touch.y):dist(vec2(self.x,self.y+300)) < 50 then
self.swatch = true
end
end
if self.grabR == true then self.r = (touch.x-self.x)*255/self.w end
if self.grabG == true then self.g = (touch.x-self.x)*255/self.w end
if self.grabB == true then self.b = (touch.x-self.x)*255/self.w end
if self.grabA == true then self.a = (touch.x-self.x)*255/self.w end
if self.r < 0 then self.r = 0 end
if self.g < 0 then self.g = 0 end
if self.b < 0 then self.b = 0 end
if self.a < 0 then self.a = 0 end
if self.r > 255 then self.r = 255 end
if self.g > 255 then self.g = 255 end
if self.b > 255 then self.b = 255 end
if self.a > 255 then self.a = 255 end
if touch.state == ENDED then
self.grabR = false
self.grabG = false
self.grabB = false
self.grabA = false
end
if self.grabR == true or self.grabG == true or self.grabB == true then
self:setColors()
end
if touch.state == ENDED and touch.tapCount > 0 then
for i,s in pairs(self.saved) do
local pos = vec2((5-i)%5*75+self.x+150,math.ceil(i/5)*75-112+self.y+300)
if vec2(touch.x,touch.y):dist(pos) < 20 then
self.r,self.g,self.b,self.a = s.r,s.g,s.b,s.a
self:setColors()
end
end
self.swatch = false
elseif touch.state == ENDED and self.swatch == true then
for i,s in pairs(self.saved) do
local pos = vec2((5-i)%5*75+self.x+150,math.ceil(i/5)*75-112+self.y+300)
if vec2(touch.x,touch.y):dist(pos) < 20 then
s.r,s.g,s.b,s.a = self.r,self.g,self.b,self.a
end
end
self.swatch = false
end
if touch.state == BEGAN and vec2(touch.x,touch.y):dist(self.sizeDrag) < 50 then
self.sizeDragBool = true
end
if touch.state ~= ENDED and self.sizeDragBool == true then
lineSize = lineSize + touch.deltaY/10
if lineSize < 1 then lineSize = 1 end
if lineSize > 16 then lineSize = 16 end
else
self.sizeDragBool = false
lineSize = math.ceil(lineSize)
end
end
function ColorPicker:setColors()
self.red.colors = {color(0,self.g,self.b),color(0,self.g,self.b),color(255,self.g,self.b),
color(255,self.g,self.b),color(255,self.g,self.b),color(0,self.g,self.b)}
self.green.colors = {color(self.r,0,self.b),color(self.r,0,self.b),color(self.r,255,self.b),
color(self.r,255,self.b),color(self.r,255,self.b),color(self.r,0,self.b)}
self.blue.colors = {color(self.r,self.g,0),color(self.r,self.g,0),color(self.r,self.g,255),
color(self.r,self.g,255),color(self.r,self.g,255),color(self.r,self.g,0)}
self.alpha.colors = {
color(self.r,self.g,self.b,0),color(self.r,self.g,self.b,0),color(self.r,self.g,self.b,255),
color(self.r,self.g,self.b,255),color(self.r,self.g,self.b,255),color(self.r,self.g,self.b,0)}
end
function ColorPicker:drawGraphics()
self.left = image(25/2,25)
self.right = image(25/2,25)
self.topleft = image(10,10)
self.topright = image(10,10)
self.botleft = image(10,10)
self.botright = image(10,10)
self.alphagrid = image(500,50)
self.samplegrid = image(100,100)
self.saved = {}
self.swatch = false
self.tch = vec2(0,0)
for i = 1,10 do self.saved[i] = {r=0,g=0,b=0,a=0} end
fill(lightGray)
setContext(self.left)
ellipse(25/2,25/2,-25)
setContext(self.right)
ellipse(0,25/2,-25)
setContext(self.topleft)
ellipse(10,0,-20)
setContext(self.topright)
ellipse(0,0,-20)
setContext(self.botleft)
ellipse(10,10,-20)
setContext(self.botright)
ellipse(0,10,-20)
setContext(self.alphagrid)
noSmooth()
for i = 1,20 do
for j = 1,2 do
if (i+j)%2 == 0 then fill(190, 190, 200, 255) else fill(120, 120, 130, 255) end
rect(i*25-25,j*25-25,25,25)
end
end
setContext(self.samplegrid)
for i = 1,4 do
for j = 1,4 do
if (i+j)%2 == 0 then fill(190, 190, 200, 255) else fill(120, 120, 130, 255) end
rect(i*25-25,j*25-25,25,25)
end
end
self.savedgrid = self.samplegrid:copy(1,1,50,50)
smooth()
setContext()
end
--# Animator
Animator = class()
function Animator:init(x)
self.open = false
self.closing = false
self.slidePos = HEIGHT
self:resize()
parameter.watch("animator.selected")
end
function Animator:resize()
self.tab = {image(editor.w,editor.h)}
self.selected = 1
self.w = WIDTH/12
self.h = self.tab[1].height*self.w/self.tab[1].width
self.scroll = 0
self.scrollMax = math.max(0,math.ceil(#self.tab/3)*(self.h+50)-300)
self.vel = 0
self.fps = Slider(25,440,WIDTH/3-50,2,1,10,false)
self.playBut = Button(60,HEIGHT-180,50,rightArrow,function()
self.play = true
end)
self.pauseBut = Button(60,HEIGHT-180,50,pause,function()
self.play = false
self.loop = self.selected
end)
self.left = Button(WIDTH/9,75,50,leftArrow,function()
if self.selected > 1 then self:shift(-1) end
end)
self.right = Button(WIDTH*2/9,75,50,rightArrow,function()
if self.selected < #self.tab then self:shift(1) end
end)
self.play = false
self.grid = image(self.tab[1].width,self.tab[1].height)
self.back = image(self.tab[1].width+20,self.tab[1].height+20)
setContext(self.grid)
strokeWidth(0)
pushStyle()
local m = mesh()
for i = 1,4 do
for j = 1,math.ceil(4*self.h/self.w) do
local s = self.grid.width/4
local g = m:addRect(i*s-s/2,j*s-s/2,s,s)
if (i+j)%2 == 0 then
m:setRectColor(g,190,190,200,255)
else
m:setRectColor(g,120,120,130,255)
end
end
end
m:draw()
setContext(self.back)
pushStyle()
strokeWidth(5)
if theme == "light" then stroke(121, 124, 133, 255) else stroke(lightGray) end
local lef = 10
local rig = 10 + self.tab[1].width
local bot = 10
local top = 10 + self.tab[1].height
line(lef,bot,rig,bot)
line(rig,bot,rig,top)
line(rig,top,lef,top)
line(lef,top,lef,bot)
popStyle()
self.loopGrid = image(math.min(200,200*editor.w/editor.h),math.min(200,200*editor.h/editor.w))
self.loopBack = image(math.min(200,200*editor.w/editor.h)+50,math.min(200,200*editor.h/editor.w)+50)
setContext(self.loopGrid)
for i = 1,8 do
for j = 1,8 do
local s = math.max(self.loopGrid.width,self.loopGrid.height)/8
local g = m:addRect(i*s-s/2,j*s-s/2,s,s)
if (i+j)%2 == 0 then
m:setRectColor(g,190,190,200,255)
else
m:setRectColor(g,120,120,130,255)
end
end
end
m:draw()
setContext(self.loopBack)
pushStyle()
strokeWidth(10)
if theme == "light" then stroke(121, 124, 133, 255) else stroke(lightGray) end
local lef = 25
local rig = 25 + math.min(200,200*editor.w/editor.h)
local bot = 25
local top = 25 + math.min(200,200*editor.h/editor.w)
line(lef,bot,rig,bot)
line(rig,bot,rig,top)
line(rig,top,lef,top)
line(lef,top,lef,bot)
popStyle()
setContext()
self.loop = 1
self.counter = 1
end
function Animator:draw()
if self.closing == false then
self.slidePos = self.slidePos * 0.8
else
self.slidePos = HEIGHT - (HEIGHT-self.slidePos) * 0.8
end
if self.slidePos < 1 then self.slidePos = 0 end
if self.slidePos > HEIGHT-100 then self.slidePos = HEIGHT; self.open = false end
pushMatrix()
translate(0,self.slidePos)
if self.loop > #self.tab then self.loop = 1 end
if self.play == true then
self.counter = self.counter + DeltaTime
while self.counter > 1/6/self.fps.val do
self.counter = self.counter - 1/6/self.fps.val
self.loop = self.loop + 1
if self.loop > #self.tab then self.loop = 1 end
end
--[[
if self.counter > 1/6/self.fps.val then
self.counter = self.counter - 1/6/self.fps.val
self.loop = self.loop + 1
if self.loop > #self.tab then self.loop = 1 end
end
]]
end
noSmooth()
sprite(self.loopBack,WIDTH/3-125,HEIGHT-175,math.min(200,200*editor.w/editor.h)+50)
sprite(self.loopGrid,WIDTH/3-125,HEIGHT-175,math.min(200,200*editor.w/editor.h))
-- sprite(self.tab[self.loop%#self.tab+1],WIDTH/3-125,HEIGHT-175,math.min(200,200*editor.w/editor.h))
if self.play == true then
sprite(self.tab[self.loop],WIDTH/3-125,HEIGHT-175,math.min(200,200*editor.w/editor.h))
else
sprite(self.tab[self.selected],WIDTH/3-125,HEIGHT-175,math.min(200,200*editor.w/editor.h))
end
fill(blue)
text(6*self.fps.val.." FPS",WIDTH/6,470)
self.fps:draw()
if self.swipe == true then
if self.scroll < 0 then
self.scroll = self.scroll - self.scroll/10 + 0.1
end
if self.scroll > self.scrollMax then
self.scroll = self.scroll - (self.scroll-self.scrollMax)/10 - 0.1
end
self.vel = self.vel - self.vel/10
self.scroll = self.scroll + self.vel
end
clip(0,100+self.slidePos,WIDTH/3,HEIGHT-450)
noStroke()
fill(lightGray)
pushMatrix()
translate(0,400-self.h/2+self.scroll)
for i,s in pairs(self.tab) do
local w = self.w
local h = self.h
local pos = vec2(((i+2)%3+1/2)*WIDTH/9,-(h+50)*(math.ceil(i/3)-1))
-- rect(pos.x-w/2,pos.y-h/2,w,h)
noSmooth()
-- sprite(self.back,pos.x,pos.y,WIDTH/12+50)
-- pushStyle()
-- smooth()
if theme == "light" then stroke(121, 124, 133, 255) else stroke(lightGray) end
strokeWidth(7)
translate(pos.x,pos.y)
line(w/2,h/2,w/2,-h/2)
line(w/2,-h/2,-w/2,-h/2)
line(-w/2,-h/2,-w/2,h/2)
line(-w/2,h/2,w/2,h/2)
translate(-pos.x,-pos.y)
-- noSmooth()
-- popStyle()
noSmooth()
sprite(self.grid,pos.x,pos.y,WIDTH/12)
sprite(self.tab[i],pos.x,pos.y,WIDTH/12)
if self.play == false and i == self.selected or self.play == true and i == self.loop then
pushStyle()
fill(120,120,130,210)
if theme == "light" then fill(120, 120, 130, 210) else fill(109, 114, 129, 210) end
rect(pos.x-w/2-5,pos.y-h/2-5,w+10,h+10)
popStyle()
end
popStyle()
end
popMatrix()
clip()
fill(blue)
if self.play == true then
text(self.loop.."/"..#self.tab,56,HEIGHT-80)
else
text(self.selected.."/"..#self.tab,56,HEIGHT-80)
end
if self.play == false then self.playBut:draw() else self.pauseBut:draw() end
self.left:draw()
self.right:draw()
popMatrix()
end
function Animator:touched(touch)
if self.fps.grab == false and self.playBut.pressed == false and self.pauseBut.pressed == false
and self.left.pressed == false and self.right.pressed == false then
if touch.state == ENDED and touch.tapCount > 0 and touch.deltaY == 0
and touch.y < 450 and touch.y > 50 then
for i,s in pairs(self.tab) do
local pos = vec2(((i+2)%3+1/2)*WIDTH/9,
400-self.h/2-(self.h+50)*(math.ceil(i/3)-1)+self.scroll-20)
local dist = vec2(touch.x,touch.y):dist(pos)
if dist < self.w and self.selected ~= i then
-- self.selected = i
self:update(self.selected,i,true)
end
end
elseif touch.state ~= ENDED then
self.swipe = false
if self.scroll < 0 then
self.scroll = self.scroll + touch.deltaY/(-math.min(self.scroll,-1)/7)^0.5
elseif self.scroll > self.scrollMax then
self.scroll = self.scroll + touch.deltaY/(self.scroll/7-self.scrollMax/7)^0.5
else
self.scroll = self.scroll + touch.deltaY
end
self.swipe = false
elseif touch.state == ENDED and math.abs(touch.deltaY) > 2 then
self.swipe = true
else
self.swipe = false
end
end
self.fps:touched(touch)
if touch.state == ENDED then self.swipe = true end
self.vel = self.temp or touch.deltaY
self.temp = touch.deltaY
if self.play == false then self.playBut:touched(touch) else self.pauseBut:touched(touch) end
self.left:touched(touch)
self.right:touched(touch)
end
function Animator:update(prev,new,reset)
self.tab[prev] = image(editor.w,editor.h)
setContext(self.tab[prev])
editor.mesh:draw()
setContext()
collectgarbage()
self.selected = new
for i = 1,editor.w do
for j = 1, editor.h do
local r,g,b,a = self.tab[new]:get(i,j)
if a < 1 then a = 1 end
local v = 255/a
-- self.mesh:setRectColor(self.meshTab[i][j],color(r,g,b,a))
editor.mesh:setRectColor(editor.meshTab[i][j],color(r*v,g*v,b*v,a))
end
end
if reset == true then
editor.undoId = 0
editor:updateImg()
editor.undoTab = {self.tab[new]}
collectgarbage()
end
end
function Animator:addSprite(cop)
if #self.tab < 100 then
if self.selected < #self.tab then
local temp = {}
for i = self.selected+1,#self.tab do
temp[i] = self.tab[i]
end
for i = self.selected+1,#self.tab do
self.tab[i+1] = temp[i]
end
end
self.selected = self.selected + 1
self.tab[self.selected] = image(editor.w,editor.h)
self.scrollMax = math.max(0,math.ceil(#self.tab/3)*(self.h+50)-300)
for i = 1,editor.w do
for j = 1, editor.h do
local r,g,b,a = self.tab[self.selected-1]:get(i,j)
if a < 1 then a = 1 end
local v = 255/a
-- self.mesh:setRectColor(self.meshTab[i][j],color(r,g,b,a))
if cop == true then
editor.mesh:setRectColor(editor.meshTab[i][j],color(r*v,g*v,b*v,a))
else
editor.mesh:setRectColor(editor.meshTab[i][j],color(0,0))
end
end
end
self:update(self.selected,self.selected,true)
end
end
function Animator:deleteSprite()
self.play = false
if #self.tab > 1 then
table.remove(self.tab,self.selected)
self.tab = {table.unpack(self.tab)}
collectgarbage()
self.scrollMax = math.max(0,math.ceil(#self.tab/3)*(self.h+50)-300)
if self.selected > #self.tab then self.selected = #self.tab end
for i = 1,editor.w do
for j = 1, editor.h do
local r,g,b,a = self.tab[self.selected]:get(i,j)
if a < 1 then a = 1 end
local v = 255/a
-- self.mesh:setRectColor(self.meshTab[i][j],color(r,g,b,a))
editor.mesh:setRectColor(editor.meshTab[i][j],color(r*v,g*v,b*v,a))
end
end
self:update(self.selected,self.selected,true)
else
self:update(self.selected,self.selected,true)
self.tab = {image(editor.w,editor.h)}
for i = 1,editor.w do
for j = 1,editor.h do
editor.mesh:setRectColor(editor.meshTab[i][j],color(0,0))
end
end
editor.undoTab = {image(editor.w,editor.h)}
end
end
function Animator:shift(s)
self.play = false
local temp = self.tab[self.selected]
self.tab[self.selected] = self.tab[self.selected+s]
self.tab[self.selected+s] = temp
self.selected = self.selected + s
end
--# Preview
function Editor:previewImg(x,y,d,s)
local m = self.preview
local t = self.prevTab
for i = 1,#t do
for j = 1,#t[i] do
m:setRectColor(t[i][j],color(0,0))
end
end
local c = color(colorpicker.r,colorpicker.g,colorpicker.b,colorpicker.a)
if tool == "Line" then
s.x = math.ceil(s.x)
s.y = math.ceil(s.y)
local slope = (y-s.y)/(x-s.x)
if s ~= vec2(0,0) then
if math.abs(x-s.x) > math.abs(y-s.y) then
local eq = function(i) j = slope*(i-x)+y return j end
for i = math.min(s.x,x),math.max(s.x,x) do
j = eq(i)
i = math.ceil(i)
j = math.ceil(j-1/2)
self:prevThicken(i,j,c)
end
elseif math.abs(x-s.x) < math.abs(y-s.y) then
local eq = function(j) i = (j-y)/slope+x return i end
for j = math.min(s.y,y),math.max(s.y,y) do
i = eq(j)
i = math.ceil(i-1/2)
j = math.ceil(j)
self:prevThicken(i,j,c)
end
elseif slope == -1 or slope == 1 then
local eq = function(i) j =
slope*(i-x)+y return j end
for i = math.min(x,s.x),math.max(x,s.x) do
j = eq(i)
i = math.ceil(i)
j = math.ceil(j)
self:prevThicken(i,j,c)
end
end
end
end
if tool == "Rectangle" then
local c = color(colorpicker.r,colorpicker.g,colorpicker.b,colorpicker.a)
if colorpicker.fillShape.val == true then
for i = math.min(x,s.x),math.max(x,s.x) do
for j = math.min(y,s.y),math.max(y,s.y) do
self:prevThicken(i,j,c)
end
end
else
for i = math.min(x,s.x),math.max(x,s.x) do
local bot = math.min(y,s.y)
local top = math.max(y,s.y)
self:prevThicken(i,bot,c)
self:prevThicken(i,top,c)
end
for j = math.min(y,s.y),math.max(y,s.y) do
local lef = math.min(x,s.x)
local rig = math.max(x,s.x)
self:prevThicken(lef,j,c)
self:prevThicken(rig,j,c)
end
end
end
if tool == "Circle" then
local c = color(colorpicker.r,colorpicker.g,colorpicker.b,colorpicker.a)
local img = image(math.abs(x-s.x)+1,math.abs(y-s.y)+1)
setContext(img)
sprite(self.circle,img.width/2,img.height/2,img.width,img.height)
setContext()
local X = math.min(x,s.x)
local Y = math.min(y,s.y)
for i = 1,math.ceil(img.width/2) do
for j = 1,math.ceil(img.height/2) do
if colorpicker.fillShape.val == false then
local r,g,b,la,ra,da,ua
if i > 1 then r,g,b,la = img:get(i-1,j) end
if i < img.width then r,g,b,ra = img:get(i+1,j) end
if j > 1 then r,g,b,da = img:get(i,j-1) end
if j < img.height then r,g,b,ua = img:get(i,j+1) end
la = la or 0
ra = ra or 0
da = da or 0
ua = ua or 0
local r,g,b,a = img:get(i,j)
if a == 255 and la ~= 255 or a == 255 and ra ~= 255
or a == 255 and da ~= 255 or a == 255 and ua ~= 255 then
local lef = math.min(x,s.x)+i-1
local rig = math.max(x,s.x)-i+1
local bot = math.min(y,s.y)+j-1
local top = math.max(y,s.y)-j+1
-- self.mesh:setRectColor(self.meshTab[lef][bot],c)
-- self.mesh:setRectColor(self.meshTab[rig][bot],c)
-- self.mesh:setRectColor(self.meshTab[lef][top],c)
-- self.mesh:setRectColor(self.meshTab[rig][top],c)
self:prevThicken(lef,bot,c)
self:prevThicken(rig,bot,c)
self:prevThicken(lef,top,c)
self:prevThicken(rig,top,c)
end
else
local r,g,b,a = img:get(i,j)
if a == 255 then
local lef = math.min(x,s.x)+i-1
local rig = math.max(x,s.x)-i+1
local bot = math.min(y,s.y)+j-1
local top = math.max(y,s.y)-j+1
self.preview:setRectColor(self.prevTab[lef][bot],c)
self.preview:setRectColor(self.prevTab[rig][bot],c)
self.preview:setRectColor(self.prevTab[lef][top],c)
self.preview:setRectColor(self.prevTab[rig][top],c)
if la ~= 255 or ra ~= 255 or da ~= 255 or ua ~= 255 then
self:prevThicken(lef,bot,c)
self:prevThicken(rig,bot,c)
self:prevThicken(lef,top,c)
self:prevThicken(rig,top,c)
end
end
end
end
end
end
if tool == "Select" then
for i = math.min(x,s.x),math.max(x,s.x) do
local bot = math.min(y,s.y)
local top = math.max(y,s.y)
local c
local r,g,b,a = self.undoTab[self.undoId]:get(i,bot)
local val = (r+g+b)/3
if (i+bot)%3 == 1 then c = color(255,0)
elseif val > 127 or a < 127 then c = color(0,255) else c = color(255,255) end
self:prevThicken(i,bot,c)
local r,g,b,a = self.undoTab[self.undoId]:get(i,top)
local val = (r+g+b)/3
if (i+top)%3 == 1 then c = color(255,0)
elseif val > 127 or a < 127 then c = color(0,255) else c = color(255,255) end
self:prevThicken(i,top,c)
end
for j = math.min(y,s.y),math.max(y,s.y) do
local lef = math.min(x,s.x)
local rig = math.max(x,s.x)
local c
local r,g,b,a = self.undoTab[self.undoId]:get(lef,j)
local val = (r+g+b)/3
if (j+lef)%3 == 1 then c = color(255,0)
elseif val > 127 or a < 127 then c = color(0,255) else c = color(255,255) end
self:prevThicken(lef,j,c)
local r,g,b,a = self.undoTab[self.undoId]:get(rig,j)
local val = (r+g+b)/3
if (j+rig)%3 == 1 then c = color(255,0)
elseif val > 127 or a < 127 then c = color(0,255) else c = color(255,255) end
self:prevThicken(rig,j,c)
end
end
end
function Editor:prevThicken(x,y,c)
local m = self.preview
local t = self.prevTab
--[[
for i = 1,lineSize do
for j = 1,lineSize do
local r,g,b,a = self.pens[lineSize]:get(i,j)
if a > 0 then
local X = math.ceil(x+i-lineSize/2-1)
local Y = math.ceil(y+j-lineSize/2-1)
if X > 0 and X <= self.w and Y > 0 and Y <= self.h then
m:setRectColor(t[X][Y],c)
end
end
end
end
]]
-- x = math.ceil(x)
-- y = math.ceil(y)
m:setRectColor(t[x][y],c)
end
function Editor:selectPreview(x,y,s)
local v = math.ceil(ElapsedTime*2)%3
--[[
for i = math.min(x,s.x),math.max(x,s.x) do
local bot = math.min(y,s.y)
local top = math.max(y,s.y)
local c
if (i+bot)%3 == v then c = color(255,0) else c = color(0,255) end
self:prevThicken(i,bot,c)
if (i+top)%3 == v then c = color(255,0) else c = color(0,255) end
self:prevThicken(i,top,c)
end
for j = math.min(y,s.y),math.max(y,s.y) do
local lef = math.min(x,s.x)
local rig = math.max(x,s.x)
local c
if (j+lef)%3 == v then c = color(255,0) else c = color(0,255) end
self:prevThicken(lef,j,c)
if (j+rig)%3 == v then c = color(255,0) else c = color(0,255) end
self:prevThicken(rig,j,c)
end
]]
for i = math.min(x,s.x),math.max(x,s.x) do
local bot = math.min(y,s.y)
local top = math.max(y,s.y)
local c
local r,g,b,a = self.undoTab[self.undoId]:get(i,bot)
local val = (r+g+b)/3
if (i+bot)%3 == v then c = color(255,0)
elseif val > 127 or a < 127 then c = color(0,255) else c = color(255,255) end
self:prevThicken(i,bot,c)
local r,g,b,a = self.undoTab[self.undoId]:get(i,top)
local val = (r+g+b)/3
if (i+top)%3 == v then c = color(255,0)
elseif val > 127 or a < 127 then c = color(0,255) else c = color(255,255) end
self:prevThicken(i,top,c)
end
for j = math.min(y,s.y),math.max(y,s.y) do
local lef = math.min(x,s.x)
local rig = math.max(x,s.x)
local c
local r,g,b,a = self.undoTab[self.undoId]:get(lef,j)
local val = (r+g+b)/3
if (j+lef)%3 == v then c = color(255,0)
elseif val > 127 or a < 127 then c = color(0,255) else c = color(255,255) end
self:prevThicken(lef,j,c)
local r,g,b,a = self.undoTab[self.undoId]:get(rig,j)
local val = (r+g+b)/3
if (j+rig)%3 == v then c = color(255,0)
elseif val > 127 or a < 127 then c = color(0,255) else c = color(255,255) end
self:prevThicken(rig,j,c)
end
end
--# Draw
function Editor:smoothLines(x,y,d)
local c = color(colorpicker.r,colorpicker.g,colorpicker.b,colorpicker.a)
local m = self.mesh
local t = self.meshTab
d.x = math.ceil(d.x)
d.y = math.ceil(d.y)
local slope = (y-d.y)/(x-d.x)
if d ~= vec2(0,0) then
if math.abs(x-d.x) > math.abs(y-d.y) then
local eq = function(i) j = slope*(i-x)+y return j end
for i = math.min(d.x,x),math.max(d.x,x) do
j = eq(i)
i = math.ceil(i)
j = math.ceil(j-1/2)
self:thickenLines(i,j,c)
end
elseif math.abs(x-d.x) < math.abs(y-d.y) then
local eq = function(j) i = (j-y)/slope+x return i end
for j = math.min(d.y,y),math.max(d.y,y) do
i = eq(j)
i = math.ceil(i-1/2)
j = math.ceil(j)
self:thickenLines(i,j,c)
end
elseif slope == -1 or slope == 1 then
local eq = function(i) j =
slope*(i-x)+y return j end
for i = math.min(x,d.x),math.max(x,d.x) do
j = eq(i)
i = math.ceil(i)
j = math.ceil(j)
self:thickenLines(i,j,c)
end
elseif vec2(x,y) == d then
self:thickenLines(x,y,c)
end
end
end
function Editor:thickenLines(x,y,c,img)
local m = self.mesh
local t = self.meshTab
local p = colorpicker
for i = 1,lineSize do
for j = 1,lineSize do
local r,g,b,a = self.pens[lineSize]:get(i,j)
if a > 0 then
local X = math.ceil(x+i-lineSize/2-1)
local Y = math.ceil(y+j-lineSize/2-1)
if X > 0 and X <= self.w and Y > 0 and Y <= self.h then
local colr
if tool == "Erase" then
colr = color(0,0)
elseif colorpicker.blend.val == true then
-- self.undoTab[self.undoId].premultiplied = true
local R,G,B,A = self.undoTab[self.undoId]:get(X,Y)
-- colr = c:mix(color(R+colorpicker.r,G+colorpicker.g,
-- B+colorpicker.b,A+colorpicker.a),0.5)
--[[
self.im:set(1,1,color(0,0))
setContext(self.im)
fill(c)
rect(0,0,1,1)
fill(R,G,B,A)
rect(0,0,1,1)
setContext()
local r,g,b,a = self.im:get(1,1)
colr = color(r,g,b,a)
]]
local cp = colorpicker
local a
if cp.a == 0 then a = 1 else a = cp.a end
local v = 255/a
colr = color(cp.r*v,cp.g*v,cp.b*v,a):blend(color(R,G,B,A/3))
else
colr = c
end
m:setRectColor(t[X][Y],colr)
end
end
end
end
end
function Editor:drawRect(x,y,s)
local c = color(colorpicker.r,colorpicker.g,colorpicker.b,colorpicker.a)
if colorpicker.fillShape.val == true then
for i = math.min(x,s.x),math.max(x,s.x) do
for j = math.min(y,s.y),math.max(y,s.y) do
self:thickenLines(i,j,c)
end
end
else
for i = math.min(x,s.x),math.max(x,s.x) do
local bot = math.min(y,s.y)
local top = math.max(y,s.y)
self:thickenLines(i,bot,c)
self:thickenLines(i,top,c)
end
for j = math.min(y,s.y),math.max(y,s.y) do
local lef = math.min(x,s.x)
local rig = math.max(x,s.x)
self:thickenLines(lef,j,c)
self:thickenLines(rig,j,c)
end
end
end
function Editor:drawEllipse(x,y,d,s)
local c = color(colorpicker.r,colorpicker.g,colorpicker.b,colorpicker.a)
local img = image(math.abs(x-s.x)+1,math.abs(y-s.y)+1)
setContext(img)
sprite(self.circle,img.width/2,img.height/2,img.width,img.height)
setContext()
local X = math.min(x,s.x)
local Y = math.min(y,s.y)
for i = 1,math.ceil(img.width/2) do
for j = 1,math.ceil(img.height/2) do
if colorpicker.fillShape.val == false then
local r,g,b,la,ra,da,ua
if i > 1 then r,g,b,la = img:get(i-1,j) end
if i < img.width then r,g,b,ra = img:get(i+1,j) end
if j > 1 then r,g,b,da = img:get(i,j-1) end
if j < img.height then r,g,b,ua = img:get(i,j+1) end
la = la or 0
ra = ra or 0
da = da or 0
ua = ua or 0
local r,g,b,a = img:get(i,j)
if a == 255 and la ~= 255 or a == 255 and ra ~= 255
or a == 255 and da ~= 255 or a == 255 and ua ~= 255 then
local lef = math.min(x,s.x)+i-1
local rig = math.max(x,s.x)-i+1
local bot = math.min(y,s.y)+j-1
local top = math.max(y,s.y)-j+1
-- self.mesh:setRectColor(self.meshTab[lef][bot],c)
-- self.mesh:setRectColor(self.meshTab[rig][bot],c)
-- self.mesh:setRectColor(self.meshTab[lef][top],c)
-- self.mesh:setRectColor(self.meshTab[rig][top],c)
self:thickenLines(lef,bot,c)
self:thickenLines(rig,bot,c)
self:thickenLines(lef,top,c)
self:thickenLines(rig,top,c)
end
else
local r,g,b,a = img:get(i,j)
if a == 255 then
local lef = math.min(x,s.x)+i-1
local rig = math.max(x,s.x)-i+1
local bot = math.min(y,s.y)+j-1
local top = math.max(y,s.y)-j+1
self.mesh:setRectColor(self.meshTab[lef][bot],c)
self.mesh:setRectColor(self.meshTab[rig][bot],c)
self.mesh:setRectColor(self.meshTab[lef][top],c)
self.mesh:setRectColor(self.meshTab[rig][top],c)
if la ~= 255 or ra ~= 255 or da ~= 255 or ua ~= 255 then
self:thickenLines(lef,bot,c)
self:thickenLines(rig,bot,c)
self:thickenLines(lef,top,c)
self:thickenLines(rig,top,c)
end
end
end
end
end
end
function Editor:paint(x,y)
local c = color(colorpicker.r,colorpicker.g,colorpicker.b,colorpicker.a)
local t = colorpicker.tolerance.val+0
self.paintImg = image(self.w,self.h)
setContext(self.paintImg)
self.mesh:draw()
setContext()
self.checkImg = image(self.w,self.h)
local R,G,B,A = self.paintImg:get(x,y)
if color(R,G,B,A) ~= c then
self:checkPixel(x,y,t,c,R,G,B,A)
end
for i = 1,self.w do
for j = 1,self.h do
-- self.paintImg.premultiplied = false
local r,g,b,a = self.paintImg:get(i,j)
local rr,gg,bb,aa = self.checkImg:get(i,j)
local v = 255/a
if aa == 255 then
self.mesh:setRectColor(self.meshTab[i][j],color(r,g,b,a))
else
self.mesh:setRectColor(self.meshTab[i][j],color(r*v,g*v,b*v,a))
end
end
end
collectgarbage()
end
function Editor:checkPixel(x,y,t,c,R,G,B,A,d)
d = d or nil
local r,g,b,a = self.paintImg:get(x,y)
if math.abs(R-r) <= t and math.abs(G-g) <= t and math.abs(B-b) <= t and math.abs(A-a) <= t then
self.mesh:setRectColor(self.meshTab[x][y],c)
self.paintImg:set(x,y,c)
local rr,gg,bb,aa = self.checkImg:get(x,y)
if aa ~= 255 then
self.checkImg:set(x,y,color(0,255))
if x > 1 and d ~= "left" then
self:checkPixel(x-1,y,t,c,R,G,B,A,"right") end
if y > 1 and d ~= "down" then
self:checkPixel(x,y-1,t,c,R,G,B,A,"up") end
if x < self.paintImg.width and d ~= "right" then
self:checkPixel(x+1,y,t,c,R,G,B,A,"left") end
if y < self.paintImg.height and d ~= "up" then
self:checkPixel(x,y+1,t,c,R,G,B,A,"down") end
end
end
end
function Editor:fill(x,y)
local c = color(colorpicker.r,colorpicker.g,colorpicker.b,colorpicker.a)
local v = colorpicker.tolerance.val+0
self.fillImg = image(self.w,self.h)
setContext(self.fillImg)
self.mesh:draw()
setContext()
local R,G,B,A = self.fillImg:get(x,y)
for i = 1,self.fillImg.width do
for j = 1,self.fillImg.height do
local r,g,b,a = self.fillImg:get(i,j)
if math.abs(R-r) <= v and math.abs(G-g) <= v and math.abs(B-b) <= v and math.abs(A-a) <= v then
self.mesh:setRectColor(self.meshTab[i][j],c)
end
end
end
end
--# Undo
function Editor:updateImg()
self.undoId = self.undoId + 1
local img = image(self.w,self.h)
setContext(img)
img.premultiplied = false
self.mesh:draw()
setContext()
self.undoTab[self.undoId] = img
local r,g,b,a = img:get(1,1)
if self.undoId > self.undoMax then
self.undoId = self.undoMax
for i = 1,self.undoMax do
self.undoTab[i] = self.undoTab[i+1]
end
self.undoTab[self.undoMax+1] = nil
collectgarbage()
end
if self.undoId < self.undoMax then
for i = self.undoId+1,self.undoMax do
self.undoTab[i] = nil
end
end
collectgarbage()
end
function Editor:undo()
self.undoId = self.undoId - 1
if self.undoId < 1 then self.undoId = 1 end
if self.undoTab[self.undoId] then
-- self.undoTab[self.undoId].premultiplied = true
for i = 1,self.w do
for j = 1, self.h do
local r,g,b,a = self.undoTab[self.undoId]:get(i,j)
if a < 1 then a = 1 end
local v = 255/a
-- self.mesh:setRectColor(self.meshTab[i][j],color(r,g,b,a))
self.mesh:setRectColor(self.meshTab[i][j],color(r*v,g*v,b*v,a))
end
end
end
--[[
local img = image(self.w,self.h)
setContext(img)
self.mesh:draw()
setContext()
self.undoTab[self.undoId] = img
]]
end
function Editor:redo()
if self.undoId < #self.undoTab then
self.undoId = self.undoId + 1
end
if self.undoId <= #self.undoTab then
-- self.undoTab[self.undoId].premultiplied = true
for i = 1,self.w do
for j = 1, self.h do
local r,g,b,a = self.undoTab[self.undoId]:get(i,j)
if a < 1 then a = 1 end
local v = 255/a
-- self.mesh:setRectColor(self.meshTab[i][j],color(r,g,b,a))
self.mesh:setRectColor(self.meshTab[i][j],color(r*v,g*v,b*v,a))
end
end
end
--[[
local img = image(self.w,self.h)
setContext(img)
self.mesh:draw()
setContext()
self.undoTab[self.undoId] = img
]]
end
--# Pens
function drawPens()
pens = {}
pens[1] = {
"x"
}
pens[2] = {
"xx",
"xx"
}
pens[3] = {
" x ",
"xxx",
" x "
}
pens[4] = {
" xx ",
"xxxx",
"xxxx",
" xx "
}
pens[5] = {
" xxx ",
"xxxxx",
"xxxxx",
"xxxxx",
" xxx "
}
pens[6] = {
" xxxx ",
"xxxxxx",
"xxxxxx",
"xxxxxx",
"xxxxxx",
" xxxx "
}
pens[7] = {
" xxx ",
" xxxxx ",
"xxxxxxx",
"xxxxxxx",
"xxxxxxx",
" xxxxx ",
" xxx "
}
pens[8] = {
" xxxx ",
" xxxxxx ",
"xxxxxxxx",
"xxxxxxxx",
"xxxxxxxx",
"xxxxxxxx",
" xxxxxx ",
" xxxx "
}
pens[9] = {
" xxx ",
" xxxxxxx ",
" xxxxxxx ",
"xxxxxxxxx",
"xxxxxxxxx",
"xxxxxxxxx",
" xxxxxxx ",
" xxxxxxx ",
" xxx "
}
pens[10] = {
" xxxx ",
" xxxxxxxx ",
" xxxxxxxx ",
"xxxxxxxxxx",
"xxxxxxxxxx",
"xxxxxxxxxx",
"xxxxxxxxxx",
" xxxxxxxx ",
" xxxxxxxx ",
" xxxx "
}
pens[11] = {
" xxxxx ",
" xxxxxxx ",
" xxxxxxxxx ",
"xxxxxxxxxxx",
"xxxxxxxxxxx",
"xxxxxxxxxxx",
"xxxxxxxxxxx",
"xxxxxxxxxxx",
" xxxxxxxxx ",
" xxxxxxx ",
" xxxxx "
}
pens[12] = {
" xxxx ",
" xxxxxxxx ",
" xxxxxxxxxx ",
" xxxxxxxxxx ",
"xxxxxxxxxxxx",
"xxxxxxxxxxxx",
"xxxxxxxxxxxx",
"xxxxxxxxxxxx",
" xxxxxxxxxx ",
" xxxxxxxxxx ",
" xxxxxxxx ",
" xxxx "
}
pens[13] = {
" xxxxx ",
" xxxxxxxxx ",
" xxxxxxxxxxx ",
" xxxxxxxxxxx ",
"xxxxxxxxxxxxx",
"xxxxxxxxxxxxx",
"xxxxxxxxxxxxx",
"xxxxxxxxxxxxx",
"xxxxxxxxxxxxx",
" xxxxxxxxxxx ",
" xxxxxxxxxxx ",
" xxxxxxxxx ",
" xxxxx "
}
pens[14] = {
" xxxx ",
" xxxxxxxx ",
" xxxxxxxxxx ",
" xxxxxxxxxxxx ",
" xxxxxxxxxxxx ",
"xxxxxxxxxxxxxx",
"xxxxxxxxxxxxxx",
"xxxxxxxxxxxxxx",
"xxxxxxxxxxxxxx",
" xxxxxxxxxxxx ",
" xxxxxxxxxxxx ",
" xxxxxxxxxx ",
" xxxxxxxx ",
" xxxx "
}
pens[15] = {
" xxxxx ",
" xxxxxxxxx ",
" xxxxxxxxxxx ",
" xxxxxxxxxxxxx ",
" xxxxxxxxxxxxx ",
"xxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxx",
" xxxxxxxxxxxxx ",
" xxxxxxxxxxxxx ",
" xxxxxxxxxxx ",
" xxxxxxxxx ",
" xxxxx "
}
pens[16] = {
" xxxxxx ",
" xxxxxxxxxx ",
" xxxxxxxxxxxx ",
" xxxxxxxxxxxxxx ",
" xxxxxxxxxxxxxx ",
"xxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxx",
" xxxxxxxxxxxxxx ",
" xxxxxxxxxxxxxx ",
" xxxxxxxxxxxx ",
" xxxxxxxxxx ",
" xxxxxx "
}
editor.pens = {}
for p = 1,#pens do
editor.pens[p] = image(p,p)
for i = 1,p do
for j = 1,p do
local pixel = string.sub(pens[p][i],j,j)
if pixel == "x" then
editor.pens[p]:set(i,j,color(0,255))
end
end
end
end
end
--# Icons
function iconDraw()
icons = {}
icons.free = {
" ",
" xx",
" x xxx",
" x xx ",
" x xxx ",
" x xx ",
"x xxx ",
"x xx ",
" x x ",
" xxx "
}
icons.line = {
" x",
" x ",
" x ",
" x ",
" x ",
" x ",
" x ",
" x ",
" x ",
"x "
}
icons.rect = {
"xxxxxxxxxx",
"x x",
"x x",
"x x",
"x x",
"x x",
"x x",
"x x",
"x x",
"xxxxxxxxxx"
}
icons.circle = {
" xxxx ",
" xx xx ",
" x x ",
"x x",
"x x",
"x x",
"x x",
" x x ",
" xx xx ",
" xxxx "
}
icons.paint = {
" xxxx ",
" xx x ",
"x xxx ",
"x xxxxxx ",
"x xxxxxx ",
" xxxxxxxx ",
" xxxxxxx",
" xxxxxxx",
" xxxxxx",
" xxx "
}
icons.fill = {
" ",
"xxxx ",
"xxxx x ",
"xxxx xx ",
"xxxxxxxxx ",
"xxxxxxxxxx",
"xxxxxxxxx ",
"xxxx xx ",
"xxxx x ",
"xxxx "
}
icons.erase = {
" xx ",
" x xxx ",
" x x",
" x x",
" x x ",
" x x ",
"x xxx x ",
"x xxx ",
" xxx x ",
" xx "
}
icons.select = {
"xx xx xx x",
" x",
"x ",
"x x",
" x",
"x ",
"x x",
" x",
"x ",
"x xx xx xx"
}
icons.cut = {
" xxx ",
" x x ",
" xxx ",
" x ",
"xxx x ",
"x xxxxxx ",
"xxx x xx",
" x ",
" x ",
" x "
}
icons.copy = {
" xxxxxxxx",
" x",
"xxxxxxxx x",
"x x x",
"x x x",
"x x x",
"x x x",
"x x x",
"x x ",
"xxxxxxxx "
}
icons.paste = {
" xx ",
" xxxxxxx",
" x",
" xxxxxxx x",
" x x x",
" x x x",
" x x x",
" x x x",
" x x ",
" xxxxxxx "
}
icons.hor = {
"xxxxxxxxxx",
"x x",
"x x",
"x x",
"x x",
"xxxxxxxxxx",
"xxxxxxxxxx",
"xxxxxxxxxx",
"xxxxxxxxxx",
"xxxxxxxxxx"
}
icons.vert = {
"xxxxxxxxxx",
"xxxxx x",
"xxxxx x",
"xxxxx x",
"xxxxx x",
"xxxxx x",
"xxxxx x",
"xxxxx x",
"xxxxx x",
"xxxxxxxxxx"
}
icons.trans = {
" x ",
" xxx ",
" x x x ",
" x ",
" x ",
" x x ",
" x x ",
"xxxxxxxxxx",
" x x ",
" x x "
}
icons.size = {
"xxx xxx",
"x x",
"x xxxxxx x",
" x x ",
" x x ",
" x x ",
" x x ",
"x xxxxxx x",
"x x",
"xxx xxx"
}
icons.rotate = {
" xxxx",
" xx ",
" x x x ",
"x x x",
"x x",
"x x",
"x x",
" x x ",
" x x ",
" xxxx "
}
icons.dropbox = {
" x x ",
" xxxx xxxx ",
" xxxxxxx xxxxxxx ",
" xxxxxxxxxxxxxxxxxx ",
" xxxxxxxx xxxxxxxx ",
" xxxxx xxxxx ",
" xx xx ",
" x x ",
" xxxx xxxx ",
" xxxxxxx xxxxxxx ",
" xxxxxxxxxxxxxxxxxx ",
" xxxxxxxx xxxxxxxx ",
" xxxxx xx xxxxx ",
" xx xxxx xx ",
" x xxxxxx x ",
" xxxxxxxxxxxx ",
" xxxxxxxxxxxx ",
" xxxxxxxxxx ",
" xxxxxx ",
" xx "
}
icons.dropbox = {
" x x ",
" xx x x xx ",
" xx x x xx ",
" x xx x ",
" x xx xx x ",
" x xx xx x ",
" xx xx ",
" x x ",
" x xx xx x ",
" x xx xx x ",
" x xx x ",
" xx x x xx ",
" xx x x xx ",
" xx xx ",
" x x ",
" x x ",
" x x ",
" xx xx ",
" xx xx ",
" xx "
}
icons.folder = {
" ",
" ",
" ",
" xxxxxxxx ",
"xxxxxxxxxx ",
"xxxxxxxxxxxxxxxxxx ",
"xxxxxxxx ",
" xxxxxxxxxx",
"xxxxxxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxxxxxx",
"xxxxxxxxxxxxxxxxxxxx",
" xxxxxxxxxxxxxxxxxx ",
" ",
" "
}
icons.folder = {
" ",
" ",
" ",
" xxxxxxxx ",
"x x ",
"x xxxxxxxxx ",
"x ",
" xxxxxxxxxx",
"xxxxxxxxxx x",
"x x",
"x x",
"x x",
"x x",
"x x",
"x x",
"x x",
"x x",
" xxxxxxxxxxxxxxxxxx ",
" ",
" "
}
icons.blank = {
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "
}
for u,v in pairs(icons) do
print(u,v)
local img = image(#v[1],#v[1])
for i = 1,img.width do
for j = 1,img.height do
-- print(icons[u][5])
local pixel = string.sub(icons[u][#v[1]+1-j],i,i)
if pixel == "x" then
img:set(i,j,blue)
end
end
end
icons[u] = img
end
collectgarbage()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.