Thoughts from a NeXTStep Guy on Cocoa Development

vImage & Image Processing

Mar 22, 2012 by Bill Dudney

Last week at CocoaConf I went to Jeff's excellent talk on the Accelerate framework for the second time. After the first time I sat through it I promised myself I'd learn to hack on vImage just to see what's possible. The span between Raleigh and Chicago was enough that I was embarrassed that I'd done nothing. I went again and sat in the back and coded while Jeff talked. I was able to get a first cut working (filled with memory leaks and bogus image conversion) but that evening Jeff and I spent a couple of hours hacking around and making the code all nice and pretty.

I've done a bit more clean up and posted it to github here. It is not nearly everything I wanted to do but I figured if I posted about it that someone else might be able to take it further.

I blurred the faces in the picture. The image was taken at DisneyWorld in Downtown Disney at the LEGO store.

Permalink     Add A Comment

The NeXT Big Thing

Oct 06, 2011 by Bill Dudney

I've never been much on rules. I finished High School at the very top of the 3rd quartile. I always looked at my time in high school as more or less a tedium to be endured. I floated around a bit after HS wondering what I'd do with my life. I took a couple of classes at a local community college but those teachers were not much more inspiring that my high school teachers.

The second year after graduation a friend convinced me to join him at a 'live in' junior college. I enjoyed my history class, the teacher was crazy. He brought history to life, encouraged me to get into the minds of the people that lived it. But the rest was just more tedium, endured to get a grade that proved I could sit for 3 hrs a week and regurgitate some facts...

Another friend was headed to Texas A&M to study Aero-Space engineering, I loved Star Trek growing up and that sounded about as close as I'd ever get to a warp drive. So I joined him.

I loved the classes, they challenged me to stretch, learn and think deeply about very technical topics. And, it seemed like life building the stuff that got astronauts into space and kept them alive would be pretty cool. And maybe, just maybe I'd have a shot at becoming one of those fortunate few that got into space.

My junior year I joined a group of 3 other students working on keeping planes from going into flutter. Flutter is very bad for planes, it's like the opera singer hitting just the right note, but instead of a wine glass its a dad/son/mother/daughter and a $30M plane being destroyed. The professor was brilliant, the topic deep and difficult and intensely mathematical.

Naturally, we used Mathematica to explore the problem.

To use Mathematica we had to have a beefy computer and our department had just acquired a beautiful new NeXT cube. I instantly fell in love with this computer. Everything about it was new and exciting. After working non-stop on the flutter problem for a couple of months I decided I wanted to go deeper and figure out how to build my own apps.

As the new semester rolled around I had a new infusion of student loan money, that, along with the limit of 2 credit cards gave me the buying power to get my very own NeXT slab.

I had found my calling, that crazy thing that my heart, my intuition knew about. I wanted to build stuff, crazy stuff, beautiful stuff. AeroSpace Engineering and the potential of becoming an astronaut were now secondary.

Thanks Steve for picking up the pieces of what must have felt like a monumental failure and doing something great with it. I owe my entire professional life to you having the courage to keep on keeping on.

I will cary on that legacy by being the absolute best me that I can be. And I will always remember:

Your time is limited, so don't waste it living someone else's life. 
Don't be trapped by dogma — which is living with the results of other people's thinking.
Don't let the noise of others' opinions drown out your own inner voice. 
And most important, have the courage to follow your heart and intuition. 
They somehow already know what you truly want to become. 
Everything else is secondary.

Thank you for staying foolish and staying hungry.

Permalink     1 Comment - Add Yours

Boulder Developer Day - Core Animation

Oct 12, 2009 by Bill Dudney

Here is my very brief introduction to Core Animation on the iPhone.

And you can find the source here; Photo Search source code.

Permalink     Add A Comment

Following iPhone Dev's on Twitter

Jan 27, 2009 by Bill Dudney

@timhanes put out a call last night for iPhone dev's on twitter to put their handle, name, and apps into a Google spread sheet via this form. The last time I looked there were over 200 devs.

Trying to follow everyone manually is a major pain in the tedious muscle. But thankfully posted a ruby script that will do the following for you in this post.

Thanks Tim & David for helping us all stay in touch!

Permalink     1 Comment - Add Yours

Beta 9 of iPhone Book is out

Jan 16, 2009 by Bill Dudney

On vacation but thankfully Daniel and Chris are not :) Grab your copy here.

Permalink     5 Comments - Add Yours

TiledLayer on the iPhone

Dec 08, 2008 by Bill Dudney

I finally got the tiled layer example ported to the phone. The SFMuni map was killing performance and takes forever to draw so I did a simple keynote slide with some text and a few shapes so it would not be too simple. This slide PDF draws very fast on my 3G iPhone. You can grab the code here. If you want to go back to the SFMuni map, just change the code in the sfMuni method of TiledDelegate class.

As the comments in the code say this is not an attempt to teach you how to handle events. I just hacked some stuff together enough to get zooming and panning working well enough to experiment with the pdf drawing so use it as that.

I hope it helps!

Permalink     16 Comments - Add Yours

Using the TrackBall

Oct 19, 2008 by Bill Dudney

So I had several pings on twitter yesterday on getting a simple example in place. So since I could not sleep this AM anyway I spent a few minutes putting one such example together. Here is a screen shot of the initial scene. Looks simple enough, two images both in layers contained in a third layer. Straightforward enough.

Just to make things interesting I put a small rotation around the X axis on each of them. Of course you can't see that right now because we are looking straight down the Z axis and the rotation is not enough to distort the images. But what happens if you move around the scene via the trackball from my last post. Well you can see the 3D nature of the scene of course :)

I placed the code here. This is one of the examples I'll be talking about @iPhoneLive, hope to see you there! And if you are really spontanious, would be great to have you @CSS where I have 90 minutes to talk CA and CA alone.

Happy hacking!

Permalink     5 Comments - Add Yours

TrackBall - 3D transforms made easy

Oct 18, 2008 by Bill Dudney

Apart from getting all my existing CA examples onto the iPhone I've also been toying with what the best way to build out the 'photo city' demo from WWDC 2008 would be (my next Core Animation screen cast series). The basic idea of the demo was that you had a set of perhaps 30 or 40 images, the images were combined into cubes and the cubes were used to make a 'city'. After getting a basic cube working I got distracted by some of the stuff I did to make the demo. Namely I finally got around to porting the OpenGL trackball example code to Core Animation.

For those that are not familiar with the trackball example; the idea is that you have a transparent sphere around your scene, you can move the scene around by moving the trackball. As you move your finger to the right it pushed this imaginary sphere around its center to the right (exposing the left side of the scene).

I'm not 100% sure this is the right API to have for such an object but I was able to use it in a couple of examples for a course I'm working on. I also will be using in one of the demos for my talk at iPhone Live. So while it might not be perfect I figure its good enough to post now. Please feel free to comment with what you think would be better.

Now on to document the TrackBall class. The idea is that you have a 2D viewport into a 3D scene, this view port has a width and height (i.e. the CGRect that defines the layers bounds). In this 3D world you construct an imaginary sphere with a radius of the minimum of height or width of your view port centered on the center of your scene. When the event begins (with a touchesBegan:withEvent:) you initialize the trackball with the touches location as the starting point. A vector is constructed from the center of the sphere to the touch (the depth dimension is calculated based on the radius of the sphere). As the user moves her finger around on the screen another vector is constructed from the center of the sphere to the current touch location (as received in touchesMoved:withEvent:). The cross product of these two vectors is the vector of rotation and the angle between them is the magnitude of the rotation.

Practically what all this means is that in the touchesBegan:withEvent: method you call the setStartPointFromLocation: method with the location of the touch (if you don't have multi touch turned on for the view there will be only one touch in the touches set, so you can use the anyObject method to get the touch, code to follow shortly). That initializes the trackball so it knows the first vector (from the center of the sphere to the starting point). As the user drags his finger around on the screen you call rotationTransformForLocation: to get a CATransform3D. This transform encapsulates the rotation vector and angle so you don't really have to grok it to use it (although it helps:). Next you set your layer's sublayersTransform property to this transform.

The scene contained in your layer will now rotate as if it existed in a sphere and you were moving that sphere around. Its a cool effect if you've never seen it before. If you want the trackball to remember where it is when the user picks up her finger you simply call finalizeTrackBallForLocation: with the touch location from the touchesEnded:withEvent: method. Now onto some code. Here is the code to initialize the trackball;

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint location = [[touches anyObject] locationInView:self];
if(nil == self.trackBall) {
self.trackBall = [TrackBall trackBallWithLocation:location inRect:self.bounds];
} else {
[self.trackBall setStartPointFromLocation:location];

In this example I'm keeping the trackball and finalizing it in the touchesEnded: method (we will see that shortly). Next up I get the transformation from the trackball in the touchesMoved:withEvent: method.

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint location = [[touches anyObject] locationInView:self];
CATransform3D transform = [trackBall rotationTransformForLocation:location];
transformed.sublayerTransform = transform;

Then in the touchesEnded:withEvent: method I finalize the trackball so it knows where it left off on the next event cycle.

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint location = [[touches anyObject] locationInView:self];
[self.trackBall finalizeTrackBallForLocation:location];

And finally here is the code. Happy hacking!

Permalink     4 Comments - Add Yours

iPhoneLive Preview WebCast

Oct 14, 2008 by Bill Dudney

I'm going to be doing a live webcast with O'Reilly today. You can join me here. Should be fun Raven and I are going to give a preview of our talks as well as Q&A. Be great to see you there.

Permalink     Add A Comment


Oct 07, 2008 by Bill Dudney

One week till early reg runs out for iPhoneLive. Would love to see you there!

Also don't forget to use the discount code ip08gd20 at registration for a cool 20% off.

I'll also be doing a webcast preview of my talk and answering questions afterwards along with my co-chair Raven. Please join if you can!

Permalink     Add A Comment

Core Animation Book At the Printers

Oct 03, 2008 by Bill Dudney

So the Core Animation book is finally really at the printers with the iPhone goodness in tact. Should be in boxes and on its way to a bookshelf near you by 10/20. Thanks to the NDA being lifted and the amazing company that is PragProg we were able to switch from printing without the iPhone chapter on Monday to printing with it by Thursday. I can't say enough good about the Prags and how much fun they are to work with as an author.

If you signed up for the beta you can grab your full PDF copy now at the book's site. Thanks again to all the folks that helped out with the book. The tech review team and everyone on Twitter that put up with me bouncing off the walls on Wednesday. Thanks!

I really can't wait to see all the cool stuff that people do with CA, its very very cool technology.

And while you are at the site check out the great Mac titles that the Prags are putting together. My new favorite is from Daniel Steinberg called Cocoa Programming: A Quick-Start Guide for Developers. I expect that to become THE newbie Cocoa book.

Permalink     10 Comments - Add Yours

20 Minute Free Intro to iPhone Development

Oct 02, 2008 by Bill Dudney

My iPhone screencast has a 20 minute intro to building a simple iPhone app with a bit of depth about how Xcode and IB can be used to build your first iPhone App. And its free :)

I think it fits nicely in the 'how do I start' space of learning iPhone Development.

Permalink     6 Comments - Add Yours

Never mind about the last post... NDA has been lifted!

Oct 01, 2008 by Bill Dudney

No More NDA!

And there was much rejoicing!

Permalink     2 Comments - Add Yours

NSColor & CGColorRef

Sep 06, 2008 by Bill Dudney

While writing an example of how to understand the 3D transforms possible with CALayer I had a bit of an epiphany about how to make building colors easier. Instead of the utility class I'd been using I cooked up this little category on NSColor. Of course I should have thought of this first but my brain has been weakened by years of Java coding...

@implementation NSColor(CGColor)

- (CGColorRef)CGColor {

    CGColorSpaceRef colorSpace = [[self colorSpace] CGColorSpace];

    NSInteger componentCount = [self numberOfComponents];

    CGFloat *components = (CGFloat *)calloc(componentCount, sizeof(CGFloat));

    [self getComponents:components];

    CGColorRef color = CGColorCreate(colorSpace, components);


    return color;



This has the disadvantage of creating a new instance on each call. If you (or I) wanted to get really fancy you could look to see if the NSColor is a named instance and if so place the CGColorRef into a CFDictionary and thus cache the CGColorRef's but I think I'll leave that to my next Epiphany.

Code is licensed under Apache 2.0, do with it what you will.

Permalink     2 Comments - Add Yours

Man What A Day

Sep 03, 2008 by Bill Dudney

Man what a great day.

First off 3 of my kids plus another 6 or 7 of their friends are part of the inaugural FIRST Summit County Lego League. It should be a great time for sure, I totally can't wait to have 8 to 10, 9 to 14 year olds building Lego Robots in my office once or twice a week. Our first competition in Nov 8 in Colorado Springs. It's going to be great fun!

Next up the Cocoa Pragmatic Studio was finally announced publicly today. It's going to be a great time learning the ins and outs of Cocoa development. If you are new to Cocoa (Touch or Regular) there is a ton you can and will get out of this 3 day intensive class. Promises to be NDA breakage free too so nothing to worry about there...

I finally got to push a new version of Dot Game out the door. Still working on the Bonjour support but had a couple of feature requests and bug reports that I finally took the time to crank out.

Now if the NDA would just lift I'd have even more cool stuff to do and talk about! :)

Permalink     Add A Comment