Drawing Primitives

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


@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
-- quad(x1,y1,x2,y2,x3,y3,x4,y4,framecolor,fillcolor): defines a polygon made of 4 points
--     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
--     same comments as for quad
-- 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.


And here is the code. Please note that this is still beta …


I removed the code. Its obsolete with the new features …
As soon as I have understood the new mesh() function properly, there will be an update.

With release 1.3 I guess, this is a bit out to date. New commands give much better results in rendering! Thanks, @Simeon, for providing the new mesh engine! Still try to figure out how it works and how to use best for my drawings, but its really great!

I Love the new mesh engine! I used it in my Zoom library example to create an alternative to ellipse.

@CrazyEd - your links don’t work anymore, have you moved the drawing primitive code somewhere else?