Paint strokes on a canvas?

Would Corona be the right framework if I wanted to let the user draw some black and white sketches using the finger, and if so, how would that be done? It would be part of something larger, not a specialized drawing app, but I would need some way to get simple smooth sketches going…

Thanks for any help! [import]uid: 10284 topic_id: 4472 reply_id: 304472[/import]

on a touch/move event create a circle … make sure to destroy so that you don’t start to eat memory…

really really rough code to get you going and I mean very crude way to see if this is what you mean. I don’t know if it is going to work or not as I didn’t test… this was off my brain…

[code]

local function drawDrag(event)

local phase = event.phase
if “began” == phase then
– Make target the top-most object

local cc = display.newCircle ( event.x, event.y, 4);
cc:setFillColor(255,0,0);

elseif “moved” == phase then
– Make object move (we subtract t.x0,t.y0 so that moves are
– relative to initial grab point, rather than object “snapping”).
local cc = display.newCircle ( event.x, event.y, 4);
cc:setFillColor(255,0,0);

elseif “ended” == phase or “cancelled” == phase then
moved = FALSE;
end

return true

end

Runtime:addEventListener(“touch”,drawDrag);
[/code] [import]uid: 24 topic_id: 4472 reply_id: 14029[/import]

won’t this start to slow down the more circles are drawn? Corona isn’t capable of “stamping” the images to static bitmap is it? i’m guessing each circle is an individual unit? is “cacheAsBitmap” a feature we can expect? (although not always what you want if you need “undo” functionality)

i dont really know how Corona/OpenGL drawing works at the moment. how many circles is a feasible number to be able to draw with the method above, without seeing device slowdown/memory issues?

thanks
j [import]uid: 6645 topic_id: 4472 reply_id: 14049[/import]

that was off the cuff sample pseudo code that i don’t know if it works right off the bat.

hopefully, that gives you a start and you can go from there. ie: setting the brush width, stroke, fill color, etc.

there is also a display.save() command that you can use to ‘cache’ as bitmap? but then again… we are highly optimized for open gl…

c.

[import]uid: 24 topic_id: 4472 reply_id: 14053[/import]

actually thanks carlos i hadn’t thought about that. a lot of drawing apps have an “ink level” allowing you to only draw a certain amount of items. (each being active so undo is still possible) once the ink level ran out you could call display.save(), warn the user they won’t be able to undo past that point, but then give them fresh “ink” to draw on top of the saved image.

can we save an image just to memory without it going to disk? or at least to a temporary file cache rather than a system images folder?

regards
j [import]uid: 6645 topic_id: 4472 reply_id: 14058[/import]

Geeeeezz…

JK !

There is this acronym… but I wont go there :wink:

you could after x amount of strokes - capture screen and even maybe a delta of items to do undo. :wink:

http://developer.anscamobile.com/reference/index/displaycapturescreen

:smiley:

C.
[import]uid: 24 topic_id: 4472 reply_id: 14059[/import]

it’s alright Carlos i’ve been tempted to use that acronym myself a few times, so good point sorry :slight_smile: [import]uid: 6645 topic_id: 4472 reply_id: 14062[/import]

Another trick is to figure out if you are hovering over the same x,y and increase the thickness of the “pen”…

c. [import]uid: 24 topic_id: 4472 reply_id: 14068[/import]

try downloading and running this

http://developer.anscamobile.com/assets/main.lua.zip

carlos [import]uid: 24 topic_id: 4472 reply_id: 14084[/import]

Just wanted to say thanks so much for the quick help! [import]uid: 10284 topic_id: 4472 reply_id: 14105[/import]