const { PI: pi } = Math;
// draw on canvas drawing context
drawOnCanvas2D('#playground', (ctx) => {
const rainbowStops = [
[0, 'red'], [0.2, 'orange'], [0.4, 'yellow'], [0.6, 'green'], [0.7, 'cyan'],
[0.8, 'purple'], [0.9, 'pink'], [1.0, 'red'],
];
// linear gradient;
ctx.fillStyle = ctx.gradient('linear', [10,10,10,190], rainbowStops);
ctx.fillRect(10, 10, 10, 180);
ctx.fillRect(30, 20, 40, 50);
ctx.fillRect(30, 80, 40, 30);
ctx.fillRect(30, 120, 40, 30);
// radial gradient
ctx.fillStyle = ctx.gradient('radial', [200,100,50, 200,100,100], [
[0.0, 'transparent'],
[0.5, 'hsl(60 90% 50%)'],
[0.7, 'hsl(40 90% 50%)'],
[1.0, 'transparent'],
]);;
ctx.beginPath();
ctx.arc(200, 100, 100, 0, 2 * pi);
ctx.fill();
ctx.stroke();
// conic gradient
ctx.fillStyle = ctx.gradient('conic', [-pi/2, 200, 100], rainbowStops);
ctx.beginPath();
ctx.arc(200, 100, 50, 0, 2 * pi);
ctx.fill();
});