Pool reduction digital art javaScript example
For the last day of the year I wanted to do something fun, so I made yet another quick javaScript example type post, this time it is a kind of digital art project that has to do with an object pool that will reduce in terms of the active count of objects. When it comes to my canvas examples collection of posts I have put together a canvas example that makes use of an object pool module for that example that I will then be using in this javaScript example.
I am thinking that this might just be the first of at least a few javaScript examples where the goal is to just do something artful with canvas elements, and also try to go in some new directions with programing in general while I am in the process of doing so. Often people think in terms of what they can do that is new, or different each time a new year comes around, and there are a whole lot of things that I would like to do that are new with javaScript, as well as with this website for sure. With that said there is treating this javaScript example differently this time around by setting some intentions, and making sure to follow threw with them. For example there is not just getting a crude idea up and working and moving on, but refining and improving the over all structure of the idea in terms of the quality of the source code which is one thing I would like to do with this javaScript example.
The general idea of this example came to me when I was editing my post on the javaScript array reduce method which is of course one of the many methods in the array prototype of native javaScript. What I had in mind was just a collection of display objects that move around on the canvas, and when one or more of them overlap with one all the display objects that overlap will combine into one parent display object. So then eventual all the display objects will end up, well reducing into a single display object. After that there is having some additional code that involves having the display objects split apart again. That is it in terms of the genera idea, and as of this writing I have that general idea up and running, but I would like to continue working on this project at least a little way beyond just having the general idea working.
This object pool reduction digital art javaScript example and what to know before hand
This is a post on a full client side javaScript project example that is just a simple digital art project involving object pools and canvas elements. This is then not in any way a blog post that is intended for people that are new to javaScript in general so if you are still new to javaScript you might want to start out with a getting started post with native javaScript.
The current source code is up on Github
As of this writing I have just finished revision 4 of this javaScript example as I have outlined in the todo list of this javaScript example. This todo list of which I speak, along with the full source code of this javaScript example can be found in my test vjs Github preparatory in the for post folder that corresponds with the name of this blog post. This should be the case with my many other javaScript project example posts, as well as with all my various blog posts on javaScript in general.
1 - The utilities library for this javaScript example
First off I have the utilities library for this javaScript example, just like with many of my other javaScript examples I often have a library such as this as part of the project. In other words this is a custom cut collection of methods that I will be using in one or more additional javaScript files in the rest of the source code, as such I have methods that have to do with various things that will pop up when working on all kinds of various javaScript files.
For this javaScript example project I have a mathematical modulo method as well as my wrap number method that I am using in the game module as of revision 4 of this example. I also have a distance and bounding box methods that are the usual suspect type methods with many projects such as this, they are also used in the object pool module that I am using that I borrowed from another project so I need them for that reason also.
|
|
2 - The object pool module
This is the object pool library that I will be using for this example, which I have started out with by copying what I was using from another javaScript example which would be my turn based rpg game that I was working on. In that javaScript example I was using this module for a circle menu that is being used to navigate threw various menus. In turn I also borrowed that copy of the object pool from another example, and so forth, as this seems to be a module that I keep reusing from one project to another. It would seem that much of this source code is very similar to my canvas example posts on object pools so it would seem that project is when this project started. Sense then I have found a few bugs with it that I have worked out, and I am also seeing some additional features that I wold like to add in additional future revisions of this javaScript example.
Here in this example I am going to be using it to create and update the object pool that will be these various objects that will move around and when they overlay combine into a single object with greater mass. This will happen in the main game module of this over all project example that will make use of the module that I have hear.
|
|
3 - The game module
I have a single javaScript file that will be used to create and update the main game state object of this example. There are aways at least two public methods that I would want in a module such as this, one of which would be a create method that is used to create the starting state of the game, and the other is an update method. In other various examples I might want to have at least a few more methods beyond that, but because this is just a digital art type thing for the most part I will just be needing those two methods.
|
|
4 - The draw module
To display what is going on I am going to need to have to work out a few methods that will have to do with drawing the state of things to a canvas element. With just about any module like this I often have a method that will be used to just draw a background for the example, typically this is just a solid color background. After that I have a method that will draw the current status of the object pool of course, as well as some additional methods that will draw some basic debug into to the canvas element.
|
|
5 - The main javaScript file
I am then just going to need a little more javaScript code that will make use of everything else to create the final end result. In this main javaScript file then I am creating what might eventually become a state machine object. Even though of revision 0 there is not any state objects and I am just updating the game module in the main app loop. Speaking of the app loop that is also where I will be keeping that as you might expect.
|
|
6 - Conclusion
So far this javaScript example is looking good as of revision four at least when I last updated the content of this post to reflect that specific revision. When it comes to plans for additional edits of this post in the future I all ready have some things drafted out in the repository folder for this example. At this point there is not just adding features, as there is not much more that I think that I would want to add to it at this point, the example is more or less done with respect to what it is that I had in mind for this example. So then many of the future edits that I will be getting to when I get to them will have to do with improving the over all structure of the example, rather than adding more to the example in terms of features.