Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

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

edited November 2011 in Suggestions Posts: 53

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.

Comments

  • NatNat
    Posts: 143

    Spline curves would be great.

  • Posts: 24

    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.

  • BortelsBortels Mod
    Posts: 1,557

    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)

  • SimeonSimeon Admin Mod
    Posts: 5,020

    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?

  • BortelsBortels Mod
    Posts: 1,557

    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).

  • beebee
    edited November 2011 Posts: 381

    +1 for appropriate multi files support via dofile and require instead of IDE 'magic' currently used. ;)

  • SimeonSimeon Admin Mod
    Posts: 5,020

    Not sure I agree, bee :P

  • BortelsBortels Mod
    Posts: 1,557

    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".

  • SimeonSimeon Admin Mod
    edited November 2011 Posts: 5,020

    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.

  • beebee
    Posts: 381

    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. :)

    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". ;)

  • SimeonSimeon Admin Mod
    edited November 2011 Posts: 5,020

    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.

  • Posts: 1,976

    @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.

  • SimeonSimeon Admin Mod
    Posts: 5,020

    @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.

  • SimeonSimeon Admin Mod
    Posts: 5,020

    @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.

  • beebee
    Posts: 381

    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. :)

  • edited February 2015 Posts: 2,020

    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
  • SimeonSimeon Admin Mod
    Posts: 5,020

    Excellent polygon function, @yojimbo2000

  • Posts: 1,595

    If anyone hasn't made their own arc function, here's a deadly simple one.


    --# Main -- arc -- Use this function to perform your initial setup function setup() ar = arc(WIDTH/2,HEIGHT/2,200,150,0,180) et=0 end function touched(t) fill(t.x,(t.y*t.x)/HEIGHT,t.x-t.y) et=et+0.05 ar= arc(WIDTH/2,HEIGHT/2,200,math.sin(et)*80+110,0,(math.deg(math.atan2(t.y-HEIGHT/2,t.x-WIDTH/2)))) end -- r = radius, mr = radius of inner arc, ang1, ang2 = start/end angles of arc. function arc(x,y,r,mr,ang1,ang2) local arcshader = shader("Patterns:Arc") local minr = (mr/r)/2 local m = mesh() m.shader = arcshader m.shader.a1 = math.rad(ang1) m.shader.a2 = math.rad(ang2) local col = color(fill()) m.shader.color = vec4(col.r/255,col.g/255,col.b/255,col.a/255) m.shader.size = minr local rct = m:addRect(x,y,r,r,0) return m end function draw() background(40, 40, 50) ar:draw() end
Sign In or Register to comment.