Saturday, January 9, 2010

Snowflake SVG developer release

Recently, I have been learning SVG scripting by porting my old branching-web AS3 script to Javascript. This time around, I wanted to remedy some of the shortcomings of the previous incarnation. Here's a list of some of my goals and how they turned out.

Goals

  • Allow the user to customize each node individually, but don't add too much complexity.

    Success. The interface has become slightly more complex, but it's still relatively simple.

  • Let a node have only one child, allowing the user to taper the branches.

    Success. This effect is highly useful for creating snowflake patterns.

  • Improve the demo interface, enabling interactive editing of each node.

    Pending. I plan to tackle this feature next.

Demos

Classic snowflake

Screenshot of a classic snowflake drawn by my library
Click to view as SVG.


function startup(evt) {
    var svgDocument = evt.target.ownerDocument;
    
    var rect = svgDocument.createElementNS(svgNamespace, 'rect');
    rect.setAttributeNS(null, 'fill', 'skyblue');
    rect.setAttributeNS(null, 'width', '100%');
    rect.setAttributeNS(null, 'height', '100%');
    svgDocument.documentElement.appendChild(rect);
    
    var endPoint = createDataNode(0, 0, 0, []);
    var endCap = createDataNode(0, 5, 10, [endPoint]);
    var middleNode = createDataNode(60, 50, 10, [endCap, endCap, endCap]);
    var centerNode = createDataNode(360, 30, 10, [middleNode, middleNode, middleNode, middleNode, middleNode, middleNode]);
    
    var web = createWeb(centerNode, createPoint(0, 0), 0);
    
    var snowflake = createSnowflake(web);
    
    var snowflakeSVG = snowflake.toSVG(svgDocument);
    snowflakeSVG.setAttributeNS(null, 'fill', '#fff');
    snowflakeSVG.setAttributeNS(null, 'transform', 'translate(250 250)');
    svgDocument.documentElement.appendChild(snowflakeSVG);
}

Gothic cross snowflake

Screenshot of a gothic snowflake drawn by my library
Click to view as SVG.


function startup(evt) {

    var svgDocument = evt.target.ownerDocument;
    
    outerPoint = createDataNode(0, 0, 0, []);
    
    taperFork = createDataNode(0, 5, 10, [outerPoint]);
    
    bigFork = createDataNode(180, 25, 10, [taperFork, taperFork, taperFork]);
    
    nextFork = createDataNode(180, 25, 10, [taperFork, bigFork, taperFork]);
    
    innerFork = createDataNode(360, 15, 10, [nextFork, nextFork, nextFork, nextFork]);
    
    var web = createWeb(innerFork, createPoint(0, 0), 0);
    
    var snowflake = createSnowflake(web, innerFork);
    
    var snowflakeSVG = snowflake.toSVG(svgDocument);
    snowflakeSVG.setAttributeNS(null, 'transform', 'translate(250 250)');
    svgDocument.documentElement.appendChild(snowflakeSVG);
}

Nodes displayed as points

Screenshot of a web of nodes drawn by my library
Click to view as SVG


function startup(evt) {

    var svgDocument = evt.target.ownerDocument;
    
    var endPoint = createDataNode(0, 0, 0, []);
    var middleNode = createDataNode(180, 50, 0, [endPoint, endPoint, endPoint, endPoint]);
    var originNode = createDataNode(360, 50, 0, [middleNode, middleNode, middleNode, middleNode]);
    
    var web = createWeb(originNode, createPoint(0, 0), 0);
    var webSVG = web.toSVG(svgDocument);
    webSVG.setAttributeNS(null, 'transform', 'translate(250 250)');
    svgDocument.documentElement.appendChild(webSVG);
}

Download

I've packaged up all the necessary scripts and SVGs into one tiny .zip archive for your hacking pleasure. If you'd like to see what I'm working on next (and possibly help), you can view my Google Code project repository. Everything is licensed under the Apache 2.0 license, so you can use it in a proprietary application, modify it in any way you choose, or pass it to all your friends provided you indicate where it initially came from. If you do anything interesting with it, tell me about it. Happy hacking!

Tuesday, December 29, 2009

NeoCubes: Best. Toy. Ever.

When I find something I like, I tell people about it. When I get payed for every person I convince to buy that something, I tell more people about it. For those two reasons, I want to tell you about NeoCubes, my new favorite time-wasting toy.

Each batch of NeoCubes includes 224 neodynium BBs and a faux velvet pouch. It's shockingly easy to lose track of time when you're playing with these addictive spheres. You can form them into anything: bands and rings, geometric shapes, flat patterns, or complex models. I've built a new model each time I've pulled them out of my pocket, and I'm not even close to the end of my creativity.

Here are a few of the models I built:

Eight-pointed star

Eight-pointed star

Four-pointed star

Four-pointed star

Truncated octahedron

Truncated octahedron

Truncated tetrahedron

Truncated tetrahedron

Large bomb

Large NeoCube bomb

Metal chu (my favorite)

Metal chu

I'm not the only one who enjoys them, either. After Christmas, I let a couple of my family members play with my set of 'cubes. Big mistake. After only a couple of minutes, even a close cousin would begin hunching over his 'cubes, casting suspicious glances at me, and mumbling to himself. Everybody came up with their own use for the NeoCubes: a cousin about my age used them to fashion herself bracelets and earings, but two younger cousins experimented with the interaction of rings of magnets on a smooth table. Even my seventy-nine-year-old grandfather enjoyed manipulating them with his fingers.

I carry my NeoCubes with me everywhere, pulling them out when my fingers become restless or when some metallic objects must be stuck together. Being a geek, both of these scenarios happen quite often.

You can buy a set of 224 NeoCubes for only $20 at Amazon. Compare that to about $70 if you purchase spherical magnets in bulk (I did). Buy some for you, your geeky friends, and everybody else you know and make me a rich man! If you're still not convinced, check out the demonstration video for the competing Buckyballs, but don't be fooled by the slick packaging and marketing. NeoCubes came out two years earlier, and they're $10 cheaper.

Saturday, December 5, 2009

Playing with SVG and Javascript

As a fan of ActionScript 3, Flash's vector-drawing scripting language, I've always been interested in the SVG standard. However, now that it's actually available to most of the web-browsing population, I have an excuse to learn more about it. I had stopped programming in AS3 because of the closed nature of the platform, its instability on Linux, and my inability to develop AS3 on Linux. However, I can now play with vector-drawing once again, thanks to the widespread adoption of SVG.

Anyway, this post is just a heads-up: I'm fiddling with SVG-scripting with Javascript, and I plan to write a tutorial about it soon. Thus far, I haven't found a basic tutorial on integrating HTML, SVG, and Javasript, and I hope my tutorial will remedy this perceived shortage. Of course, the tutorial is really just an excuse to play with Javascript and SVG, but I will continue to delude myself with words of altruism and selflessness. Helping people, that's what I'm doing...

Sunday, November 15, 2009

Origami accordion toys

One of my favorite ways to burn time is folding complex origami accordion patterns. I just uploaded an album of these paper accordions, and I've listed the different types of patterns below. I might make a tutorial on how to fold one if somebody asks nicely.

Expanded diagonal compound v-shaped

Expanded diagonal v-shaped origami accordion top
Top view

Expanded diagonal v-shaped origami accordion bottom
Bottom view

This pattern is a more complex version of the classic v-shaped accordion pattern.

Deep accordion

Deep origami accordion top
Top view

Deep origami accordion bottom
Bottom view

Deep origami accordion curled
Curled

This is probably my favorite pattern of all time; it's an incredibly time-consuming way to turn a piece of paper into a mesmerizing paper toy. It requires folding and pleating in three dimensions simultaneously.

Collapsed triangle base

Collapsed triangle base origami accordion top view
Top view

Collapsed triangle base origami accordion bottom view
Bottom view

This is just a weird test pattern I folded with some spare time and a magazine renewal card. It's unique because it doesn't like to flex.

Collapsed diagonal compound v-shaped

Collapsed diagonal v-shaped origami accordion top view
Top view

Collapsed diagonal v-shaped origami accordion bottom view
Bottom view

This one is more complex than the collapsed diagonal compound v-shaped pattern, because it requires an extra pleat for each row.

Collapsed compound v-shaped

Collapsed compound v-shaped origami accordion

This one is the same pattern as the collapsed diagonal compound v-shaped accordion, but it originates from the middle of a side of the paper, instead of the corner. It looks like a snow monster.

That's all the accordion patterns I have folded recently. I know this has nothing to do with technology, but I still don't have the time to work on any serious development projects. With luck, I'll be rejoining the coding community soon.

Update: I just opened an Etsy shop to sell some of the textures you see above. If you want one, visit my shop and buy one before they sell out! Yeah, right...

Saturday, November 7, 2009

A laughable argument against net neutrality

I don't generally stray into political topics, but some issues are too important and relevant to my future and the future of the internet. For example, I believe net neutrality is critical to protecting creative uses of the internet from the internet service providers' meddling. That's why I wrote a general summary of the net neutrality issue a couple weeks ago, and that's why I'm addressing some of net neutrality's critics today.

In the October 30 opinions section of the Wall Street Journal, I read an opinion against net neutrality that is too misguided for me to ignore. Republican senators Orrin Hatch and Jim DeMint wrote the piece, arguing that net neutrality policy will obstruct broadband investment and innovation by letting the government meddle in the affairs of the ISPs. That's simply not true.

I agree with the senators that over-regulation will prevent companies from innovating. The logic is obvious; if a company can't increase its profit by improving its services, it won't improve. However, the current regulation doesn't prevent ISPs from profiting from broadband investment. They are free to changes prices, set usage caps, and even offer higher internet speeds for higher prices. The only way in which the regulations limits ISPs network management options is by preventing them from discriminating against certain types of traffic.

I'm afraid that alarmist arguments like this one about net neutrality are obstructing important discussions on the effects of the regulations and the FCC's proper role in net neutrality enforcement.

Friday, October 30, 2009

Programming is more than pointers and recursion

I apologize for last week's dry and boring post. This isn't a news blog, and it won't become one. I chose that topic because I was desperate to write about something relevant to programmers and the tech community, not because I wanted to write about it. Now I will only write about topics that interest me, topics that I can offer a unique perspective on. I won't become a me-too blogger.

...and now, for the reason you're reading this.

Today, I read a 2005 post from the venerable software-development blog Joel on Software about the problems with colleges teaching Computer Science through Java. I recommend you read the article before this post, but, to summarize, Spolsky says that because Java doesn't emphasize pointers and recursion, it isn't a suitable language through which to teach Computer Science. Here's why he's wrong.

Programming is more than just solving puzzles

First and foremost, I disagree with his view on the purpose of a CS program. He thinks that the goal of a college's CS program should be to weed out the students who aren't smart enough to succeed as programmers. Furthermore, he recommends that pointers and recursion should be taught as soon as possible to scare off the posers. That's poppycock.

The goal of a CS program should be to teach students how to develop high-quality software. Far too many programmers have no idea how to write readable code, much less create a large, functional system with lots of moving parts. Programming is intrinsically difficult, but teaching students only the most arcane and complex parts of the programming discipline scares away many potentially great programmers.

According to Steve McConnell, author of Code Complete, the best programmers are not necessarily the most intelligent, but the most humble. Someone who understands his mental limitations will use every technique available to simplify his code, reducing its complexity and thereby increasing its quality. Complexity is probably the number-one enemy of software quality.

Pointers and recursion aren't intrinsic to programming

All the CS theory and most of the content on pointers and recursion will never be used by the average CS graduate. Spolsky even says so:

Now, I freely admit that programming with pointers is not needed in 90% of the code written today, and in fact, it's downright dangerous in production code. OK. That's fine. And functional programming is just not used much in practice. Agreed.

He then says that these concepts teach students the mental flexibility to view a problem at several levels of abstraction simultaneously. I think this type of "mental flexibility" might account for some of the bad code recent CS graduates write. A graduate's "mental flexibility" could tempt him to demonstrate his new CS skills by writing overly complex code that functions on multiple levels of abstraction. As I said above, intelligence doesn't correlate strongly with a programming success, but ego certainly correlates with failure.

Please don't misunderstand my point. I believe that some of the most difficult areas of programming are the most important (and interesting.) I look forward to learning about recursion and its power. I plan on taking plenty of CS theory classes, learning about even the most esoteric aspects of computer programming. However, I don't think every student would benefit from this type of information. Because these topics aren't necessary to write great applications, I don't think they should be necessary to graduate from a CS program.

This post may, in fact, be completely off-base and unsupported by the facts. However, I've decided to make this blog more personal by sharing more of my opinions and writing about things I care about. I have been worried about writing content that's relevant to my intended audience, but right now, I simply don't spend enough time writing code and playing with my computer to generate a suitable flow of relevant posts. I'm reclaiming this blog as a tool against my personal battle with obscurity.


Edit: I was sorely mistaken. This post is the misguided rant of a readability zealot. See my current position here.

Sunday, October 18, 2009

Net neutrality: Innovation protection or unnecessary regulation

I consider myself a Libertarian on most issues. I'm generally in favor of the government getting out of the way of private innovation. For that reason, I became opposed to net neutrality as soon as I learned that it involved government intervention into the affairs of (arguably) private businesses: the internet service providers.

However, after learning more about the net neutrality issue and reading about the FCC's new net neutrality rules, I have decided to write a brief summary of the issue in favor of net neutrality.

What is net neutrality?

The issue of net neutrality is about the internet service providers' handling of information flowing through the internet. Information is transmitted over the internet in packets of information. ISPs can examine these packets to determine what type of information they are carrying. For example, an ISP can tell whether a user is watching a YouTube video, downloading email, or browsing Amazon.

For the most part, ISPs don't care about what type of information is being transmitted, but that is beginning to change. ISPs have realized that they can reduce the load on their networks by slowing down certain types of packets. This practice makes sense as a way to combat piracy by slowing down illegal traffic, but several ISPs have begun to use it to arbitrarily discriminate against certain types of traffic.

For example, Cox recently decided to make all FTP and P2P traffic slower, ostensibly to increase the speed of its other services. Although this may improve the service to most of its customers, it could be used for more nefarious purposes. For example, data being delivered from its partner's websites could be prioritized, slowing down all other traffic. Cox could even slow down a particular type of data in order to offer the full speed for a higher price.

Net neutrality legislation and policy attempts to stop this practice by forbidding ISPs from discriminating for or against any type of traffic.

Why should the government get involved?

Until recently, I didn't have an adequate answer to this question, so I couldn't justify the expense to the government and ISPs that net neutrality policy would create. I thought that competition between ISPs would prevent any overbearing packet filtering. However, according to Congress' most recent net neutrality bill, "the overwhelming majority of residential consumers subscribe to Internet access service from 1 of only 2 wireline providers: the cable operator or the telephone company." If both of these all-important ISPs decide to moderate your traffic, you won't have any other options.

Who opposes net neutrality?

Two major groups of companies oppose net neutrality for two separate but similar reasons. Most major ISPs providing high-speed internet are opposed to net neutrality because it limits their ability to profit from their high-speed internet services. Not only would net neutrality prevent them from reducing network load by slowing down some types of traffic, but also it would keep them from differentiating themselves from other ISPs by offering extra speed on certain applications. For example, net neutrality would prevent an ISP from making videos stream faster by prioritizing them over other traffic.

In addition, the high-speed wireless ISPs Verizon and AT&T have teamed up to oppose net neutrality on different grounds. Because both operate massive wireless data networks, they want to reserve the right to manage their traffic. They argue that because there is a fundamental limit to how much data can be transmitted through the wireless spectrum, they should be able to reduce the strain on their networks by slowing down high-volume traffic.

The problem with their argument is that packet filtering isn't the only way to limit network traffic. Net neutrality would allow them to limit data usage by setting customer data limits or reducing the speed of all traffic. The only thing the plan prevents is slowing down packets based on the information they contain.

What can I do?

Contact your congressman in support of H.R.3458, the Internet Freedom Preservation Act of 2009 and the FCC's recent action on net neutrality. The second point is important because some congressmen believe the FCC has overstepped its boundaries by declaring net neutrality rules while the House of Representatives was debating the issue. The FCC's rules will accelerate the enforcement of net neutrality, and that can't happen soon enough.