Here’s a simple sprite editor. Start with an existing sprite or create a new one. The sliders allow you to do different things.
To resize, set the slider and move your finger up or down the screen.
To move, set the slider and move your finger around the screen.
To getColor, set the slider and tap on a sprite position.
To setColor, set the slider and tap a sprite position.
To create a new color, tap the color circle and select a new color.
To view with or without lines, set the lines slider.
To save the sprite, tap the save Image parameter.
It’s really simple, so don’t expect a lot.
viewer.mode=STANDARD
function setup()
img=readImage(asset.builtin.Cargo_Bot.Clear_Button) -- existing sprite
--img=image(50,50) -- new sprite
w1,h1=img.width,img.height
shiftX,shiftY,size=0,0,1
noSmooth()
rectMode(CENTER)
parameter.boolean("resize",false, function() move=false end)
parameter.boolean("move",false, function() resize=false end)
parameter.boolean("getColor",false, function() resize=false move=false end)
parameter.boolean("setColor",false, function() resize=false move=false end)
parameter.color("colr",color(255))
parameter.boolean("lines",true)
parameter.action("save Image",saveImg)
imageToTable()
end
function draw()
background(200)
changeSize()
if lines and size>8 then
stroke(45, 66, 81)
strokeWidth(1)
else
noStroke()
end
for x=1,w1 do
for y=1,h1 do
fill(tab[x][y])
rect(x*size+cenX+shiftX*size,y*size+cenY+shiftY*size,size)
end
end
if lines then
stroke(255)
strokeWidth(2)
line(cenX+shiftX*size+size/2,cenY+shiftY*size+size/2,
cenX+shiftX*size+size/2,cenY+shiftY*size+h1*size+size/2)
line(cenX+shiftX*size+w1*size+size/2,cenY+shiftY*size+size/2,
cenX+shiftX*size+w1*size+size/2,cenY+shiftY*size+h1*size+size/2)
line(cenX+shiftX*size+size/2,cenY+shiftY*size+size/2,
cenX+shiftX*size+w1*size+size/2,cenY+shiftY*size+size/2)
line(cenX+shiftX*size+size/2,cenY+shiftY*size+h1*size+size/2,
cenX+shiftX*size+w1*size+size/2,cenY+shiftY*size+h1*size+size/2)
end
end
function imageToTable()
tab={}
for x=1,w1 do
tab[x]={}
for y=1,h1 do
r,g,b,a=img:get(x,y)
tab[x][y]=color(r,g,b,a)
end
end
end
function changeSize()
cenX=(WIDTH-w1*size)//2
cenY=(HEIGHT-h1*size)//2
end
function touched(t)
if t.state==BEGAN or t.state==CHANGED then
tx=(t.x-cenX-shiftX*size+size//2)//size
ty=(t.y-cenY-shiftY*size+size//2)//size
if resize then
size=math.max(1,size+t.deltaY/25)
elseif move then
shiftX=shiftX+t.deltaX/(size)
shiftY=shiftY+t.deltaY/(size)
elseif getColor then
colr=tab[tx][ty]
getColor=false
elseif setColor then
if tx>0 and tx<=w1 and ty>0 and ty<=h1 then
tab[tx][ty]=colr
end
end
end
end
function saveImg()
for x=1,w1 do
for y=1,h1 do
c=tab[x][y]
img:set(x,y,c.r,c.g,c.b,c.a)
end
end
saveImage(asset.documents.Dropbox.."newSprite",img)
end