A friend of mine was talking on Facebook about an odd bit of code he found deep in some code base he was working on. There was some situation where the first item of an array had to be put at the end of the array. I can think of 4 or 5 ways to handle this, if it ever came up, but the solution in place was brilliant!
var myArray = [0,1,2,3,4,5...]; myArray.push(myArray.shift());
According to the mozilla documentation:
The shift method removes the element at the zeroeth index and shifts the values at consecutive indexes down, then returns the removed value.
I setup a jsfiddle to see how fast it could handle an array of almost 9000 numbers. Turns out it’s pretty quick, clocking in around 180ms.
jQuery Charting Plugin: Peity
A guy by the name of Ben Pickles has a cool little jQuery plugin for building SVG charts. His documentation can be found here: http://benpickles.github.io/peity/ but the usage is really simple!
ProcessingJS – Virus Simulation
One of my first little projects in ProcessingJS was this virus simulator. There’s no interactivity, but the 30 hosts are subjected to 25 viruses. As each virus is introduced, it has a randomly set color and resiliency. The resiliency determines if the virus can survive a long time within the hosts without contact from other infected hosts. Once a host has been infected and the virus in itself dies off, the host is immune to that specific virus going forward.
I’ve always intended to go back and have the hosts retain the color of the viruses they become immune to, or adding other fun little features.
Algorithmic Works of Art
The algorithmic movements of the host nodes and viruses spreading based off the computer model led us to a topic of art generated by algorithms.
Dr. Robert D. Jansen describes himself as an “experimental artist who uses chaos mathematics to conjure mysterious and beautiful abstract art.” He’s run multiple Kickstarter campaigns (1, 2, 3, 4, 5, 6, 7, 8 ,9, 10, 11, 12) creating this abstract art featuring various methods of generating the images.
He’s also got a set of YouTube video featuring his various art projects, below is the one we discussed: Darkman.
We had a great first Recreational Programming meet-up! I’m excited to see what will come next week. These meet-ups are open to the public as well, so if you’d like to attend, check our events page for details on the time and place. And if you’d like to present some cool code trick, fun project, or some other code-related thing, send me an email through the contact form at the top of this page and include “Recreational Programming” at the top of the message!