While I was working on a project of mine, I needed to create a simple transparent arrow image. So I went to a drawing app, created and saved the image to the camera roll, went back to Codea, and loaded it into the Documents folder for use in my project. I created this program to help myself avoid this long process, and I thought I’d share it.
Tips:
• Draw the image as big as possible (unless you are creating a background).
• Change the displayMode
if you want.
• Use an actual drawing app for more complex drawing.
Code:
--# Main
-- Simple Sprite Creator
displayMode(STANDARD)
function setup()
saveProjectInfo("Description", "A simple sprite/image editor by Saturn031000.")
lines={}
witBG=image(WIDTH, HEIGHT)
woBG=image(WIDTH, HEIGHT)
parameter.color("background_color", 0)
parameter.color("pen_color", 255)
parameter.number("pen_size", 1, 20, 4)
parameter.action("CLEAR ALL", function() lines={} witBG=nil woBG=nil witBG=image(WIDTH, HEIGHT) woBG=image(WIDTH, HEIGHT) sound(SOUND_EXPLODE, 40024) end)
parameter.text("image_name", "img")
parameter.action("SAVE WITH BACKGROUND", function() saveImage("Documents:"..image_name, witBG) print("SAVED TO DOCUMENTS FOLDER") sound(SOUND_POWERUP, 35583) parameter.clear() end)
parameter.action("SAVE WITHOUT BACKGROUND", function() saveImage("Documents:"..image_name, woBG) print("SAVED TO DOCUMENTS FOLDER") sound(SOUND_POWERUP, 35583) parameter.clear() end)
end
function draw()
setContext(witBG)
background(background_color)
for a,b in pairs(lines) do
b:draw()
end
setContext()
background(background_color)
setContext(woBG)
for a,b in pairs(lines) do
b:draw()
end
setContext()
sprite(woBG, WIDTH/2, HEIGHT/2)
end
function touched(t)
table.insert(lines, ligne(t.prevX, t.prevY, t.x, t.y, pen_color, pen_size))
end
--# ligne
ligne = class()
function ligne:init(xo, yo, xt, yt, lColor, thickness)
self.xo = xo
self.yo = yo
self.xt = xt
self.yt = yt
self.lColor = lColor
self.thickness = thickness
end
function ligne:draw()
strokeWidth(self.thickness)
stroke(self.lColor)
line(self.xo, self.yo, self.xt, self.yt)
end