Education Technology

Fireworks, Flags and the Fourth of July

Posted 07/01/2022 by John Hanna

In the U.S., Independence Day is soon upon us (for the rest of the world it’s the fourth of July). The national holiday celebrates the adoption of the Declaration of Independence on July 4, 1776. Americans honor the day with family and friends, cookouts and barbeques, parades and … fireworks. Earlier this year, I wrote some Python lessons leading up to a “fireworks” display and a flag display for both the TI-Nspire™ CX II and the TI-84 Plus CE Python graphing calculators:

          

Try the Fireworks activity shown above which is found in the recently added sections “Python Modules” on TI Codes for the TI-Nspire™ CX II graphing calculator and TI Codes for the TI-84 Plus CE Python graphing calculator. You will find the fireworks activity in the "Turtle Graphics" section, and you will need the Turtle module on your calculator or computer software.

The code that generates one star polygon is:

  • n is an odd number between 5 and 11. The is the number of vertices on the polygon. To make a regular polygon we use 360/n for the turtle’s turning angle since the sum of the exterior angles of a polygon is 360 degrees. But ...
  • r is the number of revolutions the turtle makes to complete a star polygon. The value int(n/2) gives the “pointiest” stars. Why? If I use a larger or smaller value, then the vertex angles (the points of the stars) will be larger. Either int(n’2 or int(n/2)+1 yield the smallest vertex angles. Try it yourself.

See the online lesson in TI Codes for all the details and step-by-step instructions.

On another patriotic note, the U.S. flag is another great opportunity to put coding skills and art to work for this holiday. In the same Python Modules > TI Draw sections there’s an activity (Mini Project 2) to make the flag of the State of Texas:


Taking a closer look at the geometry in the image above, what would it take to make the U.S. flag? (Warning: You might need some patience to go with your patriotism!)


Tip: You can use both ti_draw functions (to make the red, white and blue rectangles) and Turtle functions (to make the stars) in the same program. Here’s some Turtle code that makes some of the stars. Note that there are six rows with five stars each and four rows with five stars for the total of 50 stars. This section makes the five-star rows at the proper positions in the blue field:


The code shown here will work on the TI-84 Plus CE Python as well, except for the paint_buffer() function at the end.

Note that the nested for loops call a function star() which is not shown here.

Another great idea for screen fireworks comes from a completely different activity found in the Beyond Basics section of TI-Basic programming on the TI-84 Plus CE graphing calculator as the conclusion of the Basketball Game. The code here is translated from the TI-Basic version online and adapted for the Python environment:



          

A close inspection of the code above reveals that the arcs of the blue and white fireworks display are each a different parabola emanating from the same point (80, 160). Here’s your engaging answer to “when will we ever use this?” Add a while loop and introduce some random values into the program so you can put on a great show. Happy Independence Day, U.S.A.!

About the author: John Hanna is a retired teacher splitting time between sailing in New Jersey and mountain biking in Florida (did he get that backwards?), still getting kicks out of working with TI to provide feedback on new products, and developing meaningful programming content for mathematics and science ... and still having fun with all the graphing calculators and the accompanying toys.