## Outro

After over a year of silence on this blog, for the sake of closure, I’ve decided to publish a brief “going dark” message. It is possible that one day I’ll flip the switch and begin writing again. So, this is not a farewell, so much as it is a see you later. All existing content will stay up for the foreseeable future and I’ll still respond to e-mails or comments.

## vim

I spent most of the day today getting comfortable using Vim. If you are not familiar with it or some of the other high octane text editors available and you spend most of your time at the computer writing text files, you might want to check them out. Vim and it’s ilk are highly configurable text editing programs made for productivity and extensibility. The pertinent information in this post falls into the “write this down for next time” category, but I thought I’d take a moment to also share why I am jumping into Vim after 6 years of writing code in IDEs.

Over the years I’ve taught myself several programming languages and the programs that are most commonly used to write them. I’ve used Eclipse for Android and Processing, Flash/Flex Builder for ActionScript, XCode for Obj-C and C++ and Visual Studio when I’m on the Windows side of things. Add a handful of other programs like TextMate, SublimeText, Komodo Edit and TextEdit to the list of editors I’ve used for Python and JavaScript and it all stacks up to quite a lot to think about. Each one of these programs has it’s own paradigms and user interfaces that at the end of the day just abstract many interesting things that I feel I should know how to do on my own. This brings me to one of the major reasons for learning Vim. I want to move away from relying on IDEs for compilation and packaging and learn to handroll these these tasks. I’d like to have a better handle on writing shell scripts to automate builds and deployment and for packaging distributable software.

Additionally, I’ve found that the text editor is the most important part of my toolchain. A good editor that doesn’t distract yet is responsive is essential. I like TextMate quite a lot. However, I have reached a point where I want to fine tune my environment beyond what TextMate offers and Vim seems to be the tool for that.

Being able to use Vim from the command line is a major plus for me. If you have Mac, it is most likely already installed on your computer. Just open the Terminal and type vim. If you immediately attempt to enter text you might be a little shocked. Instead, re-open Terminal and type vimtutor. I am actually using a program called iTerm2 which is a more advanced version of the Terminal.

Here are the first things I set out to do on my first day using Vim and some impressions or tips on each.

Complete the vimtutor
A quick intro that focusses on learning through doing and teaches all of the basics you need to know in order to get going. This is definitely the place to start out.

Set up Solarized color scheme
This proved to be pretty simple and required me to learn a little about Vim’s plugin structure and configurability. You can get the Solarized theme for Vim complete with installation instructions here: https://github.com/altercation/vim-colors-solarized

Customize behavior for certain languages
One thing that I really like about Vim is how the plugin and syntax highlighting system works. All configuration settings and plugins are contained within the root directory of your computer in a folder called .vim. Within this directory you can add sub-dirs that contain .vim files that define indentation, syntax and color schemes. There is also a file at the root called .vimrc. This file defines global settings for Vim.

So far my .vimrc file looks like this:

syntax on
colorscheme solarized
filetype indent on
filetype plugin on
set background=dark
set nu


The last line from that snippet turns on line numbers in Vim.

Another helpful trick I learned when trying to load plugins was to list all of the loaded scripts. Keep in mind that scripts are loaded as they are needed. So if you are trying to load a python script the syntax file for python may not have loaded yet and won’t appear in the list. To view loaded scripts type :scriptnames from within Vim.

I also need to update the indentation behavior for Python code. To do this I added a file called python.vim to the ~/.vim/indent. The contents of that file look like this:

set expandtab
set textwidth=0
set tabstop=4
set softtabstop=4
set shiftwidth=4
set autoindent
set backspace=indent,eol,start
set ignorecase
set smarttab


This seems to work pretty well for all of my existing Python code. It sets indentation at 4 spaces which is compliant with the PEP 8 style guide.

Posted in Coding | 4 Comments

## Processing with Jython and Eclipse

I am always looking for a reason to use Python more often, especially in situations where I’ll need to prototype rapidly, as is often the case when tasked with programming graphics. So, when a client proposed that I use Processing (Java) to build an up-coming project, I immediately thought it would be worth my time to investigate the possibility of writing a Processing app with the Java implementation of Python called Jython. In this post I’ll go through the steps I took to set up a development environment to facilitate this.

Note: I’m working on a Mac and have not tested this on a Windows machine. If anyone attempts to do so based on these instructions please send feedback or leave a comment. Also, this is a work in progress. I have not been able to test all of the features of Processing yet. Please see the caveat at the bottom of this page if you are expecting this to work seamlessly. Lastly, I am aware of the existing pyprocessing project available on Github. It is sweet and seems to work well. If you want to dive right into to using Jython with Processing, check it out. This post is more of a reminder to myself and anyone else of how to set it all up from scratch.

Setting it all up basically involves installing some dependencies and linking them together.

• Jython – This the Java implementation of Python. Just download the installer and double click it. There are a couple of prompts but the most important one to take note of is where Jython is being installed. You can install it anywhere on your system. Mine, for example, is installed at:
/Users/makemachine/development/libs/jython/2.5.2/

Once Jython is installed, you can add it to your path and test it by typing jython into the Terminal. If all is well, you should see the familiar Python interactive shell, however it will actually be the Jython interactive shell. My .bash_profile looks something like this:

PATH="/Users/makemachine/development/libs/jython/2.5.2/bin:\${PATH}"
export PATH

• Eclipse – If you are not familiar with Eclipse, it is an IDE ( integrated development environment ) that allows you to run, launch, debug and profile code for many differently languages. I installed the “Eclipse IDE for Java Developers” version, which I believe is a fairly basic version of Eclipse.
• PyDev – PyDev is a plugin for Eclipse that enables some really nice features for writing Python in Eclipse. It can be installed in a couple of different ways. I found that just using Eclipse’s built in plugin manager worked well. Once installed you should restart Eclipse. One way to verify that PyDev is installed is to go to Eclipse » Preferences and look for PyDev in the right hand menu.
• Processing – Before you can get to writing a Processing app, you will need to actually download Processing. Once it is downloaded, copy it to your Applications directory. I decided to make a copy of the contents of the Processing.app file and save them to another location on my computer. I did this just so I would have the files sand-boxed so that in the event of something breaking, Processing will still work as normal. To do this, right-click the Processing app, choose Show Package Contents, navigate to Contents » Resources » Java. Copy and paste this Java folder somewhere on your system. I placed mine at:
/Users/makemachine/development/libs/processing

Now that everything is installed you can start a project:

• Open Eclipse
• Choose Window » Open Perspective » Other and choose PyDev
• Right-click in the PyDev Package Explore on the left side of the screen
• Choose New » Project
• Choose PyDev Project from the menu
• Set a name for your project and the place it should live on your computer
• Choose “Jython” for project type
• If this is the first time you’ve used PyDev and Jython in Eclipse you will need to set the path to Jython
• Click “Configure an interpreter”
• Under Jython interpreters click the “New” button and browse to the location of the jython.jar file in the top level dir where you saved Jython in the first step.
• Click “Ok”
• Click “Finish”
• Next you need to link the Processing files to the project
• Right-click the Project file in the PyDev Package Explorer and choose “Properties”
• Under PyDev – PYTHONPATH, choose the External Libraries tab
• Click the “Add zip/jar/egg” button
• Navigate to the location where you saved the Processing libraries and select each of the following .jar files
• core.jar
• modes/java/libraries/java/opengl/library/gluegen-rt.jar
• modes/java/libraries/java/opengl/library/jogl.jar
• modes/java/libraries/java/opengl/library/opengl.jar
• Click “Ok”
• Right click the “src” folder in your project and choose New » PyDev module, name it main.py ( or whatever you want )
• Choose “Module:Main” form the list
• Click “Ok”

Now you should be able to run compile and run a Processing app! Here is some boilerplate code.

from processing.core import PApplet

class JythonProcessingApp( PApplet ):
def setup(self):
self.size(960, 540)
pass

def update(self, n):

pass

def draw(self):
self.background(0)
pass

if __name__ == '__main__':
PApplet.runSketch( ['A Jython Processing App'], JythonProcessingApp() )


To run it, with main.py open in the editor, click the little green button with a white arrow in the toolbar at the top left of the screen. If everything is working you should see a Processing app open. Right now it is not doing anything except redrawing a black screen on every frame, but that is a good start!

If you want to use Processing in the OPENGL mode there is one last step. You must add the path to the native OpenGL libraries. This is pretty trivial but took me quite a while to figure it out.

• Click the little down arrow next to the green run button and choose “Run Configurations”
• Under “Jython Run”, choose your project
• Selecte the “(x)=Arguments” tab
• In the VM Arguments box add this:
-Djava.library.path=YOUR PATH TO PROCESSING LIBS/Java/modes/java/libraries/opengl/library/macosx/

CAVEAT:

This will allow you to run Processing apps in OPENGL mode. That said, I have run into an issue where certain OPENGL commands seem to be failing. Hence, there is more work to be done.

Looking at the instructions above, this seems like a daunting task, but I assure you, that it is nothing more than installing a few things and understanding how to link them together.

Posted in Java, Processing, Python | 4 Comments

## Kinect SDK on a Mac

Earlier this summer I picked up a freelance Kinect gig. The client was pretty adamant about using the official Kinect SDK from Microsoft. The SDK is only available for Windows and as a Mac user, I had to make the decision wether or not to purchase a new Windows machine, try a virtual machine solution or use Bootcamp.

Purchasing a dedicated Windows box was the least risky, but the thought of having two computers around was not that appealing. Add to that the fact that the hardware specs on most consumer PC laptops are pretty limited compared to a the Mac and it is becomes harder to make an argument in favor of making the new purchase.

Knowing that the Kinect SDK required quite a large number of dependencies including both drivers and frameworks and that it requires considerable integration with actual hardware, the virtual machine option seemed pretty uncertain.

The last option, partitioning my disk and running Windows via Bootcamp became the most desirable solution. Still for many of the same concerns as running a virtual machine, I was certain that all of the drivers and frameworks would play nicely with Windows running on my Mac.

Just for clarity, here are my laptop specs:

Unibody Mac Book Pro
2.2 GHz Intel Core i7
8 GB 1333 MHz DDR3 Ram
128 GB Solid State HD

I ultimately ended up using Cinder and the KinectSDK block written by my friend Stephen Schieberl and documented here: http://forum.libcinder.org/topic/kinect-sdk-block and here: http://www.bantherewind.com/kinect-sdk-block-for-cinder.

The point of this article is to broadcast that it is not only possible to run the Kinect SDK on a Mac but that it works very well. I won’t go into detail about the installation process. Essentially you need to install Windows and then all of the dependencies for the SDK which are documented on the Kinect SDK website.

If you are running into problems, feel free to leave a question in the comments section or e-mail me personally.

Posted in Cinder, Kinect | Tagged , , , , | 8 Comments