Wiki

Clone wiki

Core / image

Back to Beyond the Codea in-app reference


FunctionIconType-Small.png image() function

Codea's in-app reference documents most of the image() function. The function returns a userdata value that represents a raster image.

image(width, height)

The function image(width, height) returns an image of the given width and height in 'pixels'.

myImage:set()

The myImage:set(x, y, c) syntax calls a function to set the pixel at x, y to colour c.

The bottom left hand pixel of myImage is at 1, 1. For example:

function setup()
    local red = color(255, 0, 0)
    local green = color(0, 255, 0)
    myImage = image(100, 200)
    for j = 1, 200 do
        c = red
        if j > 40 then c = green end
        for i = 1, 100 do
            myImage:set(i, j, c)
        end
    end
end

function draw()
    background(0)
    sprite(myImage, WIDTH/2, HEIGHT/2) -- Green area above red stripe
end

Updated