Skip to content

Instantly share code, notes, and snippets.

@prof3ssorSt3v3
Created January 10, 2019 16:04
Show Gist options
  • Save prof3ssorSt3v3/dbfb6380065c88ff39cb82acf33ba0a7 to your computer and use it in GitHub Desktop.
Save prof3ssorSt3v3/dbfb6380065c88ff39cb82acf33ba0a7 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
#canvas{
border: 1px solid red;
width: 70%;
height: auto;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
let canvas, ctx;
document.addEventListener('DOMContentLoaded', ()=>{
canvas = document.getElementById('canvas');
canvas.width = 600;
canvas.height = 400;
ctx = canvas.getContext('2d');
let cx = canvas.width/2;
let cy = canvas.height/2;
ctx.fillStyle = '#bada55';
ctx.strokeStyle = '#333';
ctx.lineWidth = 3;
ctx.beginPath();
ctx.moveTo(cx, cy);
ctx.arc(cx, cy, 100, 0, Math.PI*2);
ctx.fill();
ctx.closePath();
//right eye
ctx.fillStyle = '#333';
ctx.strokeStyle = '#333';
ctx.beginPath();
ctx.moveTo(cx-50, cy);
ctx.arc(cx-50, cy, 25, Math.PI*0.25, Math.PI*1.25);
ctx.fill();
ctx.closePath();
//left eye
ctx.beginPath();
ctx.moveTo(cx+50, cy);
ctx.arc(cx+50, cy, 25, -Math.PI*0.25, Math.PI*0.75 );
ctx.fill();
ctx.closePath();
//mouth
ctx.beginPath();
ctx.moveTo(cx-50, cy+50);
ctx.lineTo(cx+50, cy+50);
ctx.stroke();
ctx.closePath();
//speach bubble
ctx.beginPath();
ctx.moveTo(cx+100, cy-20);
ctx.lineTo(cx+130, cy-100);
ctx.lineTo(cx+100, cy-100);
ctx.lineTo(cx+100, cy-150);
ctx.lineTo(cx+260, cy-150);
ctx.lineTo(cx+260, cy-100);
ctx.lineTo(cx+140, cy-100);
ctx.lineTo(cx+100, cy-20);
ctx.stroke();
ctx.closePath();
//msg
ctx.beginPath();
ctx.textAlign = 'start';
ctx.font = 'normal 30px Arial';
ctx.fillText('$%@#@!', cx+110, cy-120);
ctx.closePath();
//IMAGES
// let img = document.createElement('img');
// img.addEventListener('load', ()=>{
// let w = img.naturalWidth;// * 0.3;
// let h = img.naturalHeight;// * 0.3;
// ctx.drawImage(img, 350, 0, 550, 180, 0, 0, w, h);
// })
// img.src = "./picsum.jpeg";
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment