Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Creating a Squid Game Card in HTML
Edwin Torres
Edwin Torres

Posted on

     

Creating a Squid Game Card in HTML

I really enjoyed theNetflix seriesSquid Game. The series was intense 😱, and I’m a big fan now.

So I decided to write a quick HTML canvas program to display a Squid Game card. No worries. No spoilers here!

It’s a short and simple HTML program. Let's walk through the code.

Here are the beginning HTML elements:

<!DOCTYPE html><htmllang="en"><head><title>SG</title></head>
Enter fullscreen modeExit fullscreen mode

Next are the start of the body and the canvas elements:

<body><canvasid="myCanvas"width="336"height="192"></canvas>
Enter fullscreen modeExit fullscreen mode

JavaScript code comes next. Here we get the canvas and context objects:

<script>varcanvas=document.getElementById("myCanvas");varctx=canvas.getContext("2d");
Enter fullscreen modeExit fullscreen mode

The context object lets us set colors, set styles, and draw. This code draws a filled rectangle with the specified fill color on the entire canvas, representing the business card background:

ctx.fillStyle="#E2C4A5";ctx.fillRect(0,0,canvas.width,canvas.height);
Enter fullscreen modeExit fullscreen mode

The context object also lets us set the stroke width and color of the shape outlines:

ctx.lineWidth=5;ctx.strokeStyle="#655451";
Enter fullscreen modeExit fullscreen mode

Next are the circle, triangle, and square:

ctx.beginPath();ctx.arc(105,96,25,0,2*Math.PI);ctx.stroke();ctx.beginPath();ctx.moveTo(143,121);ctx.lineTo(193,121);ctx.lineTo(168,71);ctx.lineTo(143,121);ctx.stroke();ctx.beginPath();ctx.rect(215,71,50,50);ctx.stroke();
Enter fullscreen modeExit fullscreen mode

Finally, we end the program with the closing tags:

</script></body></html>
Enter fullscreen modeExit fullscreen mode

Here's the complete program:

<!DOCTYPE html><htmllang="en"><head><title>SG</title></head><body><canvasid="myCanvas"width="336"height="192"></canvas><script>varcanvas=document.getElementById("myCanvas");varctx=canvas.getContext("2d");ctx.fillStyle="#E2C4A5";ctx.fillRect(0,0,canvas.width,canvas.height);ctx.lineWidth=5;ctx.strokeStyle="#655451";ctx.beginPath();ctx.arc(105,96,25,0,2*Math.PI);ctx.stroke();ctx.beginPath();ctx.moveTo(143,121);ctx.lineTo(193,121);ctx.lineTo(168,71);ctx.lineTo(143,121);ctx.stroke();ctx.beginPath();ctx.rect(215,71,50,50);ctx.stroke();</script></body></html>
Enter fullscreen modeExit fullscreen mode

Save this program to a file namedsg.html and open it in a browser.

Enjoy the program and Squid Game! 😀

Follow me on Twitter@realEdwinTorres for more programming tips and help.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Department Chief Engineer @MITREcorp. CS professor @monmouthu. Proud husband and father ❤️. My tweets are my own.
  • Location
    NJ
  • Education
    Doctor of Engineering, George Washington University
  • Work
    Principal Software Engineer at MITRE
  • Joined

More fromEdwin Torres

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp