function circlePath(radius) { let arc = d3.arc().outerRadius(radius); return arc({ startAngle: 0, endAngle: 8 }) } function rectPath(width,height) { return "M0,0L" + width + ",0L" + width + "," + height + "L0," + height + "Z" } function linePath(x1,x2,y1,y2) { return "M" + x1 + "," + y1 + "L" + x2 + "," + y2 + "L" } function jitterLine (pathNode) { let length = pathNode.getTotalLength(); let j = 2; let x = j + Math.random() * j * 5; let jitteredPoints = []; let lineGen = d3.line() .x(d => d.x) .y(d => d.y) .curve(d3.curveCatmullRom.alpha(0.5)); let newPoint = pathNode.getPointAtLength(0); jitteredPoints.push(newPoint); while (x < length) { newPoint = pathNode.getPointAtLength(x); let newX = newPoint.x + (Math.random() * j - j/2); let newY = newPoint.y + (Math.random() * j - j/2) jitteredPoints.push({ x: newX, y: newY }) x += j + Math.random() * j * 5; } newPoint = pathNode.getPointAtLength(length); jitteredPoints.push(newPoint); return lineGen(jitteredPoints); } function cheapSketchy(path) { let length = path.getTotalLength(); let drawCode = ""; let x = 0; let step = 8; while (x < length / 2) { let start = path.getPointAtLength(x); let end = path.getPointAtLength(length - x); drawCode += " M" + (start.x + (Math.random() * step - step/2)) + " " + (start.y + (Math.random() * step - step/2)) + "L" + (end.x + (Math.random() * step - step/2)) + " " + (end.y + (Math.random() * step - step/2)); x += step + Math.random() * step; } return drawCode; } function cheapPopArtsy (path) { let length = path.getTotalLength(); let circles = [] let x = 0; let step = 8; while (x < length / 2) { let start = path.getPointAtLength(x); let end = path.getPointAtLength(length - x); let begin = 0.75 while (begin < step) { const percent = begin / step const circleXa = percent * start.x const circleXb = (1 - percent) * end.x const circleYa = percent * start.y const circleYb = (1 - percent) * end.y circles.push([circleXa + circleXb, circleYa + circleYb]) begin = begin + (1 + Math.random()) } x = x + step } return circles; } randomColor = function (baseColor,range) { var hslBase = d3.hsl(baseColor) hslBase.h = hslBase.h + (Math.floor(Math.random() * (range * 255)) - Math.floor(range / 2)); hslBase.s = hslBase.s + (Math.floor(Math.random() * range) - Math.floor(range / 2)); hslBase.l = hslBase.l + (Math.floor(Math.random() * range) - Math.floor(range / 2)); return hslBase.toString(); }