### Twisted grid ðŸŒ€

Quadrant square tile variations

Modified concept: reddit.com/r/generat…_post_i_saw_on_here/

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

const layers=11; //min=1 max=30 step=1
const grid=15; //min=1 max=50 step=1
const margin=10; //min=0 max=50 step=1
const tileMargin = .12;//min=0 max=1 step=.01
const maxRotation=.1; //min=-.5 max=.5 step=.01
const orthogonalAt=1; //min=0 max=2 step=1 (Bottom, Middle, Top)
const rotationIncrease = 3;//min=0 max=4 step=1 (Linear, Quadratic, Inverse quadratic, Sine, Cosine)
const shapeDistribution = 0;//min=0 max=1 step=1 (Random by shape and configuration, Random by shape and then random by configuration)

// Global code will be evaluated once.
const turtle = new Turtle();
const polygons = new Polygons();

const locations = [[-1, -1], [0, -1], [1, -1],[-1, 0], [0, 0], [1, 0],[-1, 1], [0, 1], [1, 1]];
const tilesPerLayer = grid**2;
const tileSize = (200 - margin - margin) / grid;
let tiles = Array.from({length: tilesPerLayer}, (i) => Math.random() * 17 | 0); //first = full, next 4 are halves, next 4 are 3 out of 4 quadrant clockwise, next 4 are 3 out of 4 cclockwise, next 4 are single quadrant
if(shapeDistribution == 1) tiles = Array.from({length: tilesPerLayer}, function(i) {
switch(Math.random() * 4 | 0) {
case 1: return (Math.random() * 4 | 0) + 1; //any configuration of half
case 2: return (Math.random() * 8 | 0) + 5; //any configuration of 3 quadrants
case 3: return (Math.random() * 4 | 0) + 13; //any single quadrant
}
return 0; //full
});

const rot2 = (a) => [Math.cos(a), -Math.sin(a), Math.sin(a), Math.cos(a)];
const trans2 = (m, a) => [m[0]*a[0]+m[2]*a[1], m[1]*a[0]+m[3]*a[1]];
const scale2 = (a, s) => [a[0]*s, a[1]*s];
const add2 = (a, b) => [a[0]+b[0], a[1]+b[1]];

// The walk function will be called until it returns false.
function walk(i) {
const layer = i / tilesPerLayer | 0, j = i - (tilesPerLayer * layer), column = j % grid, row =  j / grid | 0;
let rot = 1 - (layer / layers); switch(rotationIncrease) { case 1: rot = 1 - (layer / Math.max(1, layers - 1))**2; break; case 2: rot = (1- (layer / Math.max(1, layers - 1)))**2; break; case 3: rot = 1 - Math.sin((layer / Math.max(1, layers - 1)) * Math.PI / 2); break; case 4: rot = Math.cos((layer / Math.max(1, layers - 1)) * Math.PI / 2); break; }
drawTile(j, [((column + .5) - (grid/2)) * tileSize, ((row + .5) - (grid/2)) * tileSize], tileSize * (1-tileMargin), rot2((rot - (orthogonalAt == 0? 0: orthogonalAt == 1? .5: 1)) * maxRotation));
return i < tilesPerLayer * layers - 1;
}

function drawTile(i, offset, size, rotation) {
let tile = [0, 2, 8, 6]; switch(tiles[i]) {case 1: tile = [0, 1, 7, 6]; break;case 2: tile = [1, 2, 8, 7]; break;case 3: tile = [0, 2, 5, 3]; break;case 4: tile = [3, 5, 8, 6]; break;case 5: tile = [0, 2, 8, 7, 4, 3]; break;case 6: tile = [2, 8, 6, 3, 4, 1]; break;case 7: tile = [8, 6, 0, 1, 4, 5]; break;case 8: tile = [6, 0, 2, 5, 4, 7]; break;case 9: tile = [0, 6, 8, 5, 4, 1]; break;case 10: tile = [6, 8, 2, 1, 4, 3]; break;case 11: tile = [8, 2, 0, 3, 4, 7]; break;case 12: tile = [2, 0, 6, 7, 4, 5]; break;case 13: tile = [0, 1, 4, 3]; break;case 14: tile = [1, 2, 5, 4]; break;case 15: tile = [3, 4, 7, 6]; break;case 16: tile = [4, 5, 8, 7]; break;}

const p = polygons.create();
p.addPoints(...tile.map((i) => trans2(rotation, add2(scale2(locations[i], size / 2), offset))));