A Canvas Rect or Box class design, movement and other relevant topics

The concept of a simple 2d Box class is something that I keep coming back to when it comes to playing around with html 5 canvas, and making all kinds of fun and interesting projects with it. In any canvas project I typically do want to make at least a few classes that are closely related to canvas. That is something involving a constructor function that creates an instance of an object that has at least the basic properties of a 2d box or rectangle. Then in addition to just the main constructor function, have at least a few methods that act on those properties in the prototype object of that constructor function. There is also choosing not to do that, and take a more functional approach to doing the same thing, but with stand alone pure functions rather than prototype object methods that some may prefer to do in place of making a class.

For example if I am making a game I will want some kind of enemy class, but I would also want some kind of base class that the class inherits from as well that is shared by all classes that are a display object of sorts in such a game. So a box class would make a good starting base class for all kinds of display objects in a game beyond that of just enemies. The player ship, power ups, and shots coming from player and enemy ships would all inherit from this box class.

Also because a lot of applications have to do with manipulation of simple 2d areas on a screen, having a solid understanding of how to go about making, or using some kind of box or sprite class if you prefer can become important. Taking the time to make a box class strikes me as something that is a good example of an exercise that can often progress into an interesting project of some kind when it comes to expanding from there in all kinds of different ways when it comes to everything that might end up being developer around such a class or module. It has helped me gain a better understand of 2d geometry, and also the nature of a class.

Read More

javaScript blog content what to write about.

One of the great things about writing a blog on javaScript is that there is never a shortage of things to write about. It’s not like I have to write about a single line of products, form a single brand, and as such there is only so much to cover until I start repeating myself. With javaScript there is an ocean of content potential to be taped into, but that can also be my undoing. It is easy to get overwhelmed, as such I thought it might be a good idea to throw together some ideas on this matter.

Read More

How to style terminal output text with node.js using chalk

When making any kind of node.js project that may involve output to the command line interface, it may be desired to style that output, for the sake of adding emphases, or just to make it look nice. Many CLI tools make use of color, for one reason or another, so if you want to add color to the output of you node.js CLI tools, you might want to check out chalk. Chalk makes changing the color of a terminal fairly easy, but if you are wondering how chalk works the answer is ANSI escape codes. If you just simply know the codes that you want to use you can just append them to the start and end of a string that you are outputting to the console. Chalk just makes working with ANSI escape codes easy

When I first wrote this post back in may I was using chalk 1.1.3, but as of this writing the latest version is now 2.3.0 as such there are a few new features, and some things just still work the same as aways.

Read More

Working with very big numbers in node.js with big-integer

Want to do some math in a node.js environment involving really big numbers? Then you might want to look into the npm package called big-integer. That is unless you are using a version of node that is 10.4.x or later in which case you might have BigInt support in the node.js environment that you are using. In this post I will be going over some nodejs example that have to do with the big-integer npm package, but if you are using a late version of node I have another post that I have wrote on the BigInt native support that there is for big integers in javaScript now.

Read More

You are not creating it, you are discovering it.

Learning how to code is hard, or at least that seems to be the idea that a lot of people have set in their head. For me I would say that picking up a programming language is the easy part, the real hard part is to get proficient at certain things that lay outside of that of programming. Things that apply not just to a certain programming language, but the creative process in general. So I thought I would write a post that will be the first of what will be a series of posts on discovery. Discovery seems to be a good word to label a certain something that seems to be what is going on when I make an original work of any kind from the ground up, with javaScript, but also any other kind of creative process including writing such as with this very blog post.

Another way to put this would be to ask myself if being creative is a construction or discovery kind of process. That is when I make some kind of creative work, such as a javaScript module, am I constructing code from the ground up, or is it something that was all ready there and I just discovered it. This differs from something like using a library or framework, I am not talking about using other peoples code. I am talking about the code that I myself write, in other words my own vanilla javaScript code. Some may say that I am constructing my own personal code from the ground up, but that is not how I see it, I always feel as though I am just discovering a proof of concept that was all ready up and running in my mind.

Read More