< Lua

598pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Drawings - Lua moduleEdit

CHDK 1.2.0 and later  releases  support Lua functions that draw simple shapes on your camera's LCD screen from a script.  See : for a description of these functions.

There is also a Lua module that allows you to enhances these drawing functions, giving you more control in adding and removing shapes.  The primary advantage of using this module is that it allows you to easily and simply redraw (repaint) the shapes you have drawn  - something that proves necessary periodically as the Canon UI tends to overwrite things randomly.

These functions are defined in drawings.lua module (A/CHDK/LUALIB/DRAWINGS.LUA).


Prior to using the commands listed below, the drawings module has to be initialized with this simple command:

require "drawings"

Note: Do not use .lua extension.


In this manual object is understood as an individual shape with its own parameters, which can be added, removed, moved or changed. Objects that are available through this module are as follows:

Element Element type Parameters
Pixel pixel x1, x2, color
Line line x1, y1, x2, y2, color
Rectangle rect x1, y1, x2, y2, color [, thickness]
Filled Rectangle rectf x1, y1, x2, y2, color1, color2 [, thickness]
Ellipse elps x, y, a, b, color
Filled ellipse elpsf x, y, a, b, color1, color2
Text string string x, y, string, text_color, backgr_color

Parameters in [] are not necessary.

Creating objectsEdit

Before objects can be drawn or seen, they must be created. To create an object use following syntax:

draw.add("element_type", parameter1, parameter2....)

For example, to create an empty rectangle whose top-left corner has the coordinates 10, 50, the bottom-right corner is at 220,200, the color is blue and line thickness is 3 use this command:

draw.add("rect", 10, 50, 220, 200, "blue", 3)

Every time the draw.add() function is called it returns a number which identifies the newly created object. This value can be further used to change various parameters of the object. To obtain this value, use a variable, e.g. my_line_id:

my_line_id=draw.add("line", 45, 30, 100, 101, "red")

Now my_line_id stores the identifier.

Drawing objectsEdit

Once objects have been created,they are stored in memory, but they are not visible on the screen. To draw them use either of the following commands:




Both commands draw all objects on the screen. The difference is that draw.redraw() first clears the screen, so only the new state visible, whereas draw.overdraw() draws new state but does not remove previous drawings. If an object is moved and then draw.overdraw() is called this object will appear in both places.

Changing objectsEdit

Any previously created objects can be changed with reference to their identifiers. Use this command:

draw.replace(id, "new_element_type", new_param1, new_param2...)

For example, assume a filled rectangle has been created:

my_rect_id=draw.add("rectf", 55, 104, 65, 114, "green", "yellow", 2)

and you would like to move it 30 px to the right, using this coommand:

draw.replace(my_rect_id, "rectf", 85, 104, 95, 114, "green", "yellow", 2)

Note that with draw.replace() every parameter of the object cam be changed. For example the small rectangle from above can be changed into a large circle:

draw.replace(my_rect_id, "elps", 90, 110, 100, 100, "white")

Note also that all these changes will not be visible until draw.redraw() or draw.overdraw() are called.

Removing objectsEdit

A specified object can be removed using:


All objects can be removed by using:


Note that this command removes objects from the screen as well as from memory. After this command none of these objects will be accessible.

Also note that simple Lua command draw_clear() is used to clear screen and is not the same as draw.clear() from this module!

Retrieving parametersEdit

If the identifier of an object is known then all its parameters can be retrieved as an array. Syntax:


For example:


Variable params will now be an array with the following content:

{ "elps"​, 90, 110, 100, 100, "white" }


In the examples above, colors were used with explicit names. However, colors can be specifiedin two ways:

  • When using the Canon firmware palette as numbers in the range 0-255. These numbers are not portable and the same number migh correspond to other color in an other camera (or even other mode). Also, the same color will have different numerical values for different cameras. Use Canon firmware numbers only to specify tones for a specific camera.
  • When using the CHDK script palette. Colors in this palette that are used by drawings module are exactly the same as described in basic Lua drawing commands, except numeric values are not used but names as strings. These names are as follows:

Basic colors:







Extended colors:













Basic colors should be available on most or all CHDK-supported cameras, since they are used by CHDK GUI and histogram. Extended colors are available only for cameras that use colored icons. If extended colors are needed in a script, cameras with no color icon support will display the most similar color (e.g. green for green_light, white for yellow). Currently blue_light and blue_dark are only placeholders and they are not available in any camera.


It has been stated that when an object is created. it is stored in memory. In fact, all these objects are stored in a two-dimentional array named SCREEN_DRAWINGS. This array can be accessed directly, but use of drawing commands is prefered.

NOTE : When using the drawing module the name SCREEN_DRAWINGS cannot be used for any other purposes, due to conflict. The other reserved word is draw. Variable names such as draw, draw[] and other derivatives should not be used

Also on Fandom

Random Wiki