FINALLY! SOME UPDATES! This website is being reconstructed. Some content will go away soon. If you want to see my new stuff, visit my github:

August 13, 2012

The Triangle

I probably should have used this weekend to look for work, instead, I did something way better. Despite suffering a cold, this weekend had to be one of my most productive weekends ever.

Jill is now stable. It's still alpha, but stable. Poly is practically object-oriented. I just need to clean up some code in it for the next version. I've got my JavaScript groove back! I just need to take care of some business with events, animation, and interactivity.

A new version of my HexColors example is now way more efficient. Instead of six loops, everything is done in three. Basically, three different hexagons are drawn at the same time.

Meanwhile, my Pascal/Sierpinski Triangle program demonstrate everything that Poly is capable of. All the shapes, colors, and text in this program are HTML5 Canvas and JavaScript. This program requires quite a bit of math to calculate despite it being efficient. The triangle goes as far as 32 steps and with the present algorithms in use are able to handle around 48 steps before math errors kick in.

Download pascaltriangle.html at the end of this post. It looks even better on a smartphone!

Yes, computers do err in mathematics. Particularly when really, really, really large numbers come into play that are larger than what the preset datatypes can handle. But this was a fun program and something I had been looking toward completing ever since I was a teenager.

Today was a momentous occasion. A quiet victory and one step closer to much greater things.

My next version of Jill may have the next version of Poly integrated into it. At least the stable parts.

The next step will likely to work on Evan, an events and animation JavaScript library.

A fun piece of JavaScript that I wish could be applicable to other languages is this line.

( !(val % 2) ? celleven : cellodd[0] ).fill(ctx);

The very essence of this code SCREAMS Perl, but it is JavaScript. I've used this line serveral times in pascaltriangle.html and I love it!

To break it down, the fill() function is actually a function I wrote that is a corollary of the fill() function defined by HTML5 Canvas. My version is a more flexible and has some feature that make for effective Canvas development.

For example, when I think of Canvas's command for fillStyle and fill(), which is generally used as means to say "The bike is painted red. Paint the bike read.", which in JavaScript would be interpreted as theBike.fillStyle="red";theBike.fill();. My version is much less passive. I say "Red is the color of the bike." or red.fill(theBike); where somewhere before that a Brush object called red has been defined using var red = new Brush('#f00');. Thus I can apply red to any object that needs this color applied to it.

Of course theBike really just represents the 2D Context element that defines what pen to use to draw with. Which is why Brush was such an idea name to define a class that takes care of simple strokes and fills.

The fact that JavaScript supports defining corollary statements is probably why when I used the ternary if-then statement (test ? true : false) inside parenthesis it allowed me to use a function that is shared by two different objects of the same type. Overall, I like this statement and plan on using it in the future. (Besides, I wanted to put some more content into this post.)

Site updates should occur between now and then end of the month. I wish I could use HTML5 Canvas as background especially if I figure out how to make Mandelbrot and Julia fractals with Canvas. Now there would be some good code!



Under Construction