/** * Playing with the roots of one. * * Web: https://codepen.io/duzun/full/PeMrNX/ * Ported from Pascal: https://dcms.duzun.me/filebrowser.html?file=programming/pascal/graph/Armonie.pas */ /*jshint esversion: 6, browser: true */ // cx,cy,ex,ey,r,o,s,ls,i: word; // i2, cl, k, inter: real; function id(i) { return document.getElementById(i); } function log() { id('out').innerText += [].join.call(arguments, ', ') + '\n'; } function showColor(color) { let c = id('color'); c.style.backgroundColor = color; c.style.color = '#' + (~parseInt(color.slice(1), 16)&0xFFFFFF).toString(16).padStart(6, '0'); c.innerText = color; } function showOrder(o) { let c = id('order'); c.innerText = o; } var c = id("canvas"); var ctx = c.getContext("2d"); let ex = c.width / 2; let ey = c.height / 2; let r = (ex+ey) / 3; function setCanvasSize() { let e = document.documentElement || document.body; let h = e.offsetHeight; let w = e.offsetWidth; r = Math.min(h-70, w); c.width = r; c.height = r; ex = r >>> 1; ey = r >>> 1; r = (ex+ey) / 3; } let inter = 0.005; let i2 = inter; let k = 0; let o = 1; let ts = Date.now(); let s = (ts / 1e3) % 60; let ls = s+15; function repeat() { ts = Date.now(); s = (ts / 1e3) % 60; let k1 = k; let n = 0; let color; do { ++n; let cx = ex-r*Math.cos(2*Math.PI*k/o+k)/2; let cy = ey-r*Math.sin(2*Math.PI*k/o+k)/2; for(let i=0; i