Codea 1.5 (Beta 9 and 10)

(Edit) The new beta 1.5(9) does fix the bug that was affecting my ‘RectWithHole’ code. Thank you.

Hello @Jmv38. I wonder if the problem you are having with Tendril is a 1.5(8) beta issue? Does it also occur in beta 1.5(9)?

Hi @Mpilgrem. I was not aware v9 was released. I’ll check once i’ve installed it.

Regarding the new ‘expression key’ in beta 1.5(9): as a ‘hunt and peck’ touchscreen typist, I prefer the way that this has been implemented in the Shader Lab Editor (which is still ‘hunt and peck’) rather than in the Editor (which mixes ‘peck and slide’ with just ‘pecking’). I also prefer the way that the placement of the ‘expression key’ dialog in the Shader Lab Editor does not obscure the last visible line of text (which tends to be the line that I am editing), unlike in the Editor (where the dialog tends to be placed over what I am editing).

In beta 1.5(9) the Shader Lab Editor appears to be more stable than in earlier betas, but it is still not wholly stable (I have had it crash out of Codea once).

In the Shader Lab Editor, it is possible to call up the on-screen keyboard without the text automatically scrolling up so that the cursor is visible above the keyboard.

Below is a further experiment with shaders and noise, from the same source as my first comment on the subject:

Lua:


--
-- WorleyGLSL
--
-- Shader makes use of:
-- Cellular noise ("Worley noise") in 2D in GLSL
-- Author: Stefan Gustavson
-- http://webstaff.itn.liu.se/~stegu/GLSL-cellular/

supportedOrientations(LANDSCAPE_ANY)
function setup()
    m = mesh()
    m:addRect(WIDTH/2, HEIGHT/2, WIDTH, HEIGHT)
    m.shader = shader("Documents:Worley")
    parameter.number("freq", 1, 289, 17)
    parameter.number("jitter", 0, 1, 1)
    parameter.color("col1", color(239, 231, 30))
    parameter.color("col2", color(239, 30, 30))
end

function draw() 
    m.shader.freq = freq
    m.shader.jitter = jitter
    m.shader.col1 = col1
    m.shader.col2 = col2
    m:draw()
end

Vertex shader:


//
// Vertex shader: Worley
//

uniform mat4 modelViewProjection;
attribute vec4 position;
attribute vec2 texCoord;

varying highp vec2 vTexCoord;

void main()
{
    vTexCoord = texCoord;
    gl_Position = modelViewProjection * position;
}

Fragment shader:


//
// Fragment shader: Worley
//

precision highp float;

varying highp vec2 vTexCoord;
uniform float freq;
uniform float jitter;
uniform vec4 col1, col2;

// ---------------------------------------------------------------
// Cellular noise ("Worley noise") in 2D in GLSL.
// Author: Stefan Gustavson
// http://webstaff.itn.liu.se/~stegu/GLSL-cellular/
// ---------------------------------------------------------------
// Copyright (c) Stefan Gustavson 2011. All rights reserved.
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

vec3 permute(vec3 x) {return mod((34.0 * x + 1.0) * x, 289.0);}

vec2 cellular(vec2 P) {
    #define K 0.142857142857 // 1/7
    #define Ko 0.428571428571 // 3/7
    vec2 Pi = mod(floor(P), 289.0);
    vec2 Pf = fract(P);
    vec3 oi = vec3(-1.0, 0.0, 1.0);
    vec3 of = vec3(-0.5, 0.5, 1.5);
    vec3 px = permute(Pi.x + oi);
    vec3 p = permute(px.x + Pi.y + oi);
    vec3 ox = fract(p * K) - Ko;
    vec3 oy = mod(floor(p * K), 7.0) * K - Ko;
    vec3 dx = Pf.x + 0.5 + jitter * ox;
    vec3 dy = Pf.y - of + jitter * oy;
    vec3 d1 = dx * dx + dy * dy;
    p = permute(px.y + Pi.y + oi);
    ox = fract(p * K) - Ko;
    oy = mod(floor(p * K), 7.0) * K - Ko;
    dx = Pf.x - 0.5 + jitter*ox;
    dy = Pf.y - of + jitter*oy;
    vec3 d2 = dx * dx + dy * dy;
    p = permute(px.z + Pi.y + oi);
    ox = fract(p*K) - Ko;
    oy = mod(floor(p*K),7.0)*K - Ko;
    dx = Pf.x - 1.5 + jitter*ox;
    dy = Pf.y - of + jitter*oy;
    vec3 d3 = dx * dx + dy * dy;
    vec3 d1a = min(d1, d2);
    d2 = max(d1, d2);
    d2 = min(d2, d3);
    d1 = min(d1a, d2);
    d2 = max(d1a, d2);
    d1.xy = (d1.x < d1.y) ? d1.xy : d1.yx;
    d1.xz = (d1.x < d1.z) ? d1.xz : d1.zx;
    d1.yz = min(d1.yz, d2.yz);
    d1.y = min(d1.y, d1.z);
    d1.y = min(d1.y, d2.x);
    return sqrt(d1.xy);
}
// ---------------------------------------------------------------

void main() {
    vec2 F = cellular(vTexCoord * freq);
    float n = 0.1 + (F.y - F.x);
    gl_FragColor = n * (col1 - col2) + col2;
}

Hello @Simeon. Is the following in the ‘Shader Overview’ in the in-app documentation correct?

The documentation states that any uniform variables declared in your shader can then be (typo: docs say ‘by’) accessed on your mesh as follows:

myMesh.myCustomUniform = 3.5

Should that:

(1) be myMesh.shader.myCustomUniform = 3.5; and

(2) refer to uniform variables being ‘set for the shader’ (rather than ‘accessed’ ) on your mesh?

I had a strange bug on v9 editor: after selecting some text, contextual menu would not appear. I had to kill codea and it was back to normal.

.@mpilgrem thanks for starting this thread and your feedback.

Is the following in the ‘Shader Overview’ in the in-app documentation correct?

That’s incorrect. Thank you for the find, I’ve fixed it. If you have any issues with the way that chapter is written, please let me know.

as a ‘hunt and peck’ touchscreen typist, I prefer the way that this has been implemented in the Shader Lab Editor (which is still ‘hunt and peck’)

On “Hunt and peck” versus drag. I will restore the old behaviour (tapping the key to get the popup fixed on-screen). The reason I wanted to encourage drag selection was because it seemed faster — and it follows Apple’s own key popover implementation (i.e. if you press and hold the “e” key you can drag to select a diacritic).

The styling also matches Apple’s keyboard popover style, which I much prefer over the generic “popover” design.

Regarding the way it obscures the last line. It’s going to obscure a fixed portion of your text, and depending on your scroll position that may or may not obscure the cursor location. In general I hoped people would know the symbol they were after before pressing the key (at least, after the first few times they used it).

Good catch that the Shader Lab hasn’t been updated to use the latest one. I’ll have to fix that.

In the Shader Lab Editor, it is possible to call up the on-screen keyboard without the text automatically scrolling up so that the cursor is visible above the keyboard.

Good find. That will need to be fixed.

I like the drag-select on the numerical symbols. One suggestion: how about adding the “.” key? I know it’s available right there on the screen, but already the rhythm of selecting the rest of a calculation off the pop-up is so slick I miss that one key.

Many nice things in this new release. One bad thing is: i’ve lost all my high scores i had saved with globaldata in my KraizyCircles game… We dont lose the projects when we update Codea, could it be the same for saved data?
[edit] my mistake, sorry! The data are still there. It is just that localData has been repaired, so my program has automatically swithched to local data save, where it cannot find the score saved in global data… So Codea works fine!

Hello @Simeon. On the current implementation of the drag selection, I am not sure what I am doing, but sometimes I find I have transitioned from the ‘expression key’ into ‘the drag the cursor around the Editor using the keyboard’ functionality when I did not intend to.

In terms of the design of key input more generally, could there be more than 11 keys in the strip above the standard keyboard? If the keys were narrower, you could fit others in. If the keys were the width of those in the ‘expression key’ pop up, I think you could fit 17 keys in the strip. My vote would be to move +, -, *, /, [] and {} from the pop up to the strip. That would create space in the pop up for other, rarer, symbols (examples might be ^, :, <=, >=, ==, _).

.@mpilgrem you were right: with this version your program does notcrash any more.

.@mpilgrem that’s a bug — I think if you have “Keyboard Gestures” turned on (where you can drag anywhere on the keyboard to move the cursor) it interferes with the expression key dragging. I’ll have to disable the keyboard gestures while the expression key is active.

I actually find the keys on the keyboard strip a bit small as it stands — that’s one of the reasons for moving to drag-selection for the small expression keys, so you don’t have small tap targets. I could always add the rarer symbols to a third row in the popup?

(And now that you mention it, “:” should definitely be in there as it’s not a rare symbol at all.)

.@Mark that’s a good idea. I’ll look at adding a “.” key.

By the way, I’ve been looking at implementing your API suggestions for compass and location data. Compass is a little more complicated than I initially thought — because the OS can display a calibration graphic that is used to direct the user to move their device in a specific pattern.

EDITOR BUG there is still this bug of the editor loosing the ‘last cursor location in this tab’. I can see that this last location is saved, because when i switch back to previous tab, i see first the cursor at the good location, but after a fraction of a second the display scrolls to a wrong location.

crashes this version seems to crash more often (my game KraizyCircles crashes 2x more)

EDITOR BUG happened twice today: the editor got locked in some weird state where
1/ the selection contextual menu does not appear on tap.
2/ the keyboard cannot be removed.
I had to kill codea manually to recover. Never seen that in previous versions.
[EDIT] i found what generates the problem: any time i use the special button to popup the special keys… Then it happen! This is reallu annoying then. Please a quick update?

I’ve been thinking further about key input in the Editor. Some keys insert content at the cursor. Other keys do something else (namely: indent, toggle in-app documentation, move cursor left/right, expand selection left/right, search code or run code).

Below is an imagined keyboard where the strip has keys (no smaller than the current ‘expression key’ popup keys) for inserting content and a key to the right that toggles on/off a second strip with keys with other functions (and space for more functions to come…).

Some further observations on the ‘Shaders & Mesh’ chapter of the in-app documentation:

###Shader Overview

In the final paragraph “For advanced users, …”, the example might start with the line:

myShader = shader()

###mesh

This does not refer to normals or shader (unlike Mesh Overview).

###mesh.clear

This is silent about normals and other attribute arrays.

###mesh.normal

Is there a myMesh:normal(i) equivalent of myMesh:vertex(i)?

###shader

This does not refer to the properties myShader.vertexProgram and myShader.fragmentProgram that are discussed in ‘Shader Overview’ (as opposed to the arguments). (Edit) … And that the properties can be read as well as written.

###triangulate

This still refers to points having to be in a clockwise order.

An experiment with RotationRate:


--
-- Rotation Rate Calibration Tester
--

supportedOrientations(PORTRAIT)
displayMode(FULLSCREEN)
function setup()
    if deviceMetrics().platformName == "iPad 1G" then
        print("This code needs a gyroscope."..
            " An iPad 1 does not have one.")
    end
    img = readImage("Planet Cute:Character Boy")
    iw = img.width
    ih = img.height
    f = math.min(WIDTH/iw, HEIGHT/ih)
    iw = iw * f
    ih = ih * f 
    x = WIDTH/2
    y = HEIGHT/2
    ax, ay, az = 0, 0, 0
end

function draw()
    local w = iw * math.cos(math.rad(ax))
    local h = ih * math.cos(math.rad(ay))
    background(0)
    translate(x, y)
    rotate(az) -- Rotates in degrees
    sprite(img, 0, 0, w, h)
    ax = ax + RotationRate.y
    ay = ay + RotationRate.x
    az = az - RotationRate.z
end