Building a Better Twister Spinner

2015-01-04 21:10:00

I got my wife Twister for Christmas. While we were playing it on Christmas morning, she remarked that the spinner was not great. It seemed to land on Left Foot more than we expected.

My first thought was, “I could write a quick Python script to get a more random spinner result!” So I grabbed my computer and threw this together in about a minute:

import random

parts = ['Right Foot', 'Right Hand', 'Left Foot', 'Left Hand']
actions = ['Red', 'Yellow', 'Green', 'Blue']
while True:
    input('{} {}'.format(random.choice(parts), random.choice(actions)))

This is about the bare minimum I could get away with: choose a random body part and a random color and print the combination. We played this way for a while before my wife had an amazing idea.

“It would be really great if the computer could just read the spin result out loud,” she said.

I immediately thought of say, because my five-year-old daughter loves to play with say on the command line and make my computer speak. So another minute or two later I had modified my script:

import random
import subprocess

parts = ['Right Foot', 'Right Hand', 'Left Foot', 'Left Hand']
actions = ['Red', 'Yellow', 'Green', 'Blue']
while True:
    move = '{} {}'.format(random.choice(parts), random.choice(actions))['say', '-v', 'Samantha', '-r', '150', move])

Now we had nice random spins and the computer calling out the moves. But the script still required someone to press Enter after each move. The final tweak was to make it automatically call out moves after a few seconds:

import random
import subprocess
import time

parts = ['Right Foot', 'Right Hand', 'Left Foot', 'Left Hand']
actions = ['Red', 'Yellow', 'Green', 'Blue']
while True:
    move = '{} {}'.format(random.choice(parts), random.choice(actions))
    print(move)['say', '-v', 'Samantha', '-r', '150', move])

At this point I was pretty happy with the behavior of my quick little script. But I took the opportunity anyway to flesh it out a bit and allow command line options to configure various things. It was a good chance to learn how to use the argparse module.

The final script is on GitHub. It includes command line arguments for:

  • allowing “in the air” as a valid alternative to a color (our version of Twister had this move on the spinner);
  • specifying the number of seconds to wait before automatically spinning again, or requiring someone to press Enter after each spin; and,
  • making the computer speak the spins out loud (only on platforms with the say command).

This script was a fun little diversion, and now my wife and I can play Twister without needing a third person to operate the spinner!

Building a Christ-centered Home

2014-01-04 14:17:16

[This is the transcript of a talk I gave in church on Sunday, December 29, 2013.]

At the beginning of this month, we hung on the wall a felt advent calendar my wife made. Each morning in December we take a shepherd, or wise man, or angel, or other character from the Christmas story out of a pocket and place it in the scene. As Christmas approaches, the cast of the nativity assembles, culminating on Christmas morning when a small, felt Christ child is placed in the small, felt manger.

Last week I took an inventory of our home. Including this advent calendar, I counted no less than 14 nativity scenes. In each depiction, whether it be felt, wood, plastic, ceramic, glass, metal, or crystal, there at the center lies the Christ. What better way to remind us of what our focus should be than to have depictions of the Savior within our glance almost continually?

Just as each nativity scene is arranged with Christ at the center, we should do all we can to make the Lord Jesus Christ the center of our homes.

Elder Richard G. Scott, of the Quorum of the Twelve Apostles, said,

When [Christ] is the center of your home, there is peace and serenity. There is a spirit of assurance that pervades the home, and it is felt by all who dwell there. [source]

In The Book of Mormon, the prophet Nephi wrote,

And we talk of Christ, we rejoice in Christ, we preach of Christ, we prophesy of Christ, and we write according to our prophecies, that our children may know to what source they may look for a remission of their sins. [2 Nephi 25:26]

You are probably already familiar with a few fundamental principles that help make the Savior the center of your home, but allow me to draw on some of my own experiences, both as a child in my parents’ home, and as a parent of two small children. The three principles I would like to talk about are prayer, scripture study, and family home evening.

The first fundamental principle of a Christ-centered home is prayer. Prophets have long counseled us to pray daily, both individually and as a family. I remember praying together with my family when I was a child. No matter what activities we were involved in or how busy we were, every day began and ended with family prayer. I learned to pray by listening to and following the examples of my parents and older siblings.

From my father and mother I learned to pray for each member of the family by name. When I take the time to think about my wife and each of my children individually, and ask our Heavenly Father to supply their specific needs, I find that the Holy Ghost can teach me how best to express Christlike love to them. In a Christ-centered home, where the Holy Ghost can inspire the hearts of each family member, we can meet each other’s needs.

We have often been taught that we can pray for anything, big or small. One day, when I was working on a puzzle with Emily, one of my daughters, we discovered one piece was missing. We searched for a minute but came up empty-handed. As if this sort of thing that happens every day, my daughter said, “We better say a prayer so we can find that piece.”

Without hesitation, she said a very simple prayer, asking Heavenly Father to help us find the missing puzzle piece. After less than a minute of searching, sure enough, we found the piece.

Then Emily said, “Okay, now we need to say thank you.” Again, without hesitation, she prayed to Heavenly Father and thanked him for helping us find the missing puzzle piece. What a humbling example of childlike faith!

We pray to the Father in the name of Jesus Christ. As our prayers become more heartfelt, by necessity we draw closer to Christ. The first fundamental principle of a Christ-centered home is prayer.

The second fundamental principle of a Christ-centered home is scripture study. If Christ is to be the center of our home, surely the words of Christ should be studied frequently, both individually and as a family. When I was a child, just as my family ended each day with family prayer, that prayer was preceded by family scripture study.

My siblings and I learned to read mostly by reading the scriptures. Before I could read myself, I started by simply repeating the words after one of my parents.

The language of the scriptures is unlike other things we read, so the younger we start to read them, the more understandable and comfortable they will be to us as we grow older. When our first daughter Emily was about six months old we began reading The Book of Mormon with her. We usually read about five verses a day. Last night, about three years and ten months after we started, we read the last few verses of Moroni and finished the book.

One day, about two years after we started this reading, when Emily was two and a half years old, she declared that it was her turn to read. She took The Book of Mormon from me, opened it to a page somewhere near the middle, and launched into one of the most amazing recitations of scripture I have ever heard.

It sounded like she was pulling random scriptural phrases out of her memory and combining them on the fly. There were also some lines I recognized from Primary songs scattered throughout her speech. She made liberal use of, “and it came to pass,” of course. If you weren’t listening too carefully, you might think she was reciting an actual verse of scripture.

Even though the words of her performance made no sense when strung together like that, we recognized that our daughter understand that there was something different about the scriptures. I pray that this is only the beginning of a meaningful, personal relationship with the words of Christ.

In my family growing up, we would mostly read through the scriptures linearly together. But one summer, we studied the Doctrine and Covenants differently. My father put a list of sections on the wall. Each child could choose a section to study individually, then make a report to the family about what that section was about. When a child reported on a section, it was crossed off the list.

We were pragmatic children, so as you can imagine, the shorter sections were claimed quickly. Even though we were always looking for the easiest way to complete these assignments, I have specific memories of the Holy Ghost testifying to my heart that Joseph Smith was a prophet and that through him the Lord restored his Gospel in these last days. I will be forever thankful that my parents worked to build a Christ-centered home where I could have these experiences and where my testimony could grow.

You may recall the story of the Liahona, that curious brass ball that acted as a compass to Lehi and his family as they travelled through the wilderness. When they had faith that God would use the Liahona to lead them to a land of promise, the Liahona led them. After the travellers arrived on this continent and inherited the land that God promised them, it appears the Liahona’s purpose was fulfilled. But rather than discard it, prophets handed down this sacred object through the generations until it was cared for by a man named Alma.

As Alma prepared to pass the Liahona on to his son Helaman, he gave this counsel:

For behold, it is as easy to give heed to the word of Christ, which will point to you a straight course to eternal bliss, as it was for our fathers to give heed to this compass, which would point unto them a straight course to the promised land. […] For just as surely as this director did bring our fathers, by following its course, to the promised land, shall the words of Christ, if we follow their course, carry us beyond this vale of sorrow into a far better land of promise. [Alma 37:44-45]

The world is full of sorrow, which only seems to increase with each passing day. If we study the words of Christ and give the scriptures a place in our minds and hearts, we can build our homes into a promised land today.

The second fundamental principle of a Christ-centered home is scripture study.

The third fundamental principle of a Christ-centered home is family home evening. The idea of a weekly family home evening was formally announced in 1915. Joseph F. Smith, the President of the Church at that time, called for families to

[…] spend an hour or more together in a devotional way - in the singing of hymns, songs, prayer, reading of the Scriptures and other good books, instrumental music, family topics, and specific instructions on the principles of the Gospel and on the ethical problems of life, as well as the duties and obligations of children to parents, the home, the Church, society and the nation. [In James R. Clark, comp, Messages of the First Presidency of The Church of Jesus Christ of Latter-day Saints, 6 vols. (1965–75), 5:89]

This counsel was followed by a promise:

If the Saints obey this counsel we promise that great blessings will result. Love at home and obedience to parents will increase. Faith will be developed in the hearts of the youth of Israel, and they will gain power to combat the evil influences and temptations which beset them.

In 1970, the Church set aside Monday night as a designated family night, and asked local wards and stakes to not hold activities on that night. I remember spending Monday nights with my family. We sang songs, played games, acted out scripture stories, and took turns giving lessons about the gospel. Sometimes we didn’t get along. No family is perfect. But as I recall, we usually enjoyed ourselves.

We did not only have family home evening when it was convenient. When my brother Eric and I were in high school, our school choir director announced the organization of an extra-curricular men’s chorus that would meet to rehearse on Monday nights. Eric and I were both singers and wanted to participate in this new chorus.

We both knew that on Monday nights our place was at home with our family. We talked to the choir director and asked if it would be alright if we were late to the weekly rehearsal. He said that would be okay. So each Monday night, after family home evening, we went to rehearsal.

We never could convince the director to move rehearsal to another night. But even then, I knew that family home evening came first.

So now I have two young girls, and our family home evenings don’t always go as planned. But in the introduction of the Family Home Evening Resource Book it says,

The most important thing your children will remember is the spirit they feel in your family home evenings and activities. Be sure that the atmosphere is one of love, understanding, and enjoyment. It is more important to have a good time with one another than to get through a lesson. [source]

This is encouraging! We definitely have a good time together, and even if we don’t think our daughters are paying any attention, we have found that they get more from the lessons than we think they do.

I have faith that as we make family home evening a priority, our family will be strengthened and we will draw closer to Christ together. The third fundamental principle of a Christ-centered home is family home evening.

Remember that building a Christ-centered home will not magically remove trials from our lives. Elder Scott said that

[…] living an obedient life, firmly rooted in the gospel of Jesus Christ, provides the greatest assurance for peace and refuge in our homes. There will still be plenty of challenges or heartaches, but even in the midst of turmoil, we can enjoy inner peace and profound happiness. [source]

I echo that testimony. We can find joy and love in our homes when we work to put Christ at the center. In the name of Jesus Christ, amen.

On the Idempotence of Instagram Filters

2013-07-11 20:05:52

While I was recently posting a photo to Instagram, I had cause to wonder what would happen if I applied the same filter to a photo multiple times. My wonder was caused by an interesting side-effect of the app’s workflow on my phone.

The typical steps to take when posting to Instagram are these:

  1. Tap the “take a photo” button.
  2. Compose a photo and tap the shutter button to take the photo.
  3. Optionally apply a filter, border, and other effects to the photo.
  4. Optionally add a caption, tag people, add a location, and select social media sites to send the photo to.
  5. Upload to Instagram.

However, something happens behind the scenes between steps 3 and 4: the app saves a copy of the edited photo to the phone. I have found this useful in the past, particularly when I get to the captioning step and have to switch out of the app to do something else. When I get back to the app I have often lost my work and need to compose a photo all over again. But instead of taking a new photo (and editing it again) I can browse my phone and find the photo I edited the first time.

At this point, the app does not know I just loaded a photo that the app itself created moments ago, so I get the option to apply a filter and otherwise edit the photo again. So I began to wonder what would happen if I took advantage of this to apply multiple filters to a photo.

What Is Idempotence?

An operation is idempotent if it “can be applied multiple times without changing the result beyond the initial application.”[^1]

[^1]: Thanks, Wikipedia.

So, an Instagram filter is idempotent if, after the first application, any subsequent application of the same filter does not change the photo in any way. Applying the same filter several times is the same as applying the filter once.

My gut feeling is that Instagram filters are not idempotent, and if I apply a filter to the same photo over and over the photo will look crazier and crazier. Let’s see if I am right.

The Trilby

We’ll start with a boring photo of this fine trilby.

Original photo, no filter applied.

For this exercise I chose the Amaro filter. I liked how it helped bring out the pinstripes on the hat. Here is the original photo with no filter (top-left), Amaro applied once (top-right), twice (bottom-left), and thrice (bottom-right).

Photo with no filter, then Amaro applied 1, 2, and 3 times.

Already the photo is getting out of control. My hat is turning violet! And I was right, Amaro really brings out the pinstripes. Also the filters are not idempotent. But I kind of expected that anyway, I just needed an excuse to play around with multiple filters!

But maybe after a few more applications of the filter, the photo will stabilize. Let’s keep going. Here is the same photo with Amaro applied four, five, six, and seven times (top-left, top-right, bottom-left, bottom-right, respectively).

Photo with Amaro applied 4, 5, 6, and 7 times.

There is still a fair bit of difference betwen Amaro × 4 and Amaro × 7. We’re giving up violet and moving into the reds. What next?

Photo with Amaro applied 8, 9, 10, and 11 times.

The changes are slowing down now, but it is still easy to see differences.

Photo with Amaro applied 12, 13, 14, and 15 times.

Now we are all the way up to Amaro × 15 (bottom-right). It is almost indistinguishable from Amaro × 14. We’ll stop here.

All the Filters?

While we’re at it, how about one more crazy experiment before we’re through? What happens when every filter is applied to a photo? Here is the original photo with filters applied cumulatively in this order: Amaro, Mayfair, Rise, Hudson, Valencia, X-Pro II, Sierra, Willow, Lo-Fi, Earlybird, Sutro, Toaster, Brannan, Inkwell, Walden, Hefe, Nashville, 1977, and Kelvin.

Photo with all filters applied.

About halfway through we can still kind of tell it is a trilby, but by the time we get to the last four filters, who can tell what that is a photo of? Nobody, that’s who.

Obviously, applying every filter at once is overkill and no one is going to do it. But we might get good results from combining two or three filters. I wonder if the app will ever support selecting multiple filters natively. It might make a useful addition but it also might make more people over-filter their photos and that would just make me sick.

Better keep this little trick between us.

In Which We Go Camping

2013-07-01 13:33:53

Way back in January, Rebecca sent me a link to a camping workshop run by the Texas Parks & Wildlife Department and asked me what I thought about taking Emily camping. My first thought was, “Does she know me at all?”

I kept the link in my inbox and thought about it for a while and finally, in May, I decided that no matter how many unpleasant memories of camping as a Boy Scout I had, I could make this fun.

Besides, I’m an adult now. I can be responsible and wear sunblock.

William, Emily, and Zoë check out the lake.

So I registered for the workshop and Rebecca told me she was actually really surprised that I did. Maybe she does know me after all.

At first it was going to be just me and Emily. But Rebecca thought it would be more fun if we could find someone else to go with us (Rebecca wouldn’t touch a tent with a ten-foot tent pole herself). I talked to my friend Josh, who has a daughter only slightly younger than Emily, and they agreed to go on this adventure with us.

Emily and Zoë searching for wildlife.

Because we were camping as part of a workshop, the Parks Deparment provided most of the basic equipment: a tent, air mattresses for the adults, sleeping pads for the kids, a lantern, a cooking stove, and pots and pans. We only needed to bring food, clothes, towels, soap, and any other fun things we wanted. And let’s be honest, we never used the soap.

I had no idea what kind of pots and pans we would encounter in our kit so I brought along my own cast-iron skillet just to be safe.

Even though we are camping, beds still need to be jumped on.

We drove out on Friday night (21 June) and stayed until Sunday morning. We got to choose our own campsite, and we got a nice one right on the shore of Inks Lake. We spent a long time in the water on Saturday.

Josh and Zoë swimming in the lake.

William and Emily swimming in the lake.

We also got to do a little fishing (I caught a 2-inch fish!) and kayaking. Emily had a nice relaxing kayak ride while I rowed her wherever she asked me to.

William and Emily in the kayak.

We saw a fair bit of wildlife, too. We would often see lizards zipping around in the grass and on the trees. A deer came through our campsite early Saturday morning. Two ducks came to the shore at our site, probably looking for free food. We also spotted a heron in the water near our site. A pair of cardinals took some interest in us and even made off with a bit of hot dog bun Emily dropped on the ground. We also saw a wasp that was possibly as big as the fish I caught.

The weather was really nice and we all had a wonderful time! We agreed that this was definitely something we want to do again.

Emily and a full moon.

Stop externalising your life

2013-04-04 20:08:11

Sound advice from James Shakespeare:

The key thing to remember is that you are not enriching your experiences by sharing them online; you’re detracting from them because all your efforts are focused on making them look attractive to other people.