< Previous | Contents | Next >

Example 5 – Shapes, Lines, Text

This section refers to Example5_Shapes.fuse for defining and rendering of shapes, setting the color and styles. Example4_Text.fuse has info on text rendering.

It works similar to a 3D render context and there are 5 objects in creating and renderings a shape.

A Shape is a linked list of lines or curves and defines as an outline or solid. FillStyle defines what style the shape will be filled with. ChannelStyle sets the color and blur, glow of the shape. Image channel defines an image or frame buffer to render shapes into it. Matrices are used to transform the shapes before rendering them into an image.

This sets up the context and creates a shape.

local ic = ImageChannel(out, 8) -- Image Channel local fs = FillStyle() -- Fill Style Object local cs = ChannelStyle() -- Channel Style

local mat = Matrix4() -- Matrix to transform the shapes local sh = Shape()


-- Shape made of a group of line segments sh:MoveTo(0.078125, 0.1484375)

sh:LineTo(0.1748046875, -0.0078125)

sh:LineTo(0.177734375, -0.0732421875)

sh:LineTo(0.1455078125, -0.1435546875)

sh:LineTo(0.104777151878219, -0.160285078121503)

sh:LineTo(0.06640625, -0.150390625)

sh:LineTo(0.0068359375, -0.09375)

sh:LineTo(-0.05078125, -0.07421875)

sh:LineTo(-0.154296875, -0.1142578125)

sh:LineTo(-0.1767578125, -0.0986328125)

sh:LineTo(-0.1904296875, 0.0185546875)

sh:LineTo(-0.11328125, 0.0615234375)

sh:LineTo(-0.072265625, 0.1162109375)

sh:LineTo(-0.0546875, 0.1025390625)

sh:LineTo(-0.01953125, 0.1396484375)

sh:LineTo(0.0263671875, 0.1328125)

sh:LineTo(0.017578125, 0.1015625)

sh:LineTo(0.0625, 0.07421875)


The matrix is scaled, moved and rotated, the order of these operations is important, This example Scales first, moves the shape and rotates the entire shape.

The second section sets the color and look, applies the matrix to the shape and renders it to an image using ShapeFill and PutToImage.


mat:Identity() -- Set the matrix to zero mat:Scale(0.7, 0.7, 0.7) --Scale mat:Move(0.25, 0.4, 0) -- Translate the Shape

mat:RotZ(-rotation) -- Rotate, Note the order of Matrix operations


cs.Color = Pixel{R=r , G=g , B=b, A = 1} -- Set the Color ic:SetStyleFill(fs) -- Set the Drawing application styles

sh = sh:TransformOfShape(mat) -- Transform Shape using the Matrix ic:ShapeFill(sh) --Apply Shape to the Image Channel ic:PutToImage("CM_Merge", cs) --Render to the image