Erik’s Brain

The reward of a thing well done...

Instructions for Life

I just found this in my email archive. From a message received on September 29, 1999. Almost ten years ago? WOW.

INSTRUCTIONS FOR LIFE

  1. Eat much brown rice.
  2. Give people more than they expect and do it cheerfully.
  3. Memorize your favorite poem.
  4. Don’t believe all you hear, spend all you have, or sleep all you want.
  5. When you say, “I love you”, mean it.
  6. When you say, “I’m sorry”, look the person in the eye.
  7. Be engaged at least six months before you get married.
  8. Believe in love at first sight.
  9. Never laugh at anyone’s dreams.
  10. Love deeply and passionately. You might get hurt but it’s the only way to live life completely.
  11. In disagreements, fight fairly. No name calling.
  12. Don’t judge people by their relatives.
  13. Talk slowly but think quickly.
  14. When someone asks you a question you don’t want to answer, smile and ask,“Why do you want to know?”
  15. Remember that great love and great achievements involve great risk.
  16. Call your mum.
  17. Say “bless you” when you hear someone sneeze.
  18. When you lose, don’t lose the lesson.
  19. Remember the three R’s: Respect for self; Respect for others; Responsibility for all your actions.
  20. Don’t let a little dispute injure a great friendship.
  21. When you realize you’ve made a mistake, take immediate steps to correct it.
  22. Smile when picking up the phone. The caller will hear it in your voice.
  23. Marry a man/woman you love to talk to. As you get older, their conversational skills will be as important as any other.
  24. Spend some time alone.
  25. Open your arms to change, but don’t let go of your values.
  26. Remember that silence is sometimes the best answer.
  27. Read more books and watch less TV.
  28. Live a good, honorable life. Then when you get older and think back, you’ll get to enjoy it a second time.
  29. Trust in God but lock your car.
  30. A loving atmosphere in your home is so important. Do all you can to create a tranquil harmonious home.
  31. In disagreements with loved ones, deal with the current situation. Don’t bring up the past.
  32. Read between the lines.
  33. Share your knowledge. It’s a way to achieve immortality.
  34. Be gentle with the earth.
  35. Pray. There’s immeasurable power in it.
  36. Never interrupt when you are being flattered.
  37. Mind your own business.
  38. Don’t trust a man/woman who doesn’t close his/her eyes when you kiss.
  39. Once a year, go someplace you’ve never been before.
  40. If you make a lot of money, put it to use helping others while you are living. That is wealth’s greatest satisfaction.
  41. Remember that not getting what you want is sometimes a stroke of luck.
  42. Learn the rules then break some.
  43. Remember that the best relationship is one where your love for each other is greater than your need for each other.
  44. Judge your success by what you had to give up in order to get it.
  45. Remember that your character is your destiny.
  46. Approach love and cooking with reckless abandon.

Bee Paper - Pen Sketcher's Pad

I went to Flax Art looking for some paper that would work nicely with pens. Ideally it would work nicely with the Sakura Pigma Micron pens. But, like always I couldn’t find what I was looking for: nice smooth, pen friendly paper in a wire-bound pad. Sure, there are plenty of expensive papers made specifically for pens and markers. This paper is great, but it never comes wire-bound. And, like I just said, it’s also on the pricey side.

On my way out I passed the pens section and what did I find? A cheap pad of wire-bound paper for pens. And not just any pens, it says on the cover that it’s recommended for use with Sakura Pigma Micron Pens! And it’s only $5.25 for 50 sheets of 8.5 x 11! Oh Bee Paper Company, you read my mind.

Img 0800

I brought it home to test and, sure enough, it works great with the Microns, both fine tip (01) and broad tip (08). There is some visible feathering with the UniBall Vision Exact pens that I love, but it doesn’t bleed through at all. And for $5.25, I’m really happy with this.

The other thing I should point out is that there is some obvious watermarking on the sheets of paper. It’s lightly embossed with “HAMMERMILL PAPER.” I didn’t notice this in the store, but it was pretty obvious once I got home. But, considering the price and how well it works with the pens I want it to work with, I’m fine with that. Beggars can’t be choosers.

What a Bargain!

The domain name perfectionist.com can be had for the low LOW price of $34,388! Where did I put my Juniper Visa? I’d get $325 worth of iTunes downloads if I bought it.

whatadeal

MacBook Keyboard + Scotch Tape = Happiness

Using Scotch tape to clean a MacBook keyboard works surprisingly well. Apply a strip of tape across a row of keys. Rub the tape onto each key really well with your fingernail. Then peel off. I’m actually pretty impressed by this.

Lensbaby Composer

I finally took the plunge and purchased a Lensbaby Composer a week ago. I decided to add on the new super wide angle adapter, the macro filters, and a single glass element. It showed up Tuesday and I immediately had a blast with it while hanging out with my friend Jessica in Berkeley. It’s really like getting a second life in photography. If you feel like you are kind of stuck in a rut, I’d suggest you check it out.

muni

One thing that’s so exciting about it is that it’s very affordable. Okay, the Composer itself is $270, which isn’t exactly cheap. BUT, the super wide angle adapter was only around $80. The macro kit was only about $35 and the single glass optic that I can use in place of the double glass optic that shipped with the Composer, was only $35. The swappable optics are the really exciting part of this. Between the double glass, single glass, and wide angle adapter, I’ve basically got four different combinations for less than $400. And I’m certainly going to be getting the other two optics (plastic and pinhole). Lots of lenses for not a lot of money. Since the only lens I had for my 40D is the 85mm f1.2, I was really in need of something that would be more versatile and this really filled that void.

Jessica

Now the bad news. An hour before my birthday party started yesterday, I was pulling the cap off of the super wide angle adapter while it was attached to the Composer and the Composer essentially ripped apart at the seams. It was not pretty. I’ll be kind to the Lensbaby peeps and not post a picture of it. I’m being nice because their Director of Customer Happiness emailed me tonight and said they would ship me a new one right away. That’s service. A response at 9:30pm on a Sunday. But probably more importantly is they are doing the swap the right way: sending me a new one before they even get the broken one back from me. Outstanding. I can’t wait to get it in my hot little hands!

I Can't See the Crop Tool!

I ran into this issue a while ago and wanted to post the fix. On my white MacBook, I was having the hardest time in the world seeing the outline of the Photoshop CS4 crop tool. It made it a huuuge pain in the butt to make precise, to-the-pixel, crops. I thought it was just the screen, since it isn’t the great screen in the world, even for a laptop. But I quickly realized it really wasn’t the screen. Take a look at what my crop tool was looking like on my MacBook:

Probably Not Good Advice

Should Cheetos really be telling people to analyze what they eat before they eat it?

Cheetos

I didn’t think so.

Way to Go, MSI

They’ve done a quite a job of taking a great design and crapifying it. I like how the indicators below the track pad make it look like the front edge of the notebook is serrated. And the vents on the underside make it look like a shark. But they are going all out. They’ve also got some displays that look a lot like the original Apple LCDs. And how about those “new” all-in-one PCs?

Hit Area of External Assets With Alpha Channels (PNGs and SWFs)

Let’s say you are loading in an external asset that has an alpha channel, such as a PNG or a SWF*. Now let’s say that you want that asset to act like a button, with rollover and click actions. No problem. No reason you can’t do that.

But, actually, there is a problem. The hit area for that external asset will be its entire bounding box.

Take this octy image for example:

Octy

Even if you rolled over the top left of the image where it’s totally transparent, it will still trigger rollover actions, which is certainly not ideal and could potentially be very confusing for a user. This isn’t what happens if you have that image sitting in the library and you then add it to the stage at run time. But c'mon, we need it to work right with externally loaded assets! Of course I wouldn’t be writing this if I was just bitching and moaning. I’ve got a solution!

First, here’s the code in its entirety:

package
{   
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.filters.*;

    public class Main extends Sprite
    {
        // this will hold the external asset and will act like a button
        public var s:Sprite

        public function Main()
        {
            init();
        }

        private function init():void
        {
            var l:Loader = new Loader();
            l.contentLoaderInfo.addEventListener(Event.INIT, assetLoaded);
            l.load(new URLRequest("octy.png"))
        }

        private function assetLoaded(e:Event):void
        {
            // copy the content of the loaded asset into a new BitmapData object
            var bmpData:BitmapData = new BitmapData(e.target.content.width, e.target.content.height, true, 0);
            bmpData.draw(e.target.content, null, null, null, null, true);
            var newBmp:Bitmap = new Bitmap(bmpData, "auto", true);

            s = new Sprite();
            s.x = s.y = 50;
            s.addChild(newBmp);
            addChild(s);

            // make our Sprite act like a button
            s.addEventListener(MouseEvent.CLICK, clickHandler)
            s.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler)
            s.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler)
            s.buttonMode = true;
        }

        // when you roll over the Sprite, create a MOUSE_MOVE listener
        private function rollOverHandler(e:MouseEvent):void
        {
            s.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler)
        }

        // when you roll off of the Sprite, remove the MOUSE_MOUSE listener
        private function rollOutHandler(e:MouseEvent):void
        {
            s.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler)
            hideGlow();
        }

        // constantly check the alpha value of the pixel under the mouse pointer
        private function mouseMoveHandler(e:MouseEvent):void
        {
            var av:int = getAlpha(s)
            // if the pixel under the mouse isn't transparent,
            // show the hand cursor and turn on the image's glow 
            if (av > 0)
            {
                s.useHandCursor = true;
                showGlow()
            }
            // otherwise hide the hand cursor and turn off the glow
            else
            {
                s.useHandCursor = false;
                hideGlow()
            }
        }

        private function clickHandler(e:MouseEvent):void
        {
            var av:int = getAlpha(s)
            if (av > 0)
            {
                //do whatever it should do on click!
            }
        }

        private function showGlow():void
        {
            s.filters = [new GlowFilter()]
        }

        private function hideGlow():void
        {
            s.filters = []
        }

        // a little helper function that returns the alpha value of
        // the pixel under the mouse pointer
        private function getAlpha($t:Sprite):int
        {
            var bmd:BitmapData = Bitmap($t.getChildAt(0)).bitmapData;
            var av:int = (bmd.getPixel32($t.mouseX, $t.mouseY)) >> 24 & 0xFF
            return av;
        }
    }
}

The idea is pretty simple. Since Flash isn’t smart enough to handle things the way we’d like, we’ll just have to do it ourselves. To do that we’ll use BitmapData.getPixel32() to find the alpha value of the pixel underneath the mouse whenever the mouse moves. If that pixel’s alpha value is 0, then we’ll act like we aren’t over the button. But if the alpha value is greater than 0, then we will act accordingly by showing the hand cursor and triggering any cool rollover effects (in this case just a simple Glow Filter).

private function mouseMoveHandler(e:MouseEvent):void
{
    var av:int = getAlpha(s)
    // if the pixel under the mouse isn't transparent,
    // show the hand cursor and turn on the image's glow 
    if (av > 0)
    {
        s.useHandCursor = true;
        showGlow()
    }
    // otherwise hide the hand cursor and turn off the glow
    else
    {
        s.useHandCursor = false;
        hideGlow()
    }
}

But since you don’t want to waste CPU cycles by constantly checking the mouse position when you don’t need to, we’ll only enable that MOUSE_MOVE event listener when the mouse is over the bounding box of the externally loaded asset.

private function rollOverHandler(e:MouseEvent):void
{
    s.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler)
}

When you roll off of the bounding box, remove the listener.

private function rollOutHandler(e:MouseEvent):void
{
    s.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler)
    hideGlow();
}

The same kind of logic is used for the CLICK event handler. You only actually do anything if the mouse isn’t over the transparent part of the image.

private function clickHandler(e:MouseEvent):void
{
    var av:int = getAlpha(s)
    if (av > 0)
    {
        //do whatever it should do on click!
    }
}

So that should give you a pretty good idea of how to do this in your own project where needed. Hopefully someone in need finds this post and saves themselves a lot of effort!

*A word on SWFs as images

SWFs are a great alternative to PNGs if you need external images to have nice alpha channels. By using a tool like Fireworks you can open a PNG with a nice alpha channel and then save it as a SWF. This is great because by saving the PNG as a SWF, you keep the alpha channel AND get JPEG compression which will give you MUCH smaller file sizes. The PNG to SWF conversion is an extra step (why why why can’t you just save to SWF direct from Photoshop?) but it might be worth it depending on your situation.