Codea 1.5 (Beta 9 and 10)

In beta 1.5(10), searching for ‘RotationRate’ does not yield the new in-app documentation on that subject.

Some other in-app documentation observations:

###‘Vector’ chapter
This could include ‘4D Vector’/vec4 too, as other parts of the in-app documentation now refer to the vec4 userdata (‘buffer’).

###buffer

This refers to four Codea Lua userdata types - vec2, vec3, vec4 and color - and one GLSL ES type float. Should the latter refer to the Lua type ‘number’?

Should how Codea maps/casts Lua types to GLSL ES types be documented, both in terms of buffers and in terms of uniform variables (‘Shader Overview’).

###background, fill, tint, stroke

Inconsistent with other parts of the documentation and Lua, this refers to ‘int’ arguments.

###zlevel, perspective, ortho, camera

Inconsistent with other parts and Lua, this refers to a ‘float’ argument.

This occurs in other parts of the documentation: the type of some arguments is specified to be other than one of the Lua basic types or one of the Codea userdata types.

Hello @Andrew_Stacey. Your version of the rotating cube has perfected what I was trying to achieve (step 1). Step 2 is to add normals and a lighting shader…

On the subject of the orientation of the iPad, I believe that the x, y, z axes of RotationRate are aligned with the iPad in portrait orientation (irrespective of what orientation Codea is running in), with clockwise rotation (looking down the increasing direction of the axis) being positive.


--
-- Axes Explorer
--

displayMode(FULLSCREEN)
function setup()
    setLayout()
    crr = color(255, 0, 0)
    cg = color(0, 255, 0)
    fontSize(32)
    strokeWidth(10)
end

function draw()
    background(0)
    fill(255)
    text("z:", 30, yl)
    fill(crr)
    text("RotationRate", x1, yh)
    fill(cg)
    text("Gravity", x2, yh)
    stroke(crr)
    line(x1, yl, x1 + RotationRate.z * d, yl)
    line(x1, ym, x1 + RotationRate.x * d, ym + RotationRate.y * d)
    stroke(cg)
    line(x2, yl, x2 + Gravity.z * d, yl)
    line(x2, ym, x2 + Gravity.x * d, ym + Gravity.y * d)
end

function orientationChanged(orientation)
    setLayout()
end

function setLayout()
    d = (WIDTH / 4) * 0.9
    x1 = WIDTH / 4
    x2 = WIDTH * 3 / 4
    yl = HEIGHT / 10
    ym = HEIGHT / 2
    yh = HEIGHT * 9 / 10
end

.@mpilgrem the int and float use in the documentation is because Lua has no way to distinguish between the two. I guess I could use “integer” and “number” just to be clear to the user about expected values. Would this be better?

Good catch on RotationRate and search. I forgot to generate an updated search index. Also forgot to add vec4.

Buffer specifically uses “float” because it maps to a attribute float array in a vertex shader. But we can use “number” as well here — like “color” really maps to a scaled “vec4” in GLSL.

Should we “rotate” the RotationRate based on device orientation, like we do with Gravity?

On the ‘rotate’ the RotationRate question, I would make its behaviour consistent with that of Gravity, and I suggest the direction of the axes is documented in the in-app documentation.

Seconded about RotationRate orientation. I’d also make the order in which the axes work clear in the documentation.

EDITOR BUG twice: suddenly, after suppressing some lines, or cut/paste maybe, what appears on the screen is different from what i am typing . I seems the cursor is displayed at 1 location, but i am really editing 20 lines below or so. Closing the project and reopening solves the problem (except for the characters i have deleted by mistake 20 lines below…). First time i ever get this bug.

I’m getting consistent crashes from search. As soon as I type a ‘z’ in the box… I’m out of Codea.

.@Mark documentation search? I think I know what this one is. Thanks for the report.

.@Jmv38 I’ve hit this bug as well. Any ideas on how to reproduce? It’s a hard one to make appear when you want it.

Hello @Simeon. I’ve been thinking about the in-app documentation questions. In-app documentation is one of Codea’s strengths, and what you have done in 1.5 will take it to a new level.

###Codea Overview

I wondered if it would make sense to have a new, initial, chapter for the in-app reference called ‘Codea Overview’ (or something similar). It could cover certain matters that are common to one or more parts of the Codea API.

At the moment, ‘Getting Started’ (outside of the reference) covers: ‘Getting Started’, ‘Example Projects’, ‘Project Basics’, ‘Editor Basics’, ‘Editor Features’, ‘Codea Basics’ and ‘Troubleshooting’.

‘Codea Basics’ (namely, the various functions called by Codea) might be a candidate for a ‘Codea Overview’ in the reference.

Other candidates might be:

  • an explanation that Codea uses two different languages: Lua version 5.1, for most code, and the OpenGL ES Shading Language, for shaders. (The latter is stated in ‘Shader Overview’, but I think the former is not actually stated anywhere explicitly.)

  • an explanation that Codea uses the small number of Lua basic types (including number, string, boolean, function and table) together with userdata types specific to Codea. The userdata types could be listed, with related links to the parts of the reference where they are written up: body, image (codeaimage), soundbuffer (codeasoundbuffer), color, contact, joint, matrix, mesh, shader, touch, vec2, vec3, vec4.

You might add that the elements of Lua tables indexed by integers 1, 2, 3 to ‘n’ are referred to as ‘arrays’. (The term ‘array’ is used, for example, in the documentation of triangulate() and buffer.)

  • an explanation of Codea’s class() function

  • an explanation of the distribution of code between ‘tabs’ and the use of ‘dependencies’.

###Arguments, properties and results of functions

It seemed to me that the following were distinct things:

  • the type of an argument, property or results of functions
  • the acceptable range of values for an argument or property
  • what the function does, precisely

Most arguments or properties are type ‘number’. In a ‘Codea Basics’ chapter, you might state: “If the type of an argument or property is not stated, it can be assumed to be number.” That would avoid a lot of references to ‘number’ elsewhere in the documentation.

For example, in the case of zLevel(z), the argument z could simply be described as “The amount of depth for future drawing operations. Use positive values to draw in front and negative values to draw behind.” without any reference to ‘number’ (or ‘float’, as is currently the case).

Take this code for example:


--
-- Arguments
--

function setup()
    col = color(1000.5, 255, -127.5)
    print(col) -- Output: (1000, 255, -127, 255)
    fill(col)
    print(fill()) -- Output: 1000 255 -127 255
    strokeWidth(5)
end

function draw()
    background(0)
    ellipse(WIDTH/4, HEIGHT/2, 200)
    ellipse(WIDTH * 3/4, HEIGHT/2, -200) -- Draws a square with a circular hole
end

Currently, the in-app reference says that color takes four ‘float’ values from 0 to 255 and that fill takes four ‘int’ values from 0 to 255.

It would be more accurate to say in both places that:

“Distinct colors of different opacities are represented by four integers with values from 0 to 255 (red, green, blue and alpha (opacity)).”

For color() it would be more accurate to say that “The function rounds arguments to the nearest integer”. For fill() it would be more accurate to say that “If an argument is less than 0 or greater than 255, it is treated as if it were 0 or 255, respectively.”

@Simeon – yep, documentation search.

BTW, one thing that keeps happening to me: when trying to select text, I end up having the documentation slide in. It sometimes happens so readily that I have a hard time selecting text.

.@mpilgrem I agree with your suggestions for the documentation. I plan to rewrite the “Getting Started” section to bring it up to date and make it more visual (less text). When I do this, I’ll try to incorporate your suggestions.

A generic “Codea Overview” section would also be good. I’m not sure if I can get around to this before 1.5 — there’s so much left to do (namely, the Shader Lab).

.@Mark I’ve fixed the “z” search issue for the next build, thanks for reporting it.

Regarding the documentation sliding in — I’ve disabled the swipe gesture to open/close documentation sidebar.

I’ve hit http://glslstudio.com by random walk: have one of you guys tested it? For 7€ it seems to be the perfect companion for Codea shader edition. If no one has a feedback, i’ll try it.
(later) Well, i couldn’t wait i tried it. It seems to work fine, and the shaders code can be extracted via mail. There are 3 files sent: the fragment shader .fs, the vertex shader .vs and a huge .h file containing the object definition tables. What is missing is a doc about shaders. In principle it should be codea compatible (have not tried yet) because it is made for ipad.

Very cool. Our Shader Lab will be a bit like that (the next build will have more Shader Lab features that make it a lot more useful). But that definitely looks like a useful app.

To recreate the editor bug. Create a new blank tab with this content using portrait mode.

                    local nextChar = string.sub(gsNoteBeingPlayed,j+nextCharIndex,j+nextCharIndex)

then go to the end of the line and press backspace. Then things in the middle of the line are removed.

My old simple app Paragraf was the first app for writing shader on ios. But it’s not so full of features, and mostly 2d effects. The new Codea will replace the need for it. Just missing an iPhone version of it for coding emergencies. :slight_smile:

Excellent @tnlogy — that helps so much in tracking down this bug!

It turned out to be very tricky to fix. The problem was the condensed use of plus symbols going over a new line. That is, no spaces between the plus symbols and the surrounding characters. Other symbols don’t have this issue.

It may not make 1.5 given the other priorities, but in case there is capacity: more on the in-app reference in beta 1.5(10):

###backingMode
This appears twice: a longer version as 'backingMode ( MODE) ’ in the ‘Display’ chapter, and a shorter version as ‘backingMode( mode )’ in the ‘Graphics’ chapter. ‘Related’ cross-references elsewhere refer to one or other of the versions.

###Lua chapter
This does not include all parts of the Lua standard libraries that are outside of the sandbox, for example ‘debug’. If the scope of the sandbox is now limited, it may be more efficient to document what the sandbox still excludes from Codea.

###pointSize(diameter) and point(x, y)
These functions are still part of the API, but undocumented and excluded from the autocomplete. The Editor’s syntax highlighting recognises point, but not pointSize. (I cannot recall if the functions are formally deprecated.)

###pushStyle
This does not list that it also preserves font(), fontSize(), pointSize(), textAlign(), textMode() and textWrapWidth().

###RETURN global variable
Unlike BACKSPACE, this is undocumented.

(Update)

###zLevel
This has a ‘transform’ as a related link. The link does not work and may have been intended to link to ‘translate’.

Further on Editor misbehaviour: the problem in beta 1.5(8) when the Editor switches from deleting single characters to deleting chunks still exists in beta 1.5(10).

@Simeon - Hi, I’m not sure if this was mentioned, but setContext is pretty glitched atm.
Issue tracker doesn’t offer 1.5 feedback, so i’ll unload it here.

Using setContext to render a mesh to a texture unfortunately completely messes up the z ordering.
Here is an example:

Screen = class()
function Screen:init()
    self.image = image(WIDTH, HEIGHT)
    self.surface = mesh()
    self.surface:addRect(WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)
    self.surface.texture = self.image
    self.surface.shader = shader("Documents:postProcess")
end

function setup()
    screen = Screen()
    mdl = loadModel("Dropbox:creature2")
    ang = 0
end

function draw()
    background(255)

    local x = math.sin(ang)
    local y = math.cos(ang)
    perspective(45)
    camera(x, y, 0, 0, 0, 0, 0, 1)

    setContext(screen.image)
        background(0, 0, 0, 0)
        mdl:draw()
    setContext()

    ortho()
    viewMatrix(matrix())

    screen.surface:draw()

    ang = ang + math.pi/180
end

```






Also, setContext can mess up video recording.
Say we have the following in our setup function and we draw meshes in our draw function:

a = image(10,10)
b = image(10,10)

setContext(a)
setContext()

```

Using setContext on "a", the video recording works fine. 

a = image(10,10)
b = image(10,10)

setContext(a)
setContext()

setContext(b)
setContext()

```

Using setContext on "a" then on "b", the video recording is messed up. 

a = image(10,10)
b = image(10,10)

setContext(a)
setContext()

setContext(a)
setContext()

```

Using setContext on "a" then on "a" again, the video recording is fine. 

Also, the += shortcut button gives "variable = variable +" in glsl too, instead of just "variable +="

Finally, would the ability to save our shaders in dropbox be in conflict with Apple restrictions ?

Cheers,
Xavier

BUG SetContext i think (could be my code, but if so didnt find the error) that there is a bug with large images (WIDTHxHEIGHT) when filled with set context. Then when i display then with sprite() there is always a small offset ~100 in x and 30 in y, not always the same, and i cannot remove it with resetMatrix() resetStyle(). I tried to make a small program to show you but then the bug does not show up.