Day 19: Canvas and JS Objects

Dan Esmail - 1/19/2023

Intro

Today is another day of research. Research makes me a better programmer since I know more of what is out there and how to use it. Something I have seen before and wanted to work with again is the canvas. It's a great way to draw anything to your website and animated it. Also while working with the canvas it's great to know about javascript objects, and classes. All that together can make something great.

HTML Canvas

Like I said before canvas is great for drawing something to your website. I might use this to make a very simple game. The canvas is an element in HTML and will need an ID. to draw to the canvas you'll need to get context and this will let you refer back to the canvas when you use other functions on it. Once you have the context you can choose from an array of functions to draw things like text, lines, or even shapes. As you draw more things you will be able to use javascript to animate them. This is the very basis of the canvas

JavaScript Objects and Classes

These are great! With an object, you can store a bunch of primitive variables like strings, numbers, and booleans to make something great. What is great? Well, you can make a contact for example with different strings to make up the first name, last name, and phone number. These types of variables are the object's properties. Now anytime you have variables I'm sure you want to use them in functions. Well, you can even put functions in an object. Guess what those are called methods. Now Objects are great but what if you want a bunch of the same objects?

That's where classes come in. classes are the blueprint for an object. Do you want to make a bike object? Well, make it a class and throw in a bunch of properties like, color, wheels, gear count, and more. Then throw in a few methods like horn, ride, and wheele. Now, all that is left is to make a constructor. the constructor is like the machine that takes the blueprint and makes something. Once you put it you could have five bikes if you want or twenty.

All of this will help me continue making my site a little better. you just need to remember everything takes time. My site might look bad now but one year from now it might look better than Netflix's website.



Day 1

Day 1