Difference between revisions of "SHIP:Sail:qr"

From Serious Documentation
Jump to: navigation, search
(Parameters/Return Value)
(Detailed Description)
Line 39: Line 39:
 
== Detailed Description ==
 
== Detailed Description ==
  
The {{SailFunc|getChild}} function returns the direct child at <code>index</code> within the parent.
+
The {{SailFunc|qr}} function renders a QR code image into a canvas node based on runtime data held in a binary {{DataType|Buffer}} or {{DataType|String}}.
  
Nodes in [[SHIP]] may have 0 or more direct child nodesFor example, a {{Node|group}} in the {{Node|resources}} area may have N {{Node|image}}s within the {{Node|group}}. These children, if present, are implicitly numbered <code>0..(N-1)</code> where <code>N</code> is the total number of children of any type within the parent node.
+
Since QR codes are always square, the <code>size</code> parameter indicates the pixel width and pixel height of the QR codeSince canvas dimensions are positive up-and-to-the-right (vs. box/frame which are down and to the right) the offset specified in the <code>qr</code> functions <code>x</code> and <code>y</code> parameters indicate the bottom-left corner of the QR code's target locationIn the canvas, the QR code will be rendered at <nowiki>[</nowiki>x,y..(x+size-1),(y+size-1)<nowiki>]</nowiki>.
 
 
The <code>index</code> is always taken "modulus the count of children within the parent", preventing inadvertent out-of-bounds accessesFor example, a reference to index <code>5</code> when the parent only has <code>4</code> children will return <code>5%4 => 1</code>. Negative indices are handled also with a modulus. Therefore, as expected, index <code>-1</code> returns the last child.
 
 
 
If the specified parent node has no children, the parent object itself is returned by the function.
 
  
 
== Examples ==
 
== Examples ==

Revision as of 15:22, 25 July 2016

Function Returns Introduced Description
qr nothing v5.1 Generates a QR code image in a canvas object.

See Also:

Prototype

qr(Node canvas, Dimension size, Dimension x, Dimension y, Byte type, Byte redundancy, String src, [Color fg [, Color bg ]]);qr(Node canvas, Dimension size, Dimension x, Dimension y, Byte type, Byte redundancy, Buffer src, [Color fg [, Color bg ]]);

Parameters/Return Value

Parameter Data Type Description
canvas Node Node of type canvas to render into
size Dimension Pixel width and height of resulting square QR code image
x Dimension Horizontal offset in canvas for bottom right corner of QR code
y Dimension Vertical offset in canvas for bottom right corner of QR code
type Byte Type of QR code 0...127
redundancy Byte Data redundancy desired in QR image 0..100 as a percentage
src String String object for source data
src Buffer Buffer object for source data
fg Color ARGB8888 color used for rendering the foreground; if not specified default is 0xFF000000 (opaque black)
bg Color ARGB8888 color used for rendering the background; if not specified default is 0xFFFFFFFF (opaque white)

Detailed Description

The qr function renders a QR code image into a canvas node based on runtime data held in a binary Buffer or String.

Since QR codes are always square, the size parameter indicates the pixel width and pixel height of the QR code. Since canvas dimensions are positive up-and-to-the-right (vs. box/frame which are down and to the right) the offset specified in the qr functions x and y parameters indicate the bottom-left corner of the QR code's target location. In the canvas, the QR code will be rendered at [x,y..(x+size-1),(y+size-1)].

Examples

Animations

getChild is particularly useful for animations where an incrementing counter variable from a timer can be used as an index into a group of images and then assigning the result to a box's object property.