Skip to content

Commit

Permalink
randomly generates emojy each time
Browse files Browse the repository at this point in the history
  • Loading branch information
anuradha-lakruwan authored Oct 16, 2024
1 parent c40a3d8 commit 02b9bce
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions art/DynamicEmoji-Anuradha/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -27,7 +25,6 @@ function approximateCircle(center, radius, segments = 32) {
return points;
}


function generateHair(numHairs) {
const hairs = [];
const centerX = width / 2;
Expand All @@ -52,7 +49,6 @@ function generateHair(numHairs) {
return hairs;
}


function generateEmoji(type) {
const finalLines = [];

Expand Down Expand Up @@ -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);

0 comments on commit 02b9bce

Please sign in to comment.