diff --git a/art/Spooky-Anoushka/index.js b/art/Spooky-Anoushka/index.js index 469655aec..8837f71d0 100644 --- a/art/Spooky-Anoushka/index.js +++ b/art/Spooky-Anoushka/index.js @@ -8,68 +8,78 @@ const width = 125; const height = 125; setDocDimensions(width, height); -function generateWing(x, y, size, flip = 1) { - return bt.catmullRom([ - [x, y], - [x + flip * size * 0.25, y - size * 0.2], - [x + flip * size * 0.5, y - size * 0.5], - [x + flip * size * 0.25, y - size * 0.8], - [x, y - size * 0.6], - ]); -} - -function generateBat(x, y, size) { - const body = [ - [x - size * 0.1, y - size * 0.6], - [x + size * 0.1, y - size * 0.6], - ]; - - const leftWing = generateWing(x - size * 0.1, y - size * 0.6, size, -1); - const rightWing = generateWing(x + size * 0.1, y - size * 0.6, size, 1); - - return [...body, ...leftWing, ...rightWing]; -} - -const bats = []; -const batCount = 10; - -for (let i = 0; i < batCount; i++) { - const x = Math.random() * width; - const y = Math.random() * height; - const size = Math.random() * 20 + 10; - const bat = generateBat(x, y, size); - - bats.push(bat); -} - -function drawSpiderWeb(centerX, centerY, radius, layers) { - const radialCount = 12; - const angleStep = (2 * Math.PI) / radialCount; +function generateWeb(centerX, centerY, radius, layers) { + const polylines = []; + const radials = 12; + const angleStep = (2 * Math.PI) / radials; - const circles = []; for (let i = 1; i <= layers; i++) { const layerRadius = (radius / layers) * i; const points = []; - for (let angle = 0; angle <= 2 * Math.PI; angle += 0.2) { + for (let j = 0; j < radials; j++) { + const angle = j * angleStep; const x = centerX + Math.cos(angle) * layerRadius; const y = centerY + Math.sin(angle) * layerRadius; points.push([x, y]); } - circles.push(bt.resample([points], 1)[0]); + points.push(points[0]); + polylines.push(points); } - const radials = []; - for (let i = 0; i < radialCount; i++) { + for (let i = 0; i < radials; i++) { const angle = i * angleStep; - const x = centerX + Math.cos(angle) * radius; - const y = centerY + Math.sin(angle) * radius; - radials.push([[centerX, centerY], [x, y]]); + const line = [ + [centerX, centerY], + [centerX + Math.cos(angle) * radius, centerY + Math.sin(angle) * radius], + ]; + polylines.push(line); } - return [...circles, ...radials]; + return polylines; } -const spiderWeb = drawSpiderWeb(width / 2, height / 2, 80, 6); +function generateBat(x, y, size) { + const wingSpan = size * 2; + const wingDip = size * 0.5; + const bodyWidth = size * 0.6; + const bodyHeight = size * 1.2; + + const bat = bt.catmullRom([ + [x, y], + [x - wingSpan / 2, y - size * 0.3], + [x - wingSpan * 0.75, y - wingDip], + [x - wingSpan, y - size], + [x - wingSpan * 0.75, y - size * 1.5], + [x - bodyWidth, y - bodyHeight], + [x, y - bodyHeight * 1.5], + [x + bodyWidth, y - bodyHeight], + [x + wingSpan * 0.75, y - size * 1.5], + [x + wingSpan, y - size], + [x + wingSpan * 0.75, y - wingDip], + [x + wingSpan / 2, y - size * 0.3], + [x, y], + ]); + return [bat]; +} + +function generateBats(numBats) { + const bats = []; + for (let i = 0; i < numBats; i++) { + const x = Math.random() * width; + const y = Math.random() * height; + const size = 8 + Math.random() * 12; + bats.push(...generateBat(x, y, size)); + } + return bats; +} + +const web = generateWeb(width / 2, height / 2, 80, 6); +const bats = generateBats(8); + +const design = [...web, ...bats]; + +drawLines(design, { strokeStyle: 'black', lineWidth: 1.5 }); + const design = [...spiderWeb, ...bats];