Brian's Site

I'm a computer engineer turned psuedo-physicist. This is where I keep a log of things I'm playing with.

GithubTwitter

Doctors Visits

My Doctor's visits usually break down something like this:

  • 99% waiting
  • 0.9% in some kind of new visit induced pain
  • 0.1% getting the information I came for

Along the way there's something like a 50% probability I'll be asked to remove my pants.

On the whole, it's not something I enjoy but having a Kindle solves 99% of it.

Comments

First Android Game!

Hi there.

http://brianttaylor.com/static/memmatch/bigicon.png

I've just published my first Android game. It's simple, but I'm proud of it. It's one of several (unfortunately) games named "Memory Match" in the Android store. You can either search the store for "wubo" or you can just follow this direct link and let me know what you think.

I'm open to suggestions in the comments either here or in the market.

Comments

Shadow Tiles

I just finished implementing the rules for when to draw shadows on a tile and what shadows to draw. The creator of the "Planet Cute" tileset includes this very helpful guide:

http://brianttaylor.com/static/platformer/shadow-instructions.png

Thankfully, before I wasted too much time, I realized this was just the sort of thing that I could write a small DSL to describe. Here's my mapping to code of the image above:

(def *shadow-types*
     [(shadow-with :shadow-south-east
                   (present [1 1 1])
                   (absent [1 0 1]))
      (shadow-with :shadow-east
                   (present [1 0 1]))
      (shadow-with :shadow-north-east
                   (present [1 -1 1])
                   (absent [1 -1 0])
                   (absent [1 0 1]))
      (shadow-with :shadow-side-west
                   (present [0 1 -1])
                   (absent [0 1 0]))
      (shadow-with :shadow-south
                   (present [1 1 0]))
      (shadow-with :shadow-north
                   (present [1 -1 0]))
      (shadow-with :shadow-south-west
                   (present [1 1 -1])
                   (absent [1 0 -1]))
      (shadow-with :shadow-west
                   (present [1 0 -1]))
      (shadow-with :shadow-north-west
                   (present [1 -1 -1])
                   (absent [1 -1 0])
                   (absent [1 0 -1]))])

And the resulting shadowed image:

http://brianttaylor.com/static/platformer/shadow-test.png

The updated code is up on github.

Comments

Starting Something New

I just created a new repository up on GitHub.

https://github.com/netguy204/platformer

My current vision is to create a game with a play style somewhat like a classic platformer. I'm doing that because I think I can achieve the basic rendering/controls/collisions pretty quickly and can focus on what I really want to do: Physics!

Ah, the real motivation.

I recently purchased the excellent Game Physics Engine Development by Ian Millington and I want to make a sandbox that I can use to play with the things that I'm learning.

I'm also using the very handy "Planet Cute" tile set from lostgarden.

http://www.lostgarden.com/2007/05/dancs-miraculously-flexible-game.html

All I have now is a renderer. Naturally (given my current obsession) I'm working in closure. Here's a level definition:

(def *scene*
     [[[:stone :stone :brown]
       [:stone :brown :brown]
       [:stone :dirt :dirt]]
      [[:none :none :chest]
       [:none :none :none]
       [:none :dirt :dirt]]])

And here's what that looks like rendered:

http://brianttaylor.com/static/platformer/first.png

I need to add some shadows so that the height of one tile relative to another is less ambiguous.

Comments

Porting to Clojure

I've been porting my org-mode blogging system to Clojure from Rails. So far, I've been pretty blown away by how fantastically-good the tools for doing web-development in Clojure are!

For doing webdev in Clojure, I've finally found the secret ingredients: Enlive and Moustache. Enlive is a really solid template library that lets you extract, mutate, and re-assemble chunks of HTML primordial ooze into data-rich goodness.

Enlive

https://github.com/cgrand/enlive

For example, the code generating the page you're looking at right now is:

(deftemplate page-template *page*
  [{:keys [title blurb body]}]

  [:title] (maybe-content title)
  [:#page_title] (maybe-content title)

  [:#about :p] (maybe-content blurb)
  [:#buttons] (content (map button-model *buttons*))

  [:#page_content] (content body))

And the HTML looks like:

<!-- just a snippet -->
  <div id="buttons">
    <a class="button" href="/"><span>Projects</span></a>
    <a class="button" href="/"><span>Blog</span></a>
    <a class="button" href="/"><span>Github</span></a>
  </div>

  <div id="page_content">
    <h2 class="post_title">The Title</h2>
    <div class="post_timestamp">posting time</div>
    <div class="post_body">
    </div>
  </div>
<!-- just a snippet -->

Compare those two chunks of code and think CSS. Enlive is letting me pick out chunks of the HTML using something that looks very much like a CSS selector,

[:#page_content] (content body)

and then replace its content with something else and re-insert it into the document.

As another neat example, here's the snippet of Clojure that's formatting each post itself:

(def *post-sel* [:#page_content])

(defsnippet post-model *page* *post-sel*
  [{:keys [title timestamp body] :or {:timestamp ""}}]
  [:.post_timestamp] (content timestamp)
  [:.post_title] (content title)
  [:.post_body] (html-content body))

This extracts just the portion of the page matched by "#pagecontent" and replaces the timestamp, title, and body using its parameters.

Enough of that. If you want to know more, check out the very excellent enlive-tutorial.

https://github.com/swannodette/enlive-tutorial/

This was virtually 100% of my reference material for Enlive while building this site.

Moustache

The other bit of secret-sauce is Moustache.

https://github.com/cgrand/moustache

This is a no-nonsense minimalist system for routing HTTP requests to appropriate handlers. Again, for the site you're looking at now, we have the code:

(def routes
     (app
      wrap-params
      [""] (with-template
             (page-template {:title "Brian's Site"
                             :body (map post-model (all-posts))}))

      ["entry" id] (with-template
                    (let [post (get-post-id id)]
                      (page-template {:title (:title post)
                                      :body (post-model post)})))
      ["atom.xml"] (with-template
                     (atom-template (atom-date)
                                    (map atom-storify (all-posts))))
      ["post"] {:post new-post}))

The coolest (in my opinion) of those routes is the second

["entry" id] (with-template
              (let [post (get-post-id id)]
                (page-template {:title (:title post)
                                :body (post-model post)})))

This route would match a request for "/entry/1" and would bind the "1" to id before executing the code next to it. It sure is nice to be working in a language with a proper macro system again. Sometimes Java makes me so sad.

Notes

Here's a handful of other links that I found useful while going through this process:

Well, that's enough of my excited spouting. Hopefully this inspires someone to consider Clojure (esp. with Enlive and Moustache) for their next webapp experiment. I'm out.

Comments

Blogging in Org-Mode

I'm a fledgling user of the very excellent emacs org-mode. I'm finding that I gravitate to it naturally for capturing everything from quick TODO items to detailed notes and plans. It's amazing how a simple outline is really most of what I need to organize my day.

I've been dabbling in elisp lately trying to build some way to post some of those thoughts to something resembling a blog. Here's what I came up with:

This code extracts the org sub-tree that contains point and splits it into the title and body. Then it converts the body to HTML using org-mode's HTML export feature.

(defun orgblog-post-file ()
  (interactive)
  (save-excursion
    (let (title-beg title-end body-beg body-end title body)
      (setq title-beg (progn (org-back-to-heading) (point)))
      (setq title-end (progn (end-of-line) (point)))
      (setq body-beg (progn (beginning-of-line 2) (point)))
      (setq body-end (progn (org-end-of-subtree) (point)))
      (setq title (buffer-substring-no-properties title-beg title-end))
      (setq body (org-export-region-as-html body-beg body-end t 'string))
      (orgblog-post orgblog-post-url (list (cons "title" title)
                                           (cons "body" body))))))

Then this accomplishes the fairly simple task of building an HTTP POST request and passing those parameters up to the brain-dead simple web-api I slapped onto my blog.

(defun orgblog-post (url args)
  "send ARGS to URL as a post request"
  (let ((url-request-method "POST")
        (url-request-extra-headers
         '(("Content-Type" . "application/x-www-form-urlencoded")
           ("Accept" . "application/json")
           ("Connection" . "close")))
        (url-request-data
         (mapconcat (lambda (arg)
                      (concat (url-hexify-string (car arg))
                              "="
                              (url-hexify-string (cdr arg))))
                    args
                    "&")))
    (url-retrieve url 'orgblog-post-response)))

I'm sure there are far better ways to do this but this meets my needs and means that I can finally make blog posts without the distraction and frustration of leaving the work-environment I am most comfortable in.

Comments