A while ago, we got into bitmap animation using BitMapper. BitMapper was based on QuickDraws BitMap data structure. Since BitMaps are always 1 pixel deep, BitMapper was limited to black and white animation. This month, well colorize BitMapper, taking advantage of Color QuickDraws PixMap data structure.

PixMaps and GWorlds

The PixMap is much more complex than the BitMap. With BitMap animation, all you had to do was fill out the relatively simple BitMap structure, create a GrafPort, then connect the two via a call to SetPortBits(). Once thats done, you are ready to copy the BitMap from port to port via a call to CopyBits(). If you need a little refresher, check back to the BitMapper column (September, 93).

On the other hand, PixMaps are complicated beasties. Pop open your copy of Inside Macintosh, Volume V (or THINK Reference, if you prefer) and look up the PixMap data structure. To create a PixMap by hand, youd have to initialize all of those fields. Notice the pmTable field, listed as a handle to a color table (also known as a color lookup table, or CLUT). In addition to the PixMap fields, youve also got to create and initialize a ColorTable structure. Look it up.

This stuff is non-trivial. Fortunately, the Toolbox offers a high-level set of functions that make the creation of off-screen PixMaps relatively simple. These off-screen PixMaps are known as GWorlds. Off-screen simply means that you are creating something that is not drawn in a window on the screen. GWorlds are created in memory and typically drawn to a window via a call to CopyBits(), just as we did with BitMaps in BitMapper.

PixMapper

This months program is called PixMapper. PixMapper creates a window the size of the main screen and fills it in with a randomly generated sequence of colored squares. Next, PixMapper loads a PICT resource and uses a series of GWorlds to smoothly animate the PICT over the colored background.

As usual, well create the program this month, then go over the program details in next months column.

Creating the PixMapper Resources

Start by creating a folder named PixMapper inside your Development folder. Fire up ResEdit and create a file named PixMapper.Π.rsrc inside your PixMapper folder.

Now create an ALRT resource (along with a corresponding DITL resource) for our error alert. The ALRT resource should have a Top: of 40, a Left: of 30, a Height: of 116, and a Width: of 292. Be sure to set the DITL ID: to 128.

Next, create a DITL with an id of 128. Use the specifications in Figure 2 to create the OK button and the specifications in Figure 3 to create the error alerts static text item.

Figure 2. Specifications for the error alerts OK button.

Figure 3. Specifications for the error alerts static text item.

Next, create an MBAR resource with an id of 128. The MBAR should list four MENU ids: 128, 129, 130 and 131. Create four MENU resources according to the specifications in Figure 4. Be sure to include a separator line as the second item in the File menu. Also, be sure to mark the appropriate items in the Colors menu with a check mark (). Use the popup menu in the Mark: field to do this.

Figure 4. The four MENU resources.

Finally, go into the scrapbook (or your favorite graphics application) and use Copy and Paste to create a PICT resource in the resource file. Be sure that the PICT has a resource id of 128. When choosing your PICT resource, heres a couple of things to keep in mind. First of all, smaller is probably better. A smaller picture takes up less memory and contains less pixels to copy around in memory. Something around the size of a color icon is probably a good size to start with.

Next, you might want to create a picture that is non-rectangular or that has a hole in it, then use the lasso tool to select only the pixels in the picture (and not the background). Though a rectangular picture will work just fine, a non-rectangular picture (like an X or an O shape) produces much more impressive results.

Creating the PixMapper Project

Save your changes and quit ResEdit. Launch THINK C and create a new project named PixMapper.Π in the PixMapper folder. Add MacTraps to the project. Next, create a new source code window, save it as PixMapper.c and add it to the project.

As soon as you run PixMapper, the menu bar, featuring the , File, Edit, and Colors menus, will appear. Next, a window will appear, filling the entire main screen. PixMapper will fill the window with colored squares. Finally, PixMapper will animate the PICT, starting in the upper left corner moving towards the lower right corner. Every time the PICT hits the edge of the window, the PICT will bounce off and continue in the opposite direction.

Figure 5. PixMapper in action.

The speed of your PICT will depend on the speed of your machine and the size of the PICT. The important thing to notice is that the PICT animates smoothly with absolutely no flicker. If there is any hesitation, it is most likely due to the system taking time to do some housekeeping chore.

Try selecting Redraw from the File menu. PixMapper will redraw the window and start the animation over again.

Next, go to the Colors menu and play with all the different menu settings. PixMapper lets you play with both the RGB and HSV color models. RGB lets you set a colors red, green, and blue values. If you uncheck Random Reds for example, the screen will be redrawn with a red value of 0 (all greens and blues). If Random Reds is checked, the red component of the color is a random value from 0 to 65535.

If you select HSV Colors, youll be able to work with hue, saturation, and brightness rather than red, green, and blue. Unlike the RGB menu items, if you uncheck Random Hues, a colors hues component is set to 65535 instead of 0. Play around with these settings.

Till Next Month

Next month, well walk through the PixMapper source code. In the meantime, pop open Inside Macintosh and read about GWorlds and PixMaps. See you next month...

Community Search:

MacTech Search:

Software Updates via MacUpdate

Kodi 15.1.rc1 - Powerful media center to...

Kodi (was XBMC) is an award-winning free and open-source (GPL) software media player and entertainment hub that can be installed on Linux, OS X, Windows, iOS, and Android, featuring a 10-foot user... Read more

Bookends 12.5.8 - Reference management a...

Bookends is a full-featured bibliography/reference and information-management system for students and professionals.
Access the power of Bookends directly from Mellel, Nisus Writer Pro, or MS Word (... Read more

Chromium 44.0.2403.125 - Fast and stable...

Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all Internet users to experience the web.
Version 44.0.2403.125:
This release contains a number... Read more

iMazing 1.2.2 - Complete iOS device mana...

iMazing (was DiskAid) is the ultimate iOS device manager with capabilities far beyond what iTunes offers. With iMazing and your iOS device (iPhone, iPad, or iPod), you can:
Copy music to and from... Read more

Audio Hijack 3.2.0 - Record and enhance...

Audio Hijack (was Audio Hijack Pro) drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio... Read more

FontExplorer X Pro 5.0.1 - Font manageme...

FontExplorer X Pro is optimized for professional use; it's the solution that gives you the power you need to manage all your fonts.
Now you can more easily manage, activate and organize your... Read more

Calcbot 1.0.2 - Intelligent calculator a...

Calcbot is an intelligent calculator and unit converter for the rest of us. Featuring an easy-to-read history tape, expression view, intuitive conversion, and much more!
Features
History Tape -... Read more

MTR 5.0.0.1 - The Mac's oldest and...

MTR (was MacTheRipper)--the Mac's oldest and smartest DVD-backup app--is now updated to version 5.001
MTR -- the complete toolbox, not a one-trick, point-and-click extractor. MTR is intended for... Read more

LibreOffice 4.4.5.2 - Free, open-source...

LibreOffice is an office suite (word processor, spreadsheet, presentations, drawing tool) compatible with other major office suites. The Document Foundation is coordinating development and... Read more

Adobe Lightroom 6.1.1 - Import, develop,...

Adobe Lightroom is available as part of Adobe Creative Cloud for as little as $9.99/month bundled with Photoshop CC as part of the photography package. Lightroom 6 is also available for purchase as a... Read more

Bandai Namco has released Pac-Man Championship Edition DX on iOS and Android, which features the classic arcade gameplay that we've all grown to love.
Pac-Man Championship Edition DX can be enjoyed in much shorter bursts than the arcade versions... | Read more »

Angel Stone is Fincon's follow up to the massively successful Hello Hero and is out now on iOS and Android.
You play as a member of The Resistance, a group of mighty human warriors who have risen up in defiance of the Demon horde threatening to... | Read more »

The not exactly rumors were true and the birds are back. Angry Birds 2 has come to the App Store and the world will... well I suppose it'll still be the same, but now we have more bird-flinging options!
[Read more]
| Read more »

You Could Design Your Own Card for Chain...

If you've ever wanted to create your own item, weapon, trap, or even monster for Chainsaw Warrior: Lords of the Night, this is your chance. Auroch Digital is currently holding a contest so that fans can fight to the death (not really) to see which... | Read more »

Bitcoin Billionaire is Going Back in Tim...

If you thought you managed to buy everything there is to buy in Bitcoin Billionaire and make all the money, well you though wrong. Those of you who made it far enough might remember investing in time travel - and it looks like that investment is... | Read more »

Domino Drop (Games)

Domino Drop 1.0
Device: iOS Universal
Category: Games
Price: $1.99, Version: 1.0 (iTunes)
Description:
Domino Drop is a delightful new puzzle game with dominos and gravity!Learn how to play it in a minute, master it day by day.Your... | Read more »

Best Buy has iPad Air 2s on sale for up to $100 off MSRP on their online store for a limited time. Choose free shipping or free local store pickup (if available). Sale prices available for online... Read more

B&H Photo has the 13″ 1.6GHz/128GB MacBook Air on sale for $899.99 including free shipping plus NY tax only. Their price is $100 off MSRP, and it’s the lowest price available for this model.... Read more

Worldwide Tablet Market Decline Continues, Ap...

The worldwide tablet market declined -7.0% year-over-year in the second quarter of 2015 (2Q15) with shipments totaling 44.7 million units according to preliminary data from the International Data... Read more

The Apple Store has Apple Certified Refurbished iPad Air 2s available for up to $140 off the price of new models. Apple’s one-year warranty is included with each model, and shipping is free:
- 128GB... Read more

Updated Apple iPad Price Trackers

We’ve updated our iPad Air Price Tracker and our iPad mini Price Tracker with the latest information on prices and availability from Apple and other resellers.
Read more

Apple refurbished 2014 13-inch 128GB MacBook...

The Apple Store has Apple Certified Refurbished 2014 13″ MacBook Airs available starting at $759. An Apple one-year warranty is included with each MacBook, and shipping is free:
- 13″ 1.4GHz/128GB... Read more

Apple’s Education discount saves up to $300 o...

Purchase a new Mac or iPad at The Apple Store for Education and take up to $300 off MSRP. All teachers, students, and staff of any educational institution qualify for the discount. Shipping is free,... Read more

MacTech is a registered trademark of Xplain Corporation. Xplain, "The journal of Apple technology", Apple Expo, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, Apple Expo, MacTech Central, MacTech Domains, MacNews, MacForge, and the MacTutorMan are trademarks or service marks of Xplain Corporation. Sprocket is a registered trademark of eSprocket Corporation. Other trademarks and copyrights appearing in this printing or software remain the property of their respective holders. Not responsible for typographical errors.

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.