Implement a color palette program

Hello

I found a finger painting library on the internet. I can use it like this:

local fingerPaint = require("fingerPaint")
local canvas = fingerPaint.newCanvas(width,height,thickness,...)

But I want to put a color palette on the page so that the user can paint in the color of their choice after clicking on them.

I know something about listeners. But I do not know how to implement such a program. In fact, I have no idea.

I wrote the following code but it did not work at all:

local fingerPaint = require("fingerPaint")
local function onTap( event )
	color={1,0,0}
	local canvas = fingerPaint.newCanvas(100,200,30,color)
end


local red=display.newImageRect("red.png",100,100)
red.x=0 
red.y=0

red:addEventListener( "tap", onTap )

Do you have an idea in this regard?

I assume you probably have seen this short tutorial: Finger Painting in Corona With Just One Line of Code!.

Anyway, all we can see the code you pasted so if any issues I’m going to point are there due to it being an example then: I’m sorry - just trying to be helpful :slight_smile:.

You probably don’t want to recreate your canvas inside the onTap listener, instead you’d create a canvas, and the “palette widget” separately:

local fingerPaint = require("fingerPaint")
local canvas = fingerPaint.newCanvas(...)
local red = display.newImageRect("red.png",100,100)
local function onTap( event )
   canvas:setPaintColor(1,0,0)
end
red:addEventListener( "tap", onTap )

The above could take you far, but the author of the fingerpaint library oneupped us already! If you read the blogpost by Jason Schroeder carefully then you’ll notice he provided a sample project, together with a color picker widget! Reading through that small example should give you an idea on how to use it. I loaded the example project and in the simulator, it still seems to work :slight_smile:

Thank you very much for your help :+1: . This is exactly what I wanted.
Also thanks to Jason Schroeder :grinning: