Multidimensional arrays in javaScript

In JavaScript Multidimensional arrays can be implemented in a number of ways. Maybe the most common way is to just have arrays of arrays, however there are other ways of doing so that involve just having a single linear array and a formula to get or set the proper index value in the javaScript array. In addition there is also doing things like having an array of arrays, bit each element is an object and these objects then have an array as one of its properties.

Multidimensional arrays will come up often when it comes to any kind of project that will involve a 2d grid, a 3d plane, tables, or anything else where doing so might be called for when doing something interesting with many dimensions. So having a solid understanding of the different ways to go about having arrays with two or more dimensions is called for when it comes to a wide range of applications where the use of them will come into play. So lets look at some typical examples, as well as some other examples that might be not so typical with multidimensional arrays in javaScript.

Read More

Xserver Xorg, Raspbian lite, and the blackbox desktop environment

When setting up a Rasbian Linux OS, now known as Raspberry PI OS lite clean install, the main reason for doing so is that I might just want to set up a server and not much of anything else. There are maybe some additional reasons why though such as just learning how to work with a Linux system from the command line only, as a lite install of Raspberry PI OS will just be that alone, at least for starters anyway. As such I might not always want, or even need any kind of desktop environment when it comes to this kind of striped now command line only image of the OS.

However often I might want at least some kind of desktop environment if I am still going to have the raspberry pi hooked up to a monitor and not go fully headless. When it comes to that, it might still be best to go with a desktop image rater than the lite version as doing so will make life a little easier. However in some cases I might want to experiment with some desktop environment other than the default LXDE based environment that comes with the desktop version, and not have any additional bloat that I do not want on the OS image. In which case I might want to start out by just installing just the X Window System, and then choose a desktop environment that is very striped down with just the core set of features that I really need.

So In this post I will be going over installing the x window system, and setting up a very simple desktop for X called blackbox in Raspberry PI OS lite. I am not going to actually recommend blackbox as a desktop environment actually, it is generally a good idea to look into other options. However blackbox just happens to be a very light weight desktop environment that I have been aware of for a long time, at it seems like it is still available in many repositories.

Read More

Canvas example of a gradient grid

When working with a canvas element there are ways to quickly paint a gradient to the canvas but todays canvas example is about making something a little more fun and interesting that is similar to that a little. It involves having grid and a pool of objects that are used to set color channel values for each grid cell. So all of this constitutes a model object that is then drawn to the canvas resulting in a cool color gradient type effect that might be kind of cool.

If you are more interested in reading about the 2d drawing context method for drawing gradients I made a post on the plain old canvas gradients if you want to read about that. What I am writing about here is more of a full canvas project example where I am working out my own custom logic for gradient like effects using javaScript code and canvas elements.

I went a little overboard with this example, making a plugin system and a few plugins that have to do with the setting and updating of the behavior of these objects in the object pool that have to do with how the grid gradient changes. there are two types of pulgins one type will define initial conditions of objects, and the others define how objects will change. I have all ready made a number of plugins for this canvas project, and keep experimenting how plugins can be used to take this in all kinds of different directions.

Like many advanced canvas example projects I started breaking things down between code that is used to create and update a main state object, and code that makes that renders that state object to the canvas element. In addition I then have additional code that is used to tie everything together when it comes to a model and view.

So this should be a decent canvas example thus far all ready, and chances are I will come back to it again at least a few times more in the future.

Read More

Getting started with Raspbian Linux lite for raspberry pi

I have come to like the Rasbian Linux OS, and my raspberry pi 3B+. When it comes to looking for a new computer less is more for me these days as I have found that everything that I really want and need to do with a computer does not require a whole lot of overhead. In addition I would like to start writing at least a little more content on Linux, so todays post will be on getting started with Raspbian Linux lite.

There are three general images to choose from when it comes to downloading a Raspbain os image from the raspberry Pi website. There is the desktop with recommended software, desktop, and lite. In often will go with the desktop version as that has all the base software that I want and need, without this additional bloat for doing work that is outside of my little slice when it comes to programing. However in some situations it would make sense to do with a lite image for starters, the light version will be a very basic striped down Linux that does not even have a desktop environment installed. It is not so hard to set one up though, and when doing so I can choose to use a desktop different from the one that is used in the desktop image.

Read More

How to read a client side file with javaScript

Typically when dealing with files in javaScript I am actually dealing with a file that is stored on a server, I then use XMLHttpRequest or some other means as a way to retrieve all or part of that data by way of scripting the HTTP protocol. However it is not like http is the only way to retrieve and post some data over a network, and also in some cases there is going to be a need to read and save data on a clients local file system.

So then there are other ways of getting or saving files remotely, and also ways of storing data locally such as with the web storage API which is often the first go to solution for this sort of thing. However with some projects I might want to read a file on a users local file system rather than data that I am parking by way of the web storage API. Of course I can not just do so for what should be obvious security reasons, however there is a way of doing so that involves allowing the user to select a file that they do not mind giving access to. That is allowing the user to navigate to a location on there local file system, and allow for a file to be saved to loaded there at a given file URI.

Creating and loading files on the users local file system will involve the use of the FileReader constructor in conjunction with file objects and a file list input tag. In this post I will be going over a few basic examples of how to use this as a means of local storage of state.

Read More