[Graphics] How about text, polygons, and arcs?

I’ve been playing around with graphics (non-sprite) in Codea and it’s been great. I’ve cranked out some really cool stuff with the limited functions.

The three most needed (for me, lol) omissions at the moment are:

  1. drawText(x, y, message) - this is mentioned in another post by someone else

  2. drawPolygon - I really find myself needing to draw polygons without constructing them by hand with lines. The obvious one is a triangle, but I’d also like some help producing a star, etc. Not sure on parameters here, maybe a table of
    coordinates? Also need to be able to fill it.

  3. drawArc(x, y, width, height) - I find myself coming up with work-arounds for this, like drawing rectangles over parts of an ellipse. Would be good to also be able to fill this with color.

Spline curves would be great.

Yeah, it would be great not to add classes or libraries like a touch class to every single project. It would be greater to just add a library directory to a project.

In this library directory should be the most needed classes or libraries.

But then you need to add an dofile or require from lua.

Some text drawing stuff here https://gist.github.com/1330767

This is still a work in progress - the editor really doesn’t like a ton of numbers. I’m working on a differently encoded version that might play nicer with the Codea editor, but hey… Minecraft. Just sayin.

But this should tide you over on the text until it’s added or we get a nicer version.

SOMEWHERE, I have code for drawing arbitrary geometric shapes - I made a “paintbrush” type program that did that long ago on the 8-Bit atari (in Action!), and there is some chance I might still find the code, which frankly is just swiped^H^H^H^H^H^H adapted from examples I found on Compuserve somewhere… (HI I’M OLD)

I like the idea of having vector text rendering built in. What if something like this was included by default in all Codify projects (non-viewable, similar to how class() is included)? Or would everyone prefer bitmap text rendering?

Once we get to where we can import things easily, it’s less of an issue.

I suspect vector fonts will be, long term, slower. No, I know they’ll be slower. Having to redraw them each frame (as opposed to drawing once into a buffer then blitting them) is going to be a drag on performance.

I suggest one nice, fast, bitmap font is a practical necessity. If you added support for vector fonts (or built-in the Hershey fonts, which are free), that would be awesome as well. In the long run, an API to get to the iOS system fonts would be super-keen (as would blitting so we could draw once then just do a memory copy).

+1 for appropriate multi files support via dofile and require instead of IDE ‘magic’ currently used. :wink:

Not sure I agree, bee :stuck_out_tongue:

Real filesystem support, even sandboxed, as opposed to magic would be nice - but apple is already skittish in their “users shouldn’t have to worry about files” thing. Doesn’t really apply to people expecting to write code, who are presumably ready to roll back their sleeves and get dirty - but I could see it making app approval be harder or impossible. Baby steps.

I’d actually like to see send-to and accept-from support; so you could take your codify app and send-to email, for example, or go to a page in the browser and save-to codify.

What did this remind me of? oh yeah - I have a “utility” project where I stick code I may want to use in other projects - like the font stuff. Right now, I have to copy and paste into each project, and that’s slow and error-prone, and if I fix a bug I have to do it in all the projects I copied the code to. There’s gotta be a more elegant way to do that; not sure exactly how. Maybe a magic project that’s auto-included, or a pragma that says “include this other project’s code by reference”.

That send-to and import support is in Codea, but I’ve disabled it while the name change goes through. As soon as that’s done I’m re-enabling that support and doing another update.

Basically it will be tap-hold a user project to send, and any .codea file in your browser or email will be recognised as a Codea project and open appropriately.

I was thinking for “utility” type files to allow users to select new files from other projects when you tap the “+” button on the tab bar. So you can re-use code easily.

AFAIK, though sandboxed, iOS still allows real filesystem within the app itself. So, Lua’s real dofile and require can be provided by Codea, as already been done by iLuaBox. This feature would easily solve @Bortels’ problem to create cross-projects class files. :slight_smile:

However, this should be kept as advance feature. Users who don’t want to know about it could simply ignore it and still able take the benefit of currently Codea’s IDE “magic”. :wink:

But what about simply being able to add files from other projects? This seems fairly simple to me.

Neztec: arcs and quads, perhaps polygons, will be coming.

Simeon, sorry for kicking open this old thread, but it’s now 2015 and we still don’t appear to have arcs or polygons. I’m working on some educational materials, based on Codea Scratchpad, but I keep bumping into these limitations — you can’t make a decent house without reaching for meshes (for the triangular roof), and you can’t make a decent smiley face at all (without arcs). For such a great framework with so many advanced features, these seem like pretty glaring omissions.

@JoeStrout You can use the triangulate() function to build a polygon/mesh out of a list of points, and there have been many arcs/splines created by the community if you search for them.

@JoeStrout arcs are kind of included now — there is a fairly handy Arc shader in the Patterns library which can be used to design an arc primitive (this works the same way as the built-in ellipse, rect, which are internally shaders). I’ll try write a simple arc() function which uses this.

Agree on polygons, though as @SkyTheCoder says it’s possible to generate the necessary meshes with the included triangulate function. A good solution would be to wrap this up in a polygon call.

@Simeon, I agree, these things are possible (though I didn’t know about the Arc shader) – but too complex for a course aimed at 10-12 year olds. And since I’m basing the curriculum on Codea Scratchpad, I can’t even hide the ugly details in another file; it’d have to be right there, where kids would be typing it in without understanding what they’re doing.

Better in my case to just design my lessons without these features… but if you were able to get them into Codea in the next couple of months, I would certainly revise the lessons to take advantage of them. And I do think it would really help the “completeness” of the API.

@JoeStrout oh I agree it’s too complex, but a fairly simple wrapper could be written around the arc shader to provide a standalone arc() function if you need to use them right away. (Same goes for polygon()). Such a library could be used as a dependency.

Adding them as a core feature is a good idea, however.

These features have been asked since the beginning of Codea (was Codify) such as primitive shapes (arc, sector, triangle, star, rounded rect, bezier curve, polygon, etc), flood fill, etc. Also a built-in UI library so we could write non-game apps a bit easier. But obviously they’re not in Codea dev’s interest, so they’re still on the to do list. We don’t know when they will really be developed. Just be patient. :slight_smile:

I’m sure someone must have done this before, or there’s some super fast way to do this with shaders, but here’s my polygon wrapper. It should be fast enough with noStroke(). Having it outlined slows it down. The thing which confused me for ages with this is that fill() has to be wrapped inside color() for it to register as a colour. Improvements welcome. The vec2s must be in clockwise or anti-clockwise order.


function setup()
    fill(255, 0, 17, 255)
    strokeWidth(1)
    stroke(255, 254, 0, 255)
end

function draw()
    background(27, 27, 54, 255)
    local t=ElapsedTime*10
    polygon (vec2(50+t,50), vec2(100+t,50), vec2(200+t,100), vec2(50+t, 200)) --must be in clockwise or anti-clockwise order
end

function polygon(...)
    if arg.n<3 then return end
    local points=arg
    local verts=triangulate(points)
    local cols={}
    for a=1, #verts do
        cols[a]=color(fill())
    end
    local poly=mesh()
    poly.vertices=verts
    poly.colors=cols
    poly:draw()
    if strokeWidth()>0 then
        local a,b
        for a=1, #points do
            if a==#points then b=1 else b=a+1 end
            line(points[a].x,points[a].y,points[b].x,points[b].y)
        end
    end
end

Excellent polygon function, @yojimbo2000