# Drawing Primitives

In order to have more flexibly in making drawings I have coded a few more drawing primitives. An example you find here

http://crazyed.posterous.com/drawing-primitives

@Simeon: will we get in one of the next updates some more drawing primitives like arc, quad, …? I thought that this has been discussed already in one of the forum, but I can’t find the right info anymore. So please excuse if asking same things twice …

-- Those functions represent some more graphic primitives than standard Codea provides.
-- in particular those are
--
-- rrect(x,y,w,h,r,fillcolor,framecolor): rounded rectangle (most simplest one)
--     x,y define the left bottom corner
--     w,h degine width and height
--     r defines the radius of the rounded corners
--     fillcolor is the color the rectangle is filled with
--     framecolor is the color of the boundary
--
--     the four points define the quad. Note that the sequence plays a role. Usually either
--     clockwise or counterclockwise makes sense. Any other sequence creates probably
--     interesting resuls ...
--     framecolor is color of the boundary; default yellow
--     fillcolor is the color the polygon is filled with; default nil
--
-- triangle(x1,y1,x2,y2,x3,y3,framecolor,fillcolor): defines a polygon made of 3 points
--
-- polygon(x,y,framecolor,fillcolor): polygon with n points can be drawn
--     x is vector having n points defining x-coordinate of point
--     y is vector having n points defining y-coordinate of point
--     framecolor is color of the boundary; default yellow
--     fillcolor is the color the polygon is filled with; default nil
--
-- bezier(x1,y1,cx1,cy1,cx2,cy2,x2,y2,steps,thickness,linecolor,fillcolor)
--     x1 and y1 define the startpoint
--     x2 and y2 define the endpoint
--     cx1, cy1, cx2, cy2 define the control points which define the shape of the cubic bezier
--     steps determines the resolution. If distance between start and stop point is small
--     it is better to reduce steps to see a curve.
--     thickness determines the thickness of the line (default: 6)
--     linecolor defines the color of the line (default: yellow)
--     fillcolor defines the color the curve is filled with (default: nil)
--
-- arc

Those look really useful, @CrazyEd.

While the next update doesn’t introduce primitives, it introduces a new construct called Mesh. A mesh is an arbitrary polygon mesh (constructed of triangles) and renders very fast.

It’s more low-level than the primitives you describe, but you can easily use it to draw quads, triangles and arbitrary polygons.

Mesh also allows you to warp and map sections of a sprite or image onto arbitrary polygons, as well as linearly interpolate colours across vertices.

Here’s an example of mesh rendering in Codea 1.3. In this example I made 11,000 rectangles in a single mesh, each rectangle shows part of the “SpaceCute:Heart” sprite. They explode outwards.