Colour Touch

Instructions:
1.Tap the screen and then move around finger
2. ENJOY!


--# Main
-- Game

-- Use this function to perform your initial setup
function setup()
    print("Hello World!")
    object1 = {}
timer=0
end

-- This function gets called once every frame
function draw()
background(0, 0, 0, 255)   
        for i, o in pairs(object1) do
        o:draw() -- loop through your objects table and draw
    end
    -- Do your drawing here
    
end

function touched(t)
    if t.state==MOVING
    then
       table.insert(object1,Object1(CurrentTouch.x,CurrentTouch.y)) 
    end
end

--# Object1
Object1 = class()

function Object1:init()
    -- you can accept and set parameters here
    self.x = x
    self.y = y
        timer=0
    colors={
    color(0, 21, 255, 255),
    color(255, 0, 201, 255),
    color(110, 255, 0, 255),
    color(0, 208, 255, 255),
    color(255, 242, 0, 255),
    color(255, 47, 0, 255),
    color(0, 255, 146, 255)}
    mycolor = colors[math.random(#colors)]
    
end

function Object1:draw()
    timer=timer+1
    if timer==200
    then
      mycolor = colors[math.random(#colors)]
   
        end
    fill(mycolor)
    
    rect(CurrentTouch.x,CurrentTouch.y,100,100)
    
    -- Codea does not automatically call this method
end

function Object1:touched(touch)
    -- Codea does not automatically call this method
end

Something similar. Slide your finger around.

WARNING: Lots of flashing colors.

displayMode(FULLSCREEN)

function draw()
    fill(math.random(255),math.random(255),math.random(255))
    rect(CurrentTouch.x,CurrentTouch.y,100,100)
end

Another version.

displayMode(FULLSCREEN)
backingMode(RETAINED)

function draw()
    fill(math.random(255),math.random(255),math.random(255))
    ellipse(CurrentTouch.x,CurrentTouch.y,100)
end

@dave1707
I know I could have used math.random

The only problem was the colours looked terrible so instead I made a table of possible colours that looked nice.

I also only wanted the object to stay in one spot and not work like a drawing app (if that made any sense)

@magicskillz I know what you mean about colors with math.random, they’re not very vivid.

@magicskillz It’s better to calculate random colours in HSV (Hue Saturation Value) space and then convert them to RGB. This lets you pick sensible ranges for saturation and value (essentially how vivid and light the color is) and then pick any hue at random).