Friday, October 24, 2014

Corn: The First GMO?

Do you like corn? Popcorn? Sweet corn? Candy corn? Okay, that one's not really corn, but it's probably made with high-fructose corn syrup.

It may surprise you to learn that corn, the grain produced more than any other grain on this planet, was invented by humans. It would not exist on its own.

But it wasn't created in a lab by some mad scientist. Thousands of years ago, the indigenous peoples of Mesoamerica created it the old fashioned way - selective breeding. They certainly weren't mad. They were probably fairly happy. By cultivating a wild grass called Teosinte and selecting plants for certain qualities, those early Mexican farmers made the plant we know today as corn. 

Teosinte (left) and modern corn (right).
The middle is a hybrid of them both.
Photo by John Doebley.
So in a way, we have been creating Genetically Modified Organisms since we started farming. By cross-breeding different plants and selecting the ones with the most desirable traits for more cultivation, each generation of food crop was genetically different from the previous one. In a fairly short time, corn went from a plant that could produce one small ear per stalk to a plant that produces many foot-long ears per stalk. That's almost as weird as making fish that glow, and didn't require any test tubes or Erlenmeyer flasks.

And corn isn't the only plant to get this treatment! Consider Brassica oleracea. Humans took that plant, wild mustard, and turned it into cabbage, broccoli, kale, Brussels sprouts, collard greens, and kohlrabi. Yes, that's right. broccoli and kale are the same plant! Same species. Brassica oleracea. Totally blew my mind when I first learned this.

These are the kinds of things that influence my web comic. Today's was actually a reproduction of one I created back in 2001. It was probably the last one I did before re-launching this year. Back then, there was only one frog, and he only sometimes wore a lab coat. But he did try to analyze the genetic makeup of marshmallows. As far as I know, those were only domesticated starting in 1934 and their genome has yet to be sequenced.

Wednesday, October 22, 2014

Socket.io with Express

Today I introduced the world to 2-player Solitaire. It was the joke in today's comic, but I thought that it might work in real life too. At the very least, it helps add dimension to the joke.

In it, you and a friend are looking at the same card table. For each valid card placement, you get 1 point. Your goal is to put the cards on valid placements before your opponent does and thereby score the most points.

I've been working on it for about 3 weeks now, which is why I haven't had time to put much code in this blog. But now that it's ready (don't hesitate to send a bug report if you find anything weird) I have time to talk about different parts of it on a technical level.

It is a web application, using just HTML5 and JavaScript. It is playable on both mobile devices and your desktop. Since the main premise is a shared game board, I used Node and Socket.io to share the real-time game data between two web browser clients. I've been using Socket.io for years now, but this was only the second time I've used the 1.0 release combined with the Express framework. The first time I struggled with some things, so I thought I'd share the basic application outline that I came up with to make your life easier.

I'm using Express 4.8.7 and Socket.io 1.0.6 in this project. To set up your application to handle both "normal" HTTP traffic and the various Socket.io communication types, you have to deviate slightly from a typical Node/Express setup.

var express = require("express");
var http = require("http");

var app = express();
var server = http.Server(app);
var io = require("socket.io")(server);

//------------ Socket.io stuff

io.on("connection", function(socket) {
 
    // set up handlers for different events here
    socket.on("some_event", function(data) {
        // do something
    });

});

//------------ web application routes

app.get("/some/path", function(req, res, next) {
 
    res.send("some response");
 
});

// ------------ start the listening

var srv = server.listen(5000, function() {
    console.log("listening on port %d", srv.address().port);
});

The main difference between this configuration and a more typical Express app is what you see on line 4. You have to require the "http" module explicitly, and use it to create a Server instance using your Express app instance. You then pass that Server to Socket.io as I do on line 6.

After that, use your io and app objects to set up your application behavior via event handlers and routes. At the end, start your Server listening. Note that on line 29, it is the http server instance you use to start the listening instead of the Express app object.

Try that, and you're off to a good start. As always, the source code for the entire game is available on GitHub. Check it out if you want to see how I did everything else, or keep reading here and I'll talk about other parts of it soon.

Amphibian.com comic for 22 October 2014

Monday, October 20, 2014

Follow the Scrip

Today's Amphibian.com comic represents the intersection of three very different issues. A trivium, if you will. That's the singular form of trivia. And trivia are 3-way intersections. Seriously, "trivia" is a place where three roads meet. It's Latin. Tri = 3, Via = road.

So what were these three things that came together in my mind and inspired me to create such a comic?

One was the recent surge in cryptocurrencies. It's like Bitcoin got some attention in the mainstream-ish media and then everybody was coming up with their own Whatevercoin. Litecoin. Dogecoin. Peercoin. Darkcoin. There's even Pandacoin. Why not Frogcoin? You get the idea. Everybody was making up coins. Maybe they felt like since they missed the boat on Bitcoin, they should start mining something else (or maybe everything else) just in case one of the others ends up being the winner. I guess it could happen. It happens with other things. For example, Google wasn't the first search engine, just the best. Sorry Bing.

The second thing was companies paying employees with debit cards instead of checks or direct deposit into checking accounts. It happened back in 2013 in a couple places and it really troubled me. Basically, workers were getting paid with those Visa pre-paid cards that you can use like credit cards to buy things. The problem was that there were sometimes fees associated with their use, and it can be tricky to spend 100% of those things. If you've ever had one you know what I mean. Workers were basically being cheated out of some money. The reasons that employers were doing this seemed a little shady. Some lawsuits were filed, and thankfully the government ruled that employers can't require you to get paid that way. They still have to give you the option of regular pay. I'm glad they did that, because I was concerned with the natural progression of the idea if it had been left unchecked.

And by progression, I mean regression. The third thing, which is tangential to the second, is the concept of company scrip. I thought, "what if Wal-Mart decided to pay its employees with Wal-Mart gift cards?" It seemed like a real possibility. Then I found out that it actually happened! At least in Mexico. Fortunately, the Mexican Supreme Court put a stop to it. But what if they try it someday in the United States? Then we'll be back in the days of the mining companies paying their employees in fake money that was only good at the company stores, which sold everything with huge mark-ups and kept the employees constantly indebted to the company. That practice ended many years ago, and I do not want to see it return. But wait, mining companies? That ties back to the cryptocurrency thing, since people "mine" for the coins! Whenever I find a loop like that, I know there has to be at least one comic I can make out of it.


Therefore, the end result of my ponderings on these issues was the comic in which frogs are working in a cryptocurrency mine and getting paid in a different and more obscure cryptocurrency which is only good in their company store. I'm fairly certain that Merle Travis would write a song about that exact scenario if he were still alive. It would probably be titled Sixteen Gigabytes.

Amphibian.com comic for 20 October 2014

Friday, October 17, 2014

ANSI, the Other 8-Bit Art

Despite the fact that I have 2 full-size old-school arcade games in my house (Dig Dug and Burgertime) and I do enjoy Minecraft, I am not a huge fan of 8-bit art. Back in 1982 when Burgertime was new, big-pixel games were the only games. Now people draw their game art in that style that just because they like it. I think some of the new games drawn like that look really good, and I am really impressed with artists' abilities to work in that style. But it's just not my favorite game art style.

If you haven't heard, 8-bit art (and also music) refers to a style reminiscent of the video games played on 3rd-generation home consoles such as the Nintendo Entertainment System, Sega Master System, and the Atari 7800. The term "8-bit" refers to the processors in those consoles. The number of bits became a selling point, and the different generations were identified by their bit number. The Super NES was a 16-bit console, the Nintendo 64 was a 64-bit, and so on.

So while I'm not a huge fan of 80's style video game artwork, I really love ANSI art. I used to make it for a BBS back in the 90's. I've seen some really amazing things rendered in just a few simple colors and an antique character set. And since all the characters used in ANSI drawings were expressed in only a single byte, I think that ANSI art is the forgotten 8-bit art.

I recently found an online tool that can convert your pictures into ANSI art. Below is one of my frog images rendered that way. I don't know if it will look right on all platforms (especially if you are reading this on a mobile device) but it looks ok to me in Chrome on Windows 7.




Try it with some of your own pictures!

Amphibian.com comic for 17 October 2014