I need to figure out a way to make the touch stay the color it started in. Run the code to see what i’m am talking about. I started with the example multi-touch project and modded it, in my attempts so far I ended up with this (but it still doesn’t work the way I wanted it to)
Code:
--# Main
-- Multi-touch Handeler
-- Use this function to perform your initial setup
function setup()
print("This example tracks multiple touches and colors them based on their position")
-- keep track of our touches in this table
touches = {}
end
-- This function gets called whenever a touch
-- begins or changes state
function touched(touch)
if touch.state == ENDED or touch.state == CANCELLED then
-- When any touch ends, remove it from
-- our table
touches[touch.id] = nil
else
-- If the touch is in any other state
-- (such as BEGAN) we add it to our
-- table
touches[touch.id] = touch
if touch.x <= WIDTH/2 and touch.y <= HEIGHT/2 then
Color = color(26, 97, 145, 255)
elseif touch.x >= WIDTH/2 and touch.y >= HEIGHT/2 then
Color = color(67, 143, 33, 255)
elseif touch.x <= WIDTH/2 and touch.y >= HEIGHT/2 then
Color = color(167, 23, 23, 255)
elseif touch.x >= WIDTH/2 and touch.y <= HEIGHT/2 then
Color = color(171, 175, 22, 255)
end
end
end
function draw()
background(127, 127, 127, 255)
fill(255, 0, 0, 255)
rect(0,HEIGHT/2,WIDTH/2,HEIGHT/2)
fill(0, 135, 255, 255)
rect(0,0,WIDTH/2,HEIGHT/2)
fill(51, 181, 20, 255)
rect(WIDTH/2,HEIGHT/2,WIDTH/2,HEIGHT/2)
fill(255, 234, 0, 255)
rect(WIDTH/2,0,WIDTH/2,HEIGHT/2)
stroke(0, 0, 0, 255)
strokeWidth(2)
line(0,HEIGHT/2,WIDTH,HEIGHT/2)
line(WIDTH/2,0,WIDTH/2,HEIGHT)
noStroke()
for k,touch in pairs(touches) do
-- Use the touch id as the random seed
math.randomseed(touch.id)
-- This ensures the same fill color is used for the same id
fill(Color)
-- Draw ellipse at touch position
ellipse(touch.x, touch.y, 80, 80)
end
end