diff --git a/art/self_portrait-kieran/index.js b/art/self_portrait-kieran/index.js new file mode 100644 index 000000000..ed2f061ff --- /dev/null +++ b/art/self_portrait-kieran/index.js @@ -0,0 +1,112 @@ +// a self portrait by kieran + +const width = 300 +const height = 300; + +setDocDimensions(width, height); + +const svg = String.raw` Created by potrace 1.10, written by Peter Selinger 2001-2011 ` + +const face = createTurtle().fromSVG(svg); +face.scale([0.048, 0.048]); +face.translate([-2631, -2847]) + +for (let i = 0; i < 2; i++) { + const noiseface = createTurtle().fromSVG(svg); + noiseface.scale([0.0475 + (i * 0.0002), 0.0475 + (i * 0.0002)]); + noiseface.translate([-2631, -2847]) + noiseface.iteratePath((pt, tValue) => { + const [x, y] = pt + pt[0] += noise(y * 7.3) * rand() * (i * 3 + 4) + Math.sin(y * 0.42) + if (rand() < 0.97) return pt + if (rand() < lerp(0, 1, 0.20 * tValue ** 2)) return 'BREAK' + if (rand() < 0.44) return 'BREAK' + }) + face.join(noiseface) + face.resample(randInRange(1, i * 5)) +} + +const background = createTurtle(); + +function isPointInsidePolygon(pt, polygon) { + const x = pt[0]; + const y = pt[1]; + let inside = false; + + for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) { + const xi = polygon[i][0]; + const yi = polygon[i][1]; + const xj = polygon[j][0]; + const yj = polygon[j][1]; + + const intersect = + yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi; + + if (intersect) { + inside = !inside; + } + } + + return inside; +} + +// Draw shading only outside the polygon +for (let i = 0; i < 75; i++) { + for (let n = 0; n < 75; n++) { + const polygonVertices = [ + [285, 0], + [285, 15], + [273, 48], + [202, 88], + [228, 141], + [223, 161], + [234, 236], + [218, 267], + [184, 286], + [145, 295], + [126, 289], + [99, 263], + [105, 257], + [92, 245], + [87, 222], + [94, 198], + [82, 214], + [81, 190], + [83, 170], + [89, 146], + [110, 124], + [103, 104], + [93, 88], + [24, 48], + [14, 34], + [26, 42], + [64, 65], + [75, 65], + [75, 74], + [87, 77], + [110, 96], + [124, 60], + [173, 34], + [194, 43], + [199, 81], + [267, 42], + ]; + + const pointToCheck = [1 + i * 4, 2 + n * 4]; + + if (!isPointInsidePolygon(pointToCheck, polygonVertices)) { + for (let m = 0; m < 3; m++) { + background.jump([1 + i * 4, 2 + n * 4]); + background.forward(2); + } + } + } +} + +face.resample(randInRange(1, 10)) +background.resample(1) + +drawTurtles([ + face, + background +]); \ No newline at end of file diff --git a/art/self_portrait-kieran/snapshots/snapshot-1.png b/art/self_portrait-kieran/snapshots/snapshot-1.png new file mode 100644 index 000000000..35392a4c0 Binary files /dev/null and b/art/self_portrait-kieran/snapshots/snapshot-1.png differ diff --git a/art/self_portrait-kieran/snapshots/snapshot-2.png b/art/self_portrait-kieran/snapshots/snapshot-2.png new file mode 100644 index 000000000..06cd33c30 Binary files /dev/null and b/art/self_portrait-kieran/snapshots/snapshot-2.png differ diff --git a/art/self_portrait-kieran/snapshots/snapshot-3.png b/art/self_portrait-kieran/snapshots/snapshot-3.png new file mode 100644 index 000000000..3679d74d2 Binary files /dev/null and b/art/self_portrait-kieran/snapshots/snapshot-3.png differ