2D Sine Wave Example Using PyOpenGL

Here is an example of a moving 2D sine wave using Python 3, PyGame, and PyOpenGL.  See a https://blog.gahooa.com/2018/02/11/pygame-and-opengl-on-windows-10/  for how to install them.


This sample program is designed to have a 100×60 unit working area with a 10 unit buffer around the edges.  You can see the axis in the lower-left (0,0) where Y+ is up, and X+ is to the right.

The structure of the program was created to make it super easy to work on the “guts” of the graphics without getting it confused with the “bookkeeping” end of OpenGL or PyGame.

Note: the glOrtho() command is how 2D “parallel perspective” is setup.  It defines the left, right, bottom, top, near plane, and far plane.  Because it is parallel, there is not the notion of a “camera” per-se, but rather section of the plane that should be viewed.  Documented here:


Here is the code!

How to Calculate Pi

π (pi) is the ratio between a circle’s circumference and it’s diameter. You can check this by using a tape measure. Measure around a circle. Then measure across the circle.

π = Around / Across

Did you know there is a way to calculate π? There are a lot of different ways, but one is called the Leibniz formula for π.


Where the original Leibniz formula for π ends up calculating π/4, I’ve just factored this 4 into the infinite series.

π = 4/1 – 4/3 + 4/5 – 4/7 + 4/9 – 4/11 + 4/13 – 4/15 + 4/17 – … (forever)

The more terms you add/subtract to it, the closer it gets to being accurate. A problem with the Leibniz formula for π is that it takes a lot of calculations to get an accurate version of pi.

Here is a mini-program I wrote in Python 3 to repeat this one million times.

pi = 0
for n in range(1000000):
  pi += ((-1)**n*4) / (2*n+1)

Here are some of the numbers from that calculation:
…999980 more times…

Here is real PI:

Isn’t it interesting that my version of PI, after a million iterations, is 1 digit off of real Pi, but the digit is in the middle? This has something to do with Euler numbers which you can read about at http://en.wikipedia.org/wiki/Euler_number .

For most practical purposes, 3.14159 is more than enough digits to use with Pi.

Ever wonder if you could use Pie to calculate Pi?


Hi, this is Eli.  One of our school assignments is to completely learn our math tables by heart.   We wrote a python program to help us practice with this.  This is a program for multiplication tables 1-12.

9-10-2014 9-31-13 PM

Ezra and I are learning how to program in python.  Dad helped us get the structure of this program right, but we entered into IDLE and debugged it ourselves.

Here is an example of the program in action:

9-10-2014 9-36-40 PM

When you activate the program it  asks you how many problems you want – you can go from 1 to 144 problems.

When you are done with your problems it tells you how long you took and how many problems you got right and how many problems you got right and how long it took you to answer each problem.

That’s all for now!

Stratahex Game

We’ve invented a new board game, and it’s a lot of fun.  Stratahex combines resource collection, transportation, logistics, planning, defense, offense, warfare, and more into a simple and easy-to-play boardgame.



The basic game pieces are:

  1. Your base
  2. Supply Trucks
  3. Oil Rigs
  4. Small Tanks
  5. Artillery
  6. Standard Ammo
  7. High Explosive Ammo
  8. Coin

The board consists of 3 concentric circles with a hex-shaped hole pattern.  Parts of the board are painted light-gray, medium-gray, and dark-gray.

  • Oil rigs placed in light-gray recieve one coin per turn.
  • Oil rigs placed in medium-gray receive two coin per turn.
  • Oil rigs placed in dark-gray receive four coin per turn

You can only spend coin once it has been transported back to your base in a supply truck.  Each piece costs coin to purchase.  You have a limited number of moves per supply-truck and per weapon each turn.

Stratahex is a very comprehensive, but still simple, game to play.  The older kids, 8 and 10, have no trouble.  There is a lot of figuring, math, counting, and changing coin.

Gameplay is predictable, like chess, in that you can determine the possible moves of the opponent before his next turn.  There is no luck involved.

Plenty of fun!Image



Home School Software: Inventory Tracking

Ever lose track of how much flour, sugar, milk, eggs, soap, razors, spices, motor oil, filters, nails, screws, glue, paper, staples, etc… you have on hand?

Ever shop based on hunger, rather than diciplined restocking?

Ever want to have an inventory of groceries at your house, so you don’t have to run to the store for everything?

Our objective is to keep consistent inventory levels of common products around the house, so we never run out of things that we should have on hand.  To that end, I’ve been adding some basic household inventory tracking data to the Home School software.  It has (or will have) the following features:

  • Areas — places that you store products (freezer, basement shelves, kitchen, bathroom, etc…)
  • Items — each “thing” that you want to keep in a given area (flour, sugar, toothpaste, etc)
  • Units — lbs, each, bottle, roll, case, etc…
  • Min Quantity — minimum amount to have on hand
  • Max Quantity — max quantity to have on hand
  • Check every [] days — how often should this item be checked?

From that data, you will be able to pull the following information out of the system:

  • All items and current inventory levels
  • Graphs of inventory levels over time
  • Which items (sorted by area) need checked now
  • What needs refilled (eg, the container of sugar in the kitchen, from the big bags in the basement)
  • What needs purchased (40 eggs, 24 rolls of TP, 10 lbs of sugar)

You will be able to pop on, print out a list of items that need inventoried, and hand it to the kids with a pencil and clipboard to go about filling out how much there actually is.  Excellent math practice, especially if you deal in raw units like oz, lbs, quarts, etc… — the students will have to add/multiply/convert the units that are on the items they are counting.

For Example, you could specify that you want 4 bottles of dish soap around, or 96 ounces of dish soap around.  The difference is that they will need to multiply 24 oz per bottle * 3 bottles on hand = 72 ounces — time to buy another bottle.

Here are some early screen shots:


A big measuring tape and a right triangle

Just a good picture of Eli (with Ezra and Anna in the background) holding a 300′ measuring tape.

We needed to make a right angle, so I explained to them that a triangle with the sides

3, 4, 5

will be a 100% right triangle.  So we measured 15′, 20′, and 25′ around three stakes, and that is how we got our right angle :)

For anyone who has been out of high-school long enough to forget, the equation is:

A*A + B*B = C*C

That is…

3*3 + 4*4 = 5*5
9 + 16 = 25

See more about Pythagoras and his Pythagorean Theorem at Wikipedia…

Interesting Numeric Pattern

>>> for i in range(1,31):
...     print('  ' + '1'*30)
...     print('x ' + '1'*i)
...     print('= ' + str(int('1'*30) * int('1'*i)))
...     print()
x 1
= 111111111111111111111111111111

x 11
= 1222222222222222222222222222221

x 111
= 12333333333333333333333333333321

x 1111
= 123444444444444444444444444444321

x 11111
= 1234555555555555555555555555554321

x 111111
= 12345666666666666666666666666654321

x 1111111
= 123456777777777777777777777777654321

x 11111111
= 1234567888888888888888888888887654321

x 111111111
= 12345678999999999999999999999987654321

x 1111111111
= 123456790111111111111111111110987654321

x 11111111111
= 1234567901222222222222222222220987654321

x 111111111111
= 12345679012333333333333333333320987654321

x 1111111111111
= 123456790123444444444444444444320987654321

x 11111111111111
= 1234567901234555555555555555554320987654321

x 111111111111111
= 12345679012345666666666666666654320987654321

x 1111111111111111
= 123456790123456777777777777777654320987654321

x 11111111111111111
= 1234567901234567888888888888887654320987654321

x 111111111111111111
= 12345679012345678999999999999987654320987654321

x 1111111111111111111
= 123456790123456790111111111110987654320987654321

x 11111111111111111111
= 1234567901234567901222222222220987654320987654321

x 111111111111111111111
= 12345679012345679012333333333320987654320987654321

x 1111111111111111111111
= 123456790123456790123444444444320987654320987654321

x 11111111111111111111111
= 1234567901234567901234555555554320987654320987654321

x 111111111111111111111111
= 12345679012345679012345666666654320987654320987654321

x 1111111111111111111111111
= 123456790123456790123456777777654320987654320987654321

x 11111111111111111111111111
= 1234567901234567901234567888887654320987654320987654321

x 111111111111111111111111111
= 12345679012345679012345678999987654320987654320987654321

x 1111111111111111111111111111
= 123456790123456790123456790110987654320987654320987654321

x 11111111111111111111111111111
= 1234567901234567901234567901220987654320987654320987654321

x 111111111111111111111111111111
= 12345679012345679012345679012320987654320987654320987654321