ImageCalc
This program displays an image which is being continuously updated. The image (which is calculated in a separate thread) is a black & white triangle that transforms into a random pattern of grey pixels. One of the calculation parameters is controlled via a slider and a key goal of this project was to have the calculation ongoing with the image continuously updating even while the user is moving the slider around. As this project was a test bed for a compute-intensive program where performance is important, I tried to make the image display as efficient as possible. Statistics on the update rates for the calculation ("model") and display ("view") are available in a drawer that can be opened via the Window menu.
download the ImageCalc project files
(Requires the Apple Developer Tools - I used the December 2002 release)
This project illustrates several aspects of programming for Mac OS X using the Cocoa API:
- calculation in a separate thread
- synchronizing use of shared variables via NSLock
- image drawn via NSBitmapImageRep in a subclass of NSView
- regular display updates via NSTimer
- using NSEventTrackingRunLoopMode to get timer events while mouse is down
- handling window resizing via inLiveResize
- handling model size constraints when resizing
- auxiliary information displayed in an NSDrawer