From 02b9bceb66ffa4422a73222e0d2ed8e6cc87a713 Mon Sep 17 00:00:00 2001 From: Anuradha Lakruwan <128252764+anuradha-lakruwan@users.noreply.github.com> Date: Wed, 16 Oct 2024 22:08:33 +0530 Subject: [PATCH] randomly generates emojy each time --- art/DynamicEmoji-Anuradha/index.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/art/DynamicEmoji-Anuradha/index.js b/art/DynamicEmoji-Anuradha/index.js index 6497755a3..a0929adab 100644 --- a/art/DynamicEmoji-Anuradha/index.js +++ b/art/DynamicEmoji-Anuradha/index.js @@ -9,11 +9,9 @@ setDocDimensions(width, height); // Variables const eyeRadius = 5; -const numHairs = 47; // number of hairs const headCenter = [width / 2, height / 2]; const headRadius = 50; - function approximateCircle(center, radius, segments = 32) { const angleStep = (2 * Math.PI) / segments; const points = []; @@ -27,7 +25,6 @@ function approximateCircle(center, radius, segments = 32) { return points; } - function generateHair(numHairs) { const hairs = []; const centerX = width / 2; @@ -52,7 +49,6 @@ function generateHair(numHairs) { return hairs; } - function generateEmoji(type) { const finalLines = []; @@ -148,19 +144,22 @@ function generateEmoji(type) { bt.join(finalLines, [leftEyebrow]); bt.join(finalLines, [rightEyebrow]); - const hairs = generateHair(numHairs); bt.join(finalLines, hairs); - const finalBounds = bt.bounds(finalLines); const finalScale = width / finalBounds.width * 0.93; bt.scale(finalLines, finalScale); bt.translate(finalLines, [width / 2, height / 2], bt.bounds(finalLines).cc); - drawLines(finalLines); } -// different types of emojis -generateEmoji('sad'); //'sad', 'happy', 'angry','surprised' +// no of hairs in randomly multiples of 6 +const numHairs = Math.floor(Math.random() * 10) * 6; + +// select the emoji type randomy +const emojiTypes = ['sad', 'happy', 'angry', 'surprised']; +const randomEmojiType = emojiTypes[Math.floor(Math.random() * emojiTypes.length)]; + +generateEmoji(randomEmojiType);