JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.

Any URL's added here will be added as `<script>`

s in order, and run *before* the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.

If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.

You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.

+ add another resource

If active, Pens will autosave every 30 seconds after being saved once.

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Visit your global Editor Settings.

` ````
- let d = 800;
canvas#c(width=d height=d)
```

` ````
$d: 90vmin;
$c: #000;
body {
display: grid;
place-content: center;
overflow: hidden;
margin: 0;
min-height: 100vh;
background: mix(#fff, $c, 20%)
}
canvas {
max-width: $d; max-height: $d;
border-radius: .5em;
box-shadow: 2px 2px 5px rgba($c, .5);
background: mix(#fff, $c, 13.5%)
}
```

` ````
const _C = document.getElementById('c') /* canvas element */,
C = _C.getContext('2d') /* 2L canvas context */,
D = _C.width /* edge length of canvas square */,
N = 24 /* numbers of rows/ columns */,
NP = N*N /* total number of polygons */,
L = D/N /* edge length of a grid cell */,
RC = .375*L /* max circumradius of in-cell polygon */,
UA = ~~(360/(N - 1)),
THEME = ["#b86125", " #f68d2e", " #d6d2c4", " #a0d1ca"],
NT = THEME.length,
NVMAX = 8,
NVMIN = 3,
NVDIF = NVMAX - NVMIN,
OPTS = ['fill', 'stroke'],
NO = OPTS.length,
POLY = [] /* array of polygons */,
FN = ['line', 'move'];
function rand(max = 1, min = 0, dec = 0) {
return +(min + (max - min)*Math.random()).toFixed(dec)
};
class Poly {
constructor(i, j) {
this.i = ~~Math.abs(i - .5*(N - 1)); /* row index */
this.j = .5*N - ~~Math.abs(j - .5*(N - 1)); /* column index */
/* coordinates of circumcircle centre */
this.ox = (j + .5)*L;
this.oy = (i + .5)*L;
let r = Math.hypot(this.i - .5*N, this.j - .5*N)
this.n = NVMIN; /* number of polygon vertices */
this.β = 2*Math.PI/this.n; /* base angle corresponding to an edge */
this.b = ~~(Math.round(Math.atan2(this.oy - .5*D, this.ox - .5*D)*180/Math.PI + 180)/90); /* paint bucket index */
this.o = this.b%2;
this.δ = Math.round(r/N/Math.sqrt(2)*360 - ((this.i - this.j)%2)*180); /* initial angular offset of pulse */
this.f = .5*(1 - Math.cos(this.δ*Math.PI/180)); /* scaling factor */
this.vx = [];
for(let k = 0; k < this.n; k++) {
let γ = -.5*(Math.PI + ((this.n + 1)%2)*this.β) + k*this.β;
this.vx.push([RC*Math.cos(γ), RC*Math.sin(γ)])
}
}
get coords() {
this.δ += .25*UA;
if(this.δ >= 360) {
this.δ = 0;
this.n += this.n === NVMAX ? -NVDIF : 1;
this.β = 2*Math.PI/this.n;
this.b += this.b === NT - 1 ? 1 - NT : 1;
this.o = 1 - this.o;
this.vx = [];
for(let k = 0; k < this.n; k++) {
let γ = -.5*(Math.PI + ((this.n + 1)%2)*this.β) + k*this.β;
this.vx.push([RC*Math.cos(γ), RC*Math.sin(γ)])
}
}
this.f = .5*(1 - Math.cos(this.δ*Math.PI/180));
return this.vx.map(c => [
this.ox + this.f*c[0],
this.oy + this.f*c[1]
])
}
};
function draw() {
C.clearRect(0, 0, D, D); /* clean canvas before drawing again */
for(let i = 0; i < NT; i++) {
let b = POLY.filter(c => c.b === i); /* polygons in current bucket */
for(let j = 0; j < NO; j++) {
let o = b.filter(c => c.o === j); /* polygons with current option */
C[`${OPTS[j]}Style`] = THEME[i]; /* set stroke or fill */
C.beginPath();
o.forEach(c => {
let coords = c.coords; /* current poly absolute coordinate array */
for(let k = 0; k <= c.n; k++)
C[`${FN[0**k]}To`](...coords[k%c.n])
});
C.closePath();
C[OPTS[j]]();
}
}
requestAnimationFrame(draw)
};
function init() {
for(let i = 0; i < N; i++) {
for(let j = 0; j < N; j++) {
POLY.push(new Poly(i, j));
}
}
C.globalCompositeOperation = 'overlay';
draw();
};
init();
```

999px

Also see: Tab Triggers