### Spiral clock

Show multiple days worth of time on a single clock! It makes perfect sense if you don't think about it too hard.

```// LL 2021

const hours = -1; // min=-1 max=11 step=1
const minutes = -1; // min=-1 max=59 step=1
const seconds = -1; // min=-1 max=59 step=1
const draw_seconds = 2; // min=0 max=2 step=1 (Yes, No, Maybe)
const draw_hatching = 2; // min=0 max=2 step=1 (Yes, No, Maybe)
const loops = -0.5; // min=-0.5 max=10.5 step=1
const animation = 0; // min=0 max=1 step=0.01

const turtle = new Turtle();

var polygons = null;

var animated_seconds = seconds;

const scale = 95;

const hours_to_draw = (hours >= 0) ? hours : Math.floor(Math.random() * 12);
const minutes_to_draw = (minutes >= 0) ? minutes : Math.floor(Math.random() * 60);
const seconds_to_draw = (seconds >= 0) ? seconds : Math.floor(Math.random() * 60);
const loops_to_draw = (loops >= 0) ? loops : Math.floor(Math.random() * 5) + 1.5;
const hatching_to_draw = (draw_hatching==0) || ((draw_hatching==2) && (Math.random()<0.5));

Canvas.setpenopacity(.75);

const start_angle = -Math.PI / 2;
return Array.from( {length: steps}, (_, id) => (
[ Math.cos(id / steps * Math.PI*2 + start_angle) * radius, Math.sin(id / steps * Math.PI*2 + start_angle) * radius ]
));
}

function getLength(x, y) {
return Math.sqrt(x*x + y*y);
}

function getTickAngle(t) {
return t / 60 * Math.PI * 2 + Math.PI / 2;
}

const thickness = 0.015 * scale;

const angle1 = getTickAngle(t-0.1);
const angle2 = getTickAngle(t+0.1);

var points = [];
const angle_offset = 0.01;

return points;
}

for (var t=0; t<=60 * loops_to_draw; t++) {
var points = getTickPoints(t, 0.1, 1);

const p1 = polygons.create();
if (hatching_to_draw) p1.addHatching(t / 60 * Math.PI * 2, .6);
polygons.draw(turtle, p1, true);
}

const p2 = polygons.create();
polygons.draw(turtle, p2, false);
}
}
}

const points = getCirclePoints(radius * scale, steps);

const p1 = polygons.create();

if (hatching) if (hatching_to_draw) p1.addHatching(Math.PI/4, 1);
polygons.draw(turtle, p1, true);

if (shadow !== undefined && hatching_to_draw) {
const p2 = polygons.create();
polygons.draw(turtle, p2, false);
}
}

function drawHand(value, thickness, length, shadow, hatching=false) {
const start_angle = -Math.PI/2 + value * Math.PI*2;

const points = Array.from( {length: 4}, (_, id) => {
return [ Math.cos(start_angle + id / 4 * Math.PI*2) * radius, Math.sin(start_angle + id / 4 * Math.PI*2) * radius ];
});

const p1 = polygons.create();
if (hatching) if (hatching_to_draw) p1.addHatching(Math.PI/4, 1);
polygons.draw(turtle, p1, true);

if (shadow !== undefined && hatching_to_draw) {
const p2 = polygons.create();
polygons.draw(turtle, p2, false);
}

}

const thickness = 0.01 * scale;
const steps_per_loop = 100;
const steps = loops * steps_per_loop;
var points = [];
for (var i=0; i<steps; i++) {
const angle = i / steps_per_loop * Math.PI * 2 + Math.PI / 1.9;

const p1 = [ Math.cos(angle) * (r - thickness), Math.sin(angle) * (r - thickness) ];
const p2 = [ Math.cos(angle) * (r + thickness), Math.sin(angle) * (r + thickness) ];

points.push( p1 );
points.unshift( p2 );
}

const p1 = polygons.create();
polygons.draw(turtle, p1, true);
}

const p2 = polygons.create();
polygons.draw(turtle, p2, false);
}
}

}

function drawCenter() { drawCircle(0.05, 20, [0.5, 0.5], true); }

function drawHourHand() {
const hour_value = hours_to_draw / 12 + minutes / 60 / 12 + animated_seconds / 60 / 60 / 12;
drawHand(hour_value, 0.045, 0.5, [1, 1]);
}

function drawMinuteHand() {
const minute_value = minutes_to_draw / 60 + animated_seconds / 60 / 60;
drawHand(minute_value, 0.045, 0.84, [1, 1]);
}
function drawSecondHand() {
if (draw_seconds == 1) return;
if (draw_seconds == 2 && Math.random() < 0.5) return;

const second_value = animated_seconds / 60;
drawHand(second_value, 0.025, 0.84, [1, 1], true);
}

function walk(i, t) {
animated_seconds = seconds_to_draw + 12 * 60 * 60 * (t+animation);

if (i ==0) polygons = new Polygons();

var index = 0;
if (false) {}
else if (i == index++) drawCenter();
else if (i == index++) drawSecondHand();
else if (i == index++) drawMinuteHand();
else if (i == index++) drawHourHand();
else if (i == index++) drawCase(false);
else if (i == index++) drawTicks(false);
else if (i == index++) drawCase(true);
else if (i == index++) drawTicks(true);
else return false;

return true;
}

// Transforms. Created by Reinder Nijhoff 2019 - @reindernijhoff
// https://turtletoy.net/turtle/a5befa1f8d
//

////////////////////////////////////////////////////////////////
// Polygon Clipping utility code - Created by Reinder Nijhoff 2019
// https://turtletoy.net/turtle/a5befa1f8d
////////////////////////////////////////////////////////////////

function Polygons() {
const polygonList = [];
const Polygon = class {
constructor() {
this.cp = [];       // clip path: array of [x,y] pairs
this.dp = [];       // 2d lines [x0,y0],[x1,y1] to draw
this.aabb = [];     // AABB bounding box
}
// add point to clip path and update bounding box
let xmin = 1e5, xmax = -1e5, ymin = 1e5, ymax = -1e5;
(this.cp = [...this.cp, ...points]).forEach( p => {
xmin = Math.min(xmin, p[0]), xmax = Math.max(xmax, p[0]);
ymin = Math.min(ymin, p[1]), ymax = Math.max(ymax, p[1]);
});
this.aabb = [(xmin+xmax)/2, (ymin+ymax)/2, (xmax-xmin)/2, (ymax-ymin)/2];
}
// add segments (each a pair of points)
points.forEach(p => this.dp.push(p));
}
for (let i = 0, l = this.cp.length; i < l; i++) {
this.dp.push(this.cp[i], this.cp[(i + 1) % l]);
}
}
draw(t) {
for (let i = 0, l = this.dp.length; i < l; i+=2) {
t.jump(this.dp[i]), t.goto(this.dp[i + 1]);
}
}
const tp = new Polygon();
tp.cp.push([-1e5,-1e5],[1e5,-1e5],[1e5,1e5],[-1e5,1e5]);
const dx = Math.sin(a) * d,   dy = Math.cos(a) * d;
const cx = Math.sin(a) * 200, cy = Math.cos(a) * 200;
for (let i = 0.5; i < 150 / d; i++) {
tp.dp.push([dx * i + cy,   dy * i - cx], [dx * i - cy,   dy * i + cx]);
tp.dp.push([-dx * i + cy, -dy * i - cx], [-dx * i - cy, -dy * i + cx]);
}
tp.boolean(this, false);
this.dp = [...this.dp, ...tp.dp];
}
inside(p) {
let int = 0; // find number of i ntersection points from p to far away
for (let i = 0, l = this.cp.length; i < l; i++) {
if (this.segment_intersect(p, [0.1, -1000], this.cp[i], this.cp[(i + 1) % l])) {
int++;
}
}
return int & 1; // if even your outside
}
boolean(p, diff = true) {
// bouding box optimization by ge1doot.
if (Math.abs(this.aabb[0] - p.aabb[0]) - (p.aabb[2] + this.aabb[2]) >= 0 &&
Math.abs(this.aabb[1] - p.aabb[1]) - (p.aabb[3] + this.aabb[3]) >= 0) return this.dp.length > 0;

// polygon diff algorithm (narrow phase)
const ndp = [];
for (let i = 0, l = this.dp.length; i < l; i+=2) {
const ls0 = this.dp[i];
const ls1 = this.dp[i + 1];
// find all intersections with clip path
const int = [];
for (let j = 0, cl = p.cp.length; j < cl; j++) {
const pint = this.segment_intersect(ls0, ls1, p.cp[j], p.cp[(j + 1) % cl]);
if (pint !== false) {
int.push(pint);
}
}
if (int.length === 0) {
// 0 intersections, inside or outside?
if (diff === !p.inside(ls0)) {
ndp.push(ls0, ls1);
}
} else {
int.push(ls0, ls1);
// order intersection points on line ls.p1 to ls.p2
const cmpx = ls1[0] - ls0[0];
const cmpy = ls1[1] - ls0[1];
int.sort( (a,b) =>  (a[0] - ls0[0]) * cmpx + (a[1] - ls0[1]) * cmpy -
(b[0] - ls0[0]) * cmpx - (b[1] - ls0[1]) * cmpy);

for (let j = 0; j < int.length - 1; j++) {
if ((int[j][0] - int[j+1][0])**2 + (int[j][1] - int[j+1][1])**2 >= 0.001) {
if (diff === !p.inside([(int[j][0]+int[j+1][0])/2,(int[j][1]+int[j+1][1])/2])) {
ndp.push(int[j], int[j+1]);
}
}
}
}
}
return (this.dp = ndp).length > 0;
}
//port of http://paulbourke.net/geometry/pointlineplane/Helpers.cs
segment_intersect(l1p1, l1p2, l2p1, l2p2) {
const d   = (l2p2[1] - l2p1[1]) * (l1p2[0] - l1p1[0]) - (l2p2[0] - l2p1[0]) * (l1p2[1] - l1p1[1]);
if (d === 0) return false;
const n_a = (l2p2[0] - l2p1[0]) * (l1p1[1] - l2p1[1]) - (l2p2[1] - l2p1[1]) * (l1p1[0] - l2p1[0]);
const n_b = (l1p2[0] - l1p1[0]) * (l1p1[1] - l2p1[1]) - (l1p2[1] - l1p1[1]) * (l1p1[0] - l2p1[0]);
const ua = n_a / d;
const ub = n_b / d;
if (ua >= 0 && ua <= 1 && ub >= 0 && ub <= 1) {
return [l1p1[0] + ua * (l1p2[0] - l1p1[0]), l1p1[1] + ua * (l1p2[1] - l1p1[1])];
}
return false;
}
};
return {
list: () => polygonList,
create: () => new Polygon(),
draw: (turtle, p, addToVisList=true) => {
for (let j = 0; j < polygonList.length && p.boolean(polygonList[j]); j++);
p.draw(turtle);