// HELLO WORLD
import echo::{Context, Cell, contain, cell_cp};
import echo::audio::{get_freq, get_freq_ago};
// Since you can read text from any cell in the editor, it's not too hard
// to encode a message in the comments and then look it up by hardcoding
// its coordinates into the shader! It then updates immediately as you
// type. This is a lot easier than trying to memorise ASCII codes :)
const MSG_IDX: vec2i = vec2(5, 7);
const MSG_LEN: u32 = 25;
// This example is also audio reactive: make sure your [ ](#microphone)
// is enabled by clicking on the link.
fn map_cell(i: Cell, ctx: Context) -> Cell {
var p = contain(i.sp, ctx.resolution);
var o = i;
let forwards = (i.cp.y & 1u) == 1u;
let direction = select(1.0, -1.0, forwards);
let m = i32(fract((f32(i.cp.x) + ctx.time * direction * 8) / f32(MSG_LEN)) * f32(MSG_LEN));
let c = cell_cp(MSG_IDX + vec2(m, 0));
if (o.ch < 30) {
let g = get_freq_ago(
abs(i.sp.y * 0.3),
(select(i.sp.x, -i.sp.x, forwards) * 0.5 + 0.5) * 0.25
);
o.ch = c.ch;
o.fg = vec3(0.2, 0.2 + pow(g, 4) * 8, 0.5);
} else {
let opacity = 0.7;
o.fg = mix(i.bg, i.fg, opacity);
}
return echo::map_cell_selection(o, i, ctx);
}