February 2017

Monday, February 13, 2017

How to Make a Digital Valentine's Day Card


Description

Valentine's Day is tomorrow. Here's how to make a digital card to capture the heart of your sweetie. Well, OK, that might be overstating things a bit, but Harley does show an algorithmic way using trigonometry to generate a beating heart animation in an easy to use programming environment called Processing. This was inspired by a video LeiosOS posted last week.

The original inspiration: LeiosOS: Drawing a heart
Wolfram algorithm site: Heart shaped graphs

For a written transcript, go to How to Make A Digital Valentine's Day Card

Music and special effects under Creative Commons License By Attribution 3.0
Intro/Exit: "Hot Swing" by Kevin MacLeod at http://incompetech.com
Incidental: “Carefree” by Kevin MacLeod at http://incompetech.com

livingroom_light_switch by AlienXXX at http://freesound.com

Transcript

Today at the House of Hacks we're going to make a high-tech Valentine's Day greeting.

[Music]

Hi Makers, Builders and Do-it-yourselfers. Harley here.

I recently ran across a new-to-me programming channel who's name I won't even begin to try to pronounce but I will link to in the cards and description below.

He did a video about drawing a heart where he used a bit of C code and his own graphics library.

I want to take his idea, expand a bit on why it works and show how to use the Processing programming environment to do the same thing.

First let's look at generating shapes...

Many people get overwhelmed by the thought of trigonometry with its sine and cosine, angles and other related things, but at its core, it’s really pretty simple.

Remember the old cartesian graph from math class?

It had an x-axis and a y-axis and points could be located on this graph using just two coordinates.

On this graph, let’s draw a circle with its center at the origin with a radius of one.

Now, let’s imagine a line starting at the origin and going through the circle.

We can draw this line at any angle from the x axis.

If it is on the axis it will be 0 degrees.

Regardless of where we draw it, it’s going to intersect the circle at only one place.

That one place will have an x and y coordinate that, by definition, is the value of the cosine and sine functions at that angle.

So, for 0 degrees, the place where the circle intersects the x-axis, cosine will be 1 and sine will be 0.

As the angle increases, the x value decreases and the y value increases until we get to 90 degrees.

This lies on the y axis where cosine is 0 and sine is 1.

As the angle continues to increase, the x and y values continue to change, always between 0 and 1, always on the circle.

And that’s the fundamental theory behind trigonometry, everything else is derived from this.

Now let’s plot these points a bit differently.

On the x axis, let’s plot the angle and on the y axis, let’s plot of value of sine remembering that sine is the y value on our original circle.

At 0 degrees, sine is 0 so we start at the origin.

As the angle increases, sine increases until we get to 90 degrees and reach 1, then it starts decreasing as we move into the second quadrant of the circle.

At 180 degrees sine is back to 0.

As the angle continues to increase, the y coordinate of our circle drops into the negative values in the third quadrant until it reaches -1 at 270 degrees.

Finally in the fourth quadrant, we see y coming back up to 0.

After this, the cycle simple repeats itself as higher angles are duplicates of the previous angles.

Now, doing the same thing with cosine, at 0 degrees, cosine is 1 since it represents the x value on the circle.

As the angle increases, x decreases to 0 at 90 degrees, -1 at 180, back up to 0 at 270 and finally 1 at 360 degrees, the place we started.

These functions are great for describing a lot of things that are periodic in nature, things that fluctuate between two values.

If we multiply the results of sine or cosine we can make these graphs fluctuate by a different amount.

For example, here’s the result of multiplying the sine by 2.

And if we multiply the angle by a value, the frequency of the fluctuation will increase or decrease.

Here’s what it looks like if we multiply the angle by two.

Things can get really wild if we start adding these two curves together.

Or subtracting them.

Or multiplying them.

Or doing anything else really.

Sines and Cosines are the basis for a lot of things in our modern world.

Today we’re going to see how they can be used to send a message to our sweetheart.

Processing is a programming environment that was developed about 15 years ago and designed to teach the basics of programming within a visual context.

Since it was designed with a visual context in mind, it’s great for experimenting with graphics and drawing things.

The Processing.org website has free installers for Windows, Linux and Macs.

Just download the installer and run it.

This gives us a a Processing environment that, once started, we can start writing programs in.

Let's look at a simple program to draw a circle.

We first define the size of our canvas, the color of our background and the color we want to draw in.

Then we’re going to define a variable to scale our circle by and an offset for the x and y coordinates.

These are needed because sine and cosine return values around the cartesian origin but the coordinate system of the Processing screen is based with 0,0 in the upper left corner of the canvas.

Then we’re going to define a loop from 0 to twice PI, going in small increments.

We used twice PI here because in computers cosine and sine typically use what are called radians instead of degrees as their inputs.

This is just fine though because there’s a one to one mapping between degrees and radians where PI is 180 degrees and two PI is 360 degrees.

Inside the loop we set x to the cosine value of the loop variable and y to the sine value of the loop variable.

Then we’re simply going to plot that point, offset and scaled by the previously defined values.

Let's save our work at this point.

When we press the arrow button in the top tool bar, our program runs and we get this nice circle.

Now that we have the basics of creating a circle, how’s this help us with our Valentine Day project?

A web search for “heart drawing formula” leads us to the Wolfram site that has a number of different formulas for drawing a heart shape.

The sixth one in particular lends itself well to the program we have for drawing a circle.

All we have to do is change the assignments to x and y to get something that looks like a heart.

One of the cool things about the Processing environment is it works well for animating things.

If we put the statements before the loop in a function called setup they will get called one time when we run our program.

Then if we put the loop inside a method called draw, it will get continually called over and over again.

But because we’re drawing the same thing over and over, it's not going to be too exciting.

So before running this, let's add a line to change the scaling each time the draw method is called and adjust a control parameter to keep the scale between a couple values.

Finally, move the background call from setup into draw so it happens every time draw is called. This will clear our canvas each time.

Now let’s run this.

Ah, a nice beating heart.

This is cool and all, but it’s hard to show our special someone.

By adding a line to the end of our draw method, we can tell Processing to save our drawing to a file.

Now let's run this for a little bit, stop it and go look at where we saved our program.

We can see a bunch of individual snapshots of each frame of our animation.

In one last step, we can go to Processing’s Tools menu and select Movie Maker.

It gives us a dialog where we can select the directory containing the shots of our animations and press the Create Movie button.

This compiles our individual images into a MOV file that we can e-mail to our intended.

[Music]

If this is your first time here at House of Hacks: Welcome, I’m glad you’re here and would love to have you subscribe.

I believe everyone has a God-given creative spark.

Sometimes this manifests through making things with a mechanical and technical bent.

Through this channel I hope to inspire, educate and encourage these types of makers in their creative endeavors.

Usually this involves various physical media like wood, metal, electronics, photography but sometimes other things, like programming.

If this sounds interesting to you, go ahead and subscribe and I’ll see you again in the next video.

Now, go make something. Perfection’s not required. Fun is!

Sunday, February 5, 2017

How to replace an Apple MacBook Air's dead battery


Description

Replacing the battery on Apple Macbook Air is really simple and only requires a couple minutes work. In this episode, Harley shows the couple steps needed to change the battery in an mid-2011 MacBook Air and restore it to its original capacity.

Rechargeable batteries have a finite lifetime, wear out as they’re used and need to be replaced. Unlike PC laptops, MacBook’s give a warning when the battery approaches end-of-life and needs to be replaced. Applications like CoconutBattery give additional information.

Purchase battery kit on Amazon (Associates link).

More about the pentalobe screw.

CoconutBattery website

For a written transcript, go to How to replace an Apple MacBook Air's dead battery

Videography by Rich Legg

Music and special effects under Creative Commons License By Attribution 3.0
Intro/Exit: "Hot Swing" by Kevin MacLeod at http://incompetech.com
Incidental: “Mining by Moonlight” by Kevin MacLeod at http://incompetech.com

livingroom_light_switch by AlienXXX at http://freesound.com

Transcript

Rechargeable batteries wear out over time. MacBooks will give a warning when their battery is approaching their end of life and won’t hold a charge. Today at the House of Hacks we’re going to see how easy it is to replace one of these aging batteries.

[Music]

Hi Makers, Builders and Do-it-yourselfers. Harley here.

If you like to make things out of items such as wood, metal and electronics, subscribe to the House of Hacks channel to get notified of future videos.

My buddy Rich’s 5 year old MacBook Air, of mid-2011 vintage, started acting a bit strange. Instead of going to sleep when he closed the lid it started hibernating. And then, because it was hibernated, rather than coming on instantly when he opened the lid, it took a number of seconds to wake back up. And then he finally got this "service battery" warning.

After calling the local repair depot and finding it was going to be a week or so to get it replaced, and with an upcoming photoshoot in a couple days where he really needed it, he asked me to fix it for him. He got a new battery off of Amazon and brought it to the shop to get it replaced.

This particular MacBook’s battery is model number A1496 and it is available from a number of different vendors. Mac batteries are a bit more complex to replace than most Windows-based laptops, but they’re still not to too bad. Let’s take a look at the simple process.

First, for many models, Apple used security screws rather than the run of the mill straight or Phillips screws, so screwdrivers for Pentalobe screws, as well as the more common Torx, are needed for this battery replacement.

Fortunately, Rich purchased a kit that included all the screwdrivers needed to replace the battery. If you don’t get a kit with the screwdrivers, make sure you have the ones you need already on hand. These screwdrivers are not high-quality things you’ll use forever, but they are sufficient to get the one time job done.

After opening the kit, I used the Pentalobe screwdriver to open the bottom of the laptop. There are two long screws next to the screen’s hinge and short screws around the rest of the perimeter.

Once the screws are out, the bottom just lifts off, exposing the battery.

Now, there are 5 Torx screws that hold the battery in. They are at the four corners and one in the center. Again, the two next to the hinge are longer and the other three are shorter.

When the screws are all out, gently lift the battery up and disconnect it. The connector has a plastic tab to pull on. Gently tug on this straight back towards the front edge of the laptop. Do not lift up away from the laptop’s motherboard.

Putting the new battery in is just the reverse of this process.

Attach the connector and make sure it’s seated. Then place the battery back in place so the screw holes line up and replace the screws. Remember, the longer screws go next to the hinge. Be careful not to cross thread or over tighten the screws. They just need to be snug, not super tight.

And now might be a good time to blow some canned air around the fan and vents to make sure there isn’t any dust bunnies hiding around.

Finally put the bottom back on and replace the screws. Again, the long screws go next to the hinge and take care not to cross thread or over tighten them.

Turn the laptop over, and turn it on and admire your work.

If you use an application like coconutBattery, you can see details of the battery's status. This utility can take a snapshot of the status for comparison. Here we see the before and the after. The old battery was to the point where it only charged to 70% of what it was designed for. And we can see the new one goes to 100%.

The instructions that came with the battery indicated it should be discharged to 5% and then recharged to 100% several times in a row. I’m not quite sure why this is recommended. My understanding of the Lithium based battery chemistry is this isn’t needed. It may be a left-over remnant of a recommendation from the Nickel and Lead based battery chemistries or perhaps it’s to calibrate the battery’s charge controller. In any case, understand this is the recommended procedure.

And now this laptop is ready for another 5 years of service.

Join me in the comments below to let me know if you found this helpful.

If this is your first time here at House of Hacks: Welcome, I’m glad you’re here and would love to have you subscribe. I believe everyone has a God-given creative spark. Sometimes this manifests itself through making things with a mechanical and technical bent. Through this channel I hope to inspire, educate and encourage these types of makers in their creative endeavors. Usually this involves various physical media like wood, metal, electronics, photography and other similar materials. If this sounds interesting to you, go ahead and subscribe and I’ll see you again in the next video.

Thanks for joining me on our creative journey. Now, go make something. Perfection’s not required. Fun is!