### Metagons ðŸ”¯

Be sure to play with the 'phasePermille' slider to simulate the video at reddit.com/r/generative/comments/tpwp57/metagons/

Concept: reddit.com/user/iqof…ns_infinite_looping/

```// You can find the Turtle API reference here: https://turtletoy.net/syntax
Canvas.setpenopacity(.8);

// Global code will be evaluated once.
const turtle = new Turtle();
const phasePermille = 0; //min=0 max=1000 step=1
const grid = 8; //min=1 max=15 step=1
const border = 0; //min=0 max=10 step=1
const cellMargin = 2; //min=0 max=10 step=1

const pi2 = Math.PI * 2;
const cellSize = (200 - border - border) / grid;
const phase = phasePermille / 1000 * pi2;

const tr = (location, size, pt) => [location[0] + (size / 2) * pt[0], location[1] + (size / 2) * pt[1]]
const cl = (pt) => [pt[0] - grid/2*cellSize, pt[1] - grid/2*cellSize]
const add2 = (a, b) => [a[0]+b[0], a[1]+b[1]];
const scale2 = (a, s) => [a[0]*s, a[1]*s];

// The walk function will be called until it returns false.
function walk(i) {
const col = i % grid;
const row = i / grid | 0;

drawCell(cl([(col + .5) * cellSize, (row + .5) * cellSize]), cellSize - cellMargin, row + 1, col + 1);

return i < grid**2 - 1;
}

function drawCell(location, size, classe, n) {
let ro = Math.cos(phase * 3) / 4;
for(let i = 0; i < n; i++) {
let o = [Math.sin(phase + (i * pi2 / n)) / 4, -Math.cos(phase + (i * pi2 / n)) / 4];
drawElement(tr(location, size, scale2(o, 1 + ro)), size * 2/3, classe, (i * pi2 / n));
}
}

function drawElement(location, size, classe, orientation) {
if(classe == 1) {
turtle.circle(.25);
return;
}

const hSize = size / 2;

for(let i = 0; i <= classe; i++) {