Okay, here’s my first go.
Codea program
function setup()
m = mesh()
local nsteps = 200
local w = 5
local h = 1/nsteps
for n=1,nsteps do
m:addRect(0,(n-.5)*h,w,h)
end
m.shader = shader("Documents:ExperimentOne")
m.shader.time = 1
a = vec2(0,0)
b = vec2(100,0)
c = vec2(200,200)
d = vec2(200,300)
m.shader.a = a
m.shader.b = b
m.shader.c = c
m.shader.d = d
m:setColors(255,255,25)
end
function draw()
background(75, 104, 90, 255)
strokeWidth(5)
line(a.x,a.y,b.x,b.y)
line(b.x,b.y,c.x,c.y)
line(c.x,c.y,d.x,d.y)
fill(160, 172, 22, 255)
noStroke()
ellipse(a.x,a.y,20)
ellipse(b.x,b.y,20)
ellipse(c.x,c.y,20)
ellipse(d.x,d.y,20)
m:draw()
end
function touched(touch)
if touch.state == BEGAN then
for k,v in ipairs({a,b,c,d}) do
if v:distSqr(vec2(touch.x,touch.y)) < 900 then
pt = v
end
end
elseif pt then
pt.x = touch.x
pt.y = touch.y
m.shader.a = a
m.shader.b = b
m.shader.c = c
m.shader.d = d
end
end
Vertex Shader
//
// A basic vertex shader
//
//This is the current model * view * projection matrix
// Codea sets it automatically
uniform mat4 modelViewProjection;
//This is the current mesh vertex position, color and tex coord
// Set automatically
attribute vec4 position;
attribute vec4 color;
attribute vec2 texCoord;
//This is an output variable that will be passed to the fragment shader
varying lowp vec4 vColor;
varying highp vec2 vTexCoord;
uniform vec2 a;
uniform vec2 b;
uniform vec2 c;
uniform vec2 d;
uniform float time;
void main()
{
highp float t = position.y/time;
highp float tt = 1.0 - t;
highp vec2 bpos = tt*tt*tt*a + 3.0*tt*tt*t*b
+ 3.0*tt*t*t*c + t*t*t*d;
highp vec2 bdir = tt*tt*(b-a) + 2.0*tt*t*(c-b) + t*t*(d-c);
bdir = vec2(bdir.y,-bdir.x);
bdir = position.x*bdir/length(bdir);
bpos = bpos + bdir;
highp vec4 bzpos = vec4(bpos.x,bpos.y,0,1);
//Pass the mesh color to the fragment shader
vColor = color;
vTexCoord = vec2(texCoord.x, 1.0 - texCoord.y);
//Multiply the vertex position by our combined transform
gl_Position = modelViewProjection * bzpos;
}
Fragment shader
//
// A basic fragment shader
//
//This represents the current texture on the mesh
uniform lowp sampler2D texture;
//The interpolated vertex color for this fragment
varying lowp vec4 vColor;
//The interpolated texture coordinate for this fragment
varying highp vec2 vTexCoord;
void main()
{
//Sample the texture at the interpolated coordinate
lowp vec4 col = vColor;
if (vTexCoord.x < .2)
col.a = col.a*vTexCoord.x/.2;
if (vTexCoord.x > .8)
col.a = col.a*(1.-vTexCoord.x)/.2;
//Set the output color to the texture color
gl_FragColor = col;
}
What I need now is a list of available functions, a bit of guidence on syntax (what language is this?) and an explanation of what lowp and highp mean.