By Ruth Ikegah, Jules Kris
This tutorial provides a practical approach to learning how to use the core concepts of p5.js and the Document Object Model (DOM) by building a simple Game Boy emulator in the p5.js Web Editor. You’ll learn how p5.js works with HTML and CSS, its architecture, and p5.Element
functions for creating and styling HTML elements. At the end of this tutorial, you will successfully develop a retro-style Game Boy emulator capable of running a basic snake game.
This tutorial is the first in a series of tutorials on Web Design. Check out the final sketch example you will complete at the end of the Web Design tutorial series!
At the end of this first tutorial, your sketch should look something like this:
Prerequisites:
Before you begin you should understand or have:
- The desire, curiosity and willingness to learn and experiment are the most important prerequisites!
- How to use the p5.js Web Editor to create and save p5.js projects
- The final project in this tutorial requires that you understand the basic concepts of p5.js included in the Variables and Change tutorial from the Introduction to p5.js tutorials chapter
This tutorial is designed for learners of all levels, so don’t worry if you’re new to coding – that’s what we’re here to guide you through!
Project setup
Step 1 – Open the p5.js Web Editor on your browser and sign into your account
When you launch the p5.js Web Editor and click on the arrow on the text editor next to the file name sketch.js
, you should see index.html
, sketch.js
, and style.css
files like in the image above. Click the play icon in the upper left corner to see your result in the preview window. To see your changes in real-time, select Auto-refresh.
In order to save your progress, be sure to be logged into your p5.js Web Editor account. Rename to “HTML and CSS practice” and save your sketch.
HTML
The preloaded index.html
file has a standard HTML5 document with tags
and
attributes
.
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.8.0/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.8.0/addons/p5.sound.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" />
</head>
<body>
<main>
</main>
<script src="sketch.js"></script>
</body>
</html>
\n \n \n \n \n \n