create happy icon in javascript

To create a happy icon in JavaScript, we can use the HTML canvas element and JavaScript to draw the icon. Here's an example code snippet:

<canvas id="happy-icon" width="50" height="50"></canvas>
57 chars
2 lines
index.tsx
const canvas = document.getElementById('happy-icon');
const ctx = canvas.getContext('2d');

// draw face
ctx.beginPath();
ctx.fillStyle = 'yellow';
ctx.arc(25, 25, 20, 0, 2 * Math.PI);
ctx.fill();

// draw eyes
ctx.beginPath();
ctx.fillStyle = 'black';
ctx.arc(18, 20, 3, 0, 2 * Math.PI);
ctx.arc(32, 20, 3, 0, 2 * Math.PI);
ctx.fill();

// draw mouth
ctx.beginPath();
ctx.strokeStyle = 'black';
ctx.lineWidth = 2;
ctx.arc(25, 30, 10, 20, Math.PI - 20);
ctx.stroke();
468 chars
23 lines

In this code, we first get a reference to the canvas element and its 2d context. Then we start drawing the various parts of the icon using the beginPath() method, setting the fill style for the face and eyes, and the stroke style and width for the mouth. Finally, we call fill() and stroke() to render the shape on the canvas.

You can customize this code to create different expressions for your happy icon.

related categories

gistlibby LogSnag