Pxlqst v0.0.5 – map editor

Screenshot 2015-12-27 at 11.38.22 AM

I released a new version of Pxlqst, my 16×16 dungeon adventure game (pictured above), and report in the release notes that:

  • doors can now lead to new rooms
  • new format for storing room “maps” as collections of strings
  • updated README instructions for world generation and map editing
  • Known bug: cake no longer nutritious :-(
  • fewer dependencies
  • rooms can be “slept” and “woken”

This is still not quite playable, but things are coming together enough that, once I get combat and inventory running, I think it’ll be possible to build a simple quest. I have been thinking about the separation between Pxlqst, the game, and Pxlngn, the game engine, upon which I expect pixel art enthusiasts will create many a 16×16 adventure game.

See the map format here:

Screenshot 2015-12-27 at 8.10.12 AM

Partial Feldhellschreiber encoder in JavaScript

Noah Vawter (of Exertion Instruments) and I used to send each other voicemails encoded in a [pre] Nazi-era (OK, further research shows it was developed in the 1920’s) German radio protocol called Hellschreiber or Feldhellschreiber, invented by Rudolph Hell. It’s a sort of early paper-tape teletype system which was also the first example of bitmapped fonts. You can encode/decode using fldigi (available on apt in ubuntu and here: http://w1hkj.com/Fldigi.html). Despite its unfortunate origins, it’s pretty interesting as an early automated text-over-radio system which is robust mainly for the same reason people are good at reading CAPTCHAs.

Here’s a mechanical feldhellschreiber machine in red/blue stereo: http://unterbahn.com/2011/04/franks-n4spp-hellschreiber-page/

Anyways, Noah and I had always wanted to do an implementation in JavaScript, and created this repo long ago: https://github.com/jywarren/hellschreiber-js

Finally got around to more coding this weekend, and put together part of an encoder, a bit messily but short enough to be readable. You can try it out here:

http://jywarren.github.io/hellschreiber-js/

It doesn’t work.

feldhellschreiber

Well, it does make noise, and write out letters how you’d expect them to appear in fldigi — but it’s not anywhere near synced and I’m struggling with adjusting the length and latency of the sound sample — generated in JS using riffwave.js as well as the setInterval of the script itself, which ought to run once per pixel. I’m also hobbled by using an awfully-encoded hellschreiber font from the fldigi source, which I refactored into JavaScript, but which is inexplicably stored as hex values in rows instead of columns, when Hellschreiber is an innately column-based format. But I don’t think that’s the limiting factor.

I’m starting to get diminishing returns for my debugging and am pretty tired, so I’m just going to put this out there and think on it and/or see if I can get help from someone who’s a bit more methodical of a coder. Sometimes I’m a bit too much of an empiricist, not to mention a cobbler-together, impatient as I am to get to Hello World.

Also — once I get an encoder working, I really want to move on to a decoder, so you can run this on a phone facing another phone, and send/receive messages that way. How efficient and historically accurate!

Object.hasOwnProperty() in JavaScript

On StackOverflow, user Pablo Cabrera points out:

As slashnick pointed out, you can use the “for in” construct to iterate over an object for its attribute names. However you’ll be iterating over all attribute names in the object’s prototype chain. If you want to iterate only over the object’s own attributes, you can make use of the Object#hasOwnProperty() method. Thus having the following.

for (var key in obj) {
if (obj.hasOwnProperty(key)) {
/* useful code here */
}
}

Wish I’d known of that a year ago.

gdalwarp cannot perform perspectival distortion

I’ve been banging my head against a wall for a few days on this one, first struggling with ImageMagick, then switching to gdal to get full-resolution geoTIFFs from Cartagen Knitter. I had a ‘duh’ moment just now when I realized that gdalwarp can only do polynomial or thin plate spline warps, neither of which are what I want – that is, perspectival warping. I want to map 4 corner ground control points or GCPs to four latitude/longitude positions. Back to ImageMagick…

I know there are 5 GCPs in the image above – it was the same deal with just 4… it can’t do more than a shear unless you either add the minimum 6 GCPs for a single polynomial warp, or go for a thin plate spline (TPS) distort. A good way to think about TPS is as if the image were a sheet of thin metal (the reason it’s called a TPS) and that you’re bending it in the z-dimension, aplanar. This causes funny curved edges and is not what I’m looking for.

OK, one more note for future reference: see this page for a discussion of different warping techniques and also for the minimum number of GCPs required for different-order polynomial warps.

Google News library for Ruby

I was surprised that Google News has no API, so I built my own: Using HTTParty, I wrote a small Ruby library for Google News. Put this in a ‘googlenews.rb’ file in the /lib/ directory of your Rails application to grab google news stories and topic lists.

Haven’t figured out how to get more than 10 items… Safari seems to be able to with feed://news.google.com?output=rss… but I’m not sure how.

gem "httparty"
require "httparty"

class Googlenews
  include HTTParty
  base_uri 'news.google.com'
  
  def self.items
    options = { :query => { :output => 'rss' } }
    features = self.get('/news', options)
    features['rss']['channel']['item']
  end
  
  def self.extract_topic(item)
    # ncl=duPfj30A5WoxBHMupoOtlciO1jY1M&
    item['description'].match(/ncl=([a-zA-Z0-9]+)&/)[1]
  end

  def self.topic(item)
    options = { :query => { :output => 'rss', :ncl => self.extract_topic(item) } }
    features = self.get('/news/more', options)
    features['rss']['channel']['item']
  end
  

  # store in database (unused)
  # def self.story(item)
    # item['category']
    # item['title']
    # item['guid']
    # item['description']
    # item['link']
    # item['pubDate']

    # t.string :category, :default => ''
    # t.string :title, :default => ''
    # t.string :guid, :default => ''
    # t.text :description, :default => ''
    # t.string :link, :default => ''
  # end

end

Once you’ve dropped this in /lib/, you can use it in a Rails controller like this (I needed JSON, to work with the feed in JavaScript):

class DataController < ApplicationController

  def latest
    render :json => Googlenews.items
  end

end

Update: to get more than 10 items, add a GET parameter ‘num=20’ to the feed URL. This works both for topic and for the main feed. I haven’t confirmed this but I think it’s still limited to 30 items. Again, Safari manages to get more, but perhaps it does repeated queries. Still investigating. Anyways, that makes it:

 def self.items
    options = { :query => { :output => 'rss', :num => '20' } }
    features = self.get('/news', options)
    features['rss']['channel']['item']
  end 

Update: This now has a real home on Github, where it’s called ruby-googlenews.