Monday, July 6, 2020

Stewart Chapter 8: Off on a Comet

Table of Contents

1. Introduction
2. Alexander Loftus Takes on the Traditionalists
3. Shapelore Learning 14-3
4. A Rapoport Math Problem
5. Music: "Packet Rap," "Measures of Center," "Christmas in July," "Triangle Song"
6. Reblogging and Updating Old Music Posts
7. Calculating the Cosmos Chapter 8: Off on a Comet
8. Lemay Chapter 9: Graphics, Fonts, and Color
9. More About Approximating Tau in Java
10. Conclusion

Introduction

Now that the big holiday is over -- and by "big holiday," of course I mean Tau Day, not the Fourth of July -- it's time to return to my summer projects. In particular, today's a big day for Shapelore as we finally reach the chapters on the trig ratios. And I also have lots to post today about music.

But we're going to start today's post with the traditionalists. At the end of my Tau Day post, I briefly mentioned something that our main traditionalists had written, and I was planning to discuss it in more detail in this post. Well, as so often happens, both traditionalists have since continued to post again, and so I have even more to discuss today.

Alexander Loftus Takes on the Traditionalists

Let me start with the most recent post on the Barry Garelick website and proceed backwards:

https://traditionalmath.wordpress.com/2020/07/05/cheerleaders-for-common-core-dept/

Because of school closings due to Covid 19, there has been a flurry of articles about distance learning, and the difficulties that parents face when having to explain “Common Core” math. The articles take the opportunity to show that parents are just not “with it” and that the new way is actually better because it confers “deeper understanding” rather than rote memorization.

The main commenter for yesterday's post so far is Chester Draws:

Chester Draws:
And yet with a much “deeper” understanding, why are children much worse at arithmetic today than they were in the past? Surely the whole purpose of the new methods is to make them better at Maths.
In recent years in my area students they have been arriving slightly better than ten years ago — because primary schools are returning to learning rote addition and multiplication. They have seen that the new ways are worse than the old.
The old way is better than the new way -- provided, of course, that the students actually do the work rather than complain and leave it blank. (Note: I do admit that the coronavirus has added a new level to the old Common Core horror story about parents who suddenly have to deal with it.)

https://traditionalmath.wordpress.com/2020/06/30/good-grief-dept-2/

Conrad Wolfram is a brilliant mathematician. He has written a book which argues that math education should not focus on how to compute various things, but on the thinking behind the computation. This article describes in breathless wonder Wolfram’s equally breathless idea to change how math is taught in order to keep up with the real world.

Many people have heard of Conrad Wolfram's website -- Wolfram Alpha -- which can answer questions, including math problems.

I was actually still a high school senior talking AP Calculus BC when I first learned of Wolfram's predecessor website, integrals.com. (If you type in integrals.com now, the browser will just redirect you to Wolfram Alpha.) I wondered whether I should use this website for my homework, except that we were learning about derivatives at the time -- and by the time we reached integrals, I'd forgotten all about integrals.com.

Now that I'm working from a teacher's perspective, I thought that Wolfram Alpha is a dangerous website, since now students can just enter in all their homework (for all math, not just integrals) and learn nothing. But now I know that hiding Wolfram Alpha from our students is useless -- most of them don't know about Wolfram Alpha, but many do know about Photo Math. And in some ways, Photo Math is worse than Wolfram Alpha, since Wolfram Alpha at least forces the user to type in the actual problem. With Photo Math, all students have to do is take a picture of the math and the website returns the answer. So it's quite trivial to perform the hoop-jumping without learning any math at all.

SteveH:
Many adults don’t need calculus or even algebra, so why push it? Many will need to be able to use computer tools, so why push mastery of the algorithmic steps? They seem to ignore the fact that they’re proposing a vocational educational model that starts in Kindergarten. So who are the few who get the opportunity to delve deep into math, science, and engineering? Probably their kids.
The only solution is choice.
Here "choice" is a red herring. Traditionalists want "choice" because most current math classes aren't traditionalist -- but if traditionalism were someday to become the dominant pedagogy again, they'd suddenly oppose "choice."

The other commenter here is Chester Draws, who writes from a New Zealand perspective. He writes about students who can't pass a Statistics test on lines of best fit -- because they don't remember what they learned about linear functions in Algebra I (or the NZ equivalent). While his point is interesting, I wish to hurry up and get to the other posts.

Here is the next post from Garelick (actually, both of these were posted the same day, June 30th):

https://traditionalmath.wordpress.com/2020/06/30/having-it-both-ways-dept-2/

“Modeling problems have an element of being genuine problems, in the sense that students care about answering the question under consideration. In modeling, mathematics is used as a tool to answer questions that students really want answered. Students examine a problem and formulate a mathematical model (an equation, table, graph, etc.), compute an answer or rewrite their expression to reveal new information, interpret and validate the results, and report out. This is a new approach for many teachers and may be challenging to implement, but the effort should show students that mathematics is relevant to their lives. From a pedagogical perspective, modeling gives a concrete basis from which to abstract the mathematics and often serves to motivate students to become independent learners.”

And SteveH rips up the jargon that appears in this Common Core Standard:

SteveH:
“Develop fluency” – Not ensure mastery

So SteveH distinguishes between "fluency" and "mastery" here. I'm not sure of the difference. I know that the word "fluency" (which appears often in the Common Core Standards) is strongly associated with language learning. And so we ask, if someone is "fluent" in a language, is this the same as that someone having "mastered" the language?

Someone fluent in French can speak French without thinking about each word one by one -- and likewise, someone fluent with the times tables can multiply one-digit numbers without thinking. So what's the difference between that and having "mastered" the times tables facts?

SteveH:
“Deepening and extending understanding ” – No fixed targets here.
“Engage in methods” – No fixed targets here.


SteveH ends the full comment (not quoted above) with the word "choice." Once again, traditionalists only want "choice" if traditionalism is what's being chosen.

Before we leave the June 30th posts, Garelick himself writes the following:

In my experience and the experience of teachers who actually know what math is about and how to teach it, students care about problems if they’re able to solve them. Otherwise they write them off as irrelevant–sour grapes.

But this suffers from the chicken-and-egg problem. (I'm sorry for mixing metaphors here, between this and "sour grapes.") Garelick says that students don't care about a problem unless they know how to solve it first. But I say that if students don't care about a problem first, then they tune out and not pay attention during the direct instruction on how to solve it. So they leave the p-set blank (unless, as usual, there's a tutor sitting inches away from them who won't let them tune out).

Anyway, here's the main post for today -- the one that has drawn the most comments:

https://traditionalmath.wordpress.com/2020/06/29/new-boss-old-boss-dept-3/

Ontario’s math program for K-12 has come under fire the past few years. So much so that the current Premier of the province (Doug Ford) ran on a platform that included a “back to basics” math program.
The new math program was unveiled last week. A glance at its features showed that aside from the requirement that students know their multiplication facts, it appears to be the same mix of rhetoric for achieving “deeper understanding” of math.
A recent article talks about how a key aspect of the new standards is the Social and Emotional Learning (SEL) component.
At first, this day after Tau Day post didn't draw very many comments. I was distracted by the June 30th posts and ignored this post altogether. Then this post drew a few pingbacks from influential authors, including Barbara Oakley (who wrote an explosive article in favor of traditionalist math a few years ago).

And then on July 3rd, someone finally decides to stand up to the traditionalists -- most of the time, traditionalist posts are nothing more than preaching to the choir:

Alexander Loftus:
Why? I don’t think I have ever used the standard algorithm in my adult life, but I use roughly this and similar methods every time I have to do mental math. Same story with the long division algorithm. I don’t think my knowledge of these algorithms has ever really helped me in a genuine way, either as a bridge to understanding or anything else.

And regarding the multiplication and division algorithms, I must agree with Loftus and oppose the traditionalists here. When I was at the old charter school, I had sixth graders who struggled with those algorithms and preferred other algorithms, such as the lattice method.

I have no problem with keeping the standard addition and subtraction algorithms -- notice that Garelick's original post mentions addition algorithms. But again, if some people, like Loftus, would prefer the left-right method (which is what an old 1980's math show, "Solve It," called it), then that's more reason simply to teach the left-right method.

Let's see how the traditionalists respond to Loftus and his challenge. First Garelick himself chimes in:

Students who master the standard algorithm first generally take to the short-cuts you mention. Students often discover these shortcuts on their own, as you probably did. The other way around, however, based on what we’re seeing in classrooms, can result in confusion.

But exactly what's causing this confusion? It could be that the standard algorithm itself is what's causing the confusion -- the students first learn a serviceable algorithm such as left-right or the lattice method, then suddenly they're required to take on the standard algorithms, and they get confused.

SteveH also responds to Loftus here:

SteveH:
“I don’t think I have ever used the standard algorithm in my adult life,”

If that’s your idea of education, then I’ll wager you won’t like many other tradeoffs that criterion would cause.
Adults take many things for granted understanding-wise that they now consider to have been rote learning. Learning to tell time? learning to count change? Was that learning rote? No. So many things tie together to build a bigger framework of understanding. School is not about providing only adult vocational tools. My adult life has nothing to do with whether I could dissect a frog or analyze a poem.
Do students ask "When will we use this in real life?" in Biology class when it's time to dissect a frog, or in English class when it's time to analyze a poem? Or, as seems more likely, does the question "When will we use this in real life?" mainly appear in math classes -- with the students threatening to leave math p-sets blank unless they see a real-life application?

SteveH:
This doesn’t even take into account whether schools actually get students to master whatever they choose to teach. They don’t get the job done. We parents have to pick up the slack, and much of that has to do with enforcing mastery of what many people consider to be rote. Just ask us parents of the best students in high school what we had to do at home and with tutors. Enforce mastery of basic facts and skills.

Math classes do enforce "fluency" of basic skills, but according to SteveH, this isn't exactly the same as "mastery." Also, SteveH mentions that tutors enforce "mastery." But once again, it's easier for students to get away with leaving p-sets blank for a teacher with many students than for a tutor with one student.

Oh, and speaking of p-sets, this takes us to SteveH's comment from Tau Day itself -- the one I didn't have time to address in my last post:

https://traditionalmath.wordpress.com/2020/06/27/nothing-really-that-new-under-the-sun-dept/

SteveH:
When I taught college math and CS, the programming tests counted very little. That’s common in computer science education. The grade was all about individually creating a working program – the homework. that’s the way K-12 math should be. Homework P-sets are like a weekly take home test that’s graded. Everyone can get a ‘A’. That’s going to be my new theme for math – grade homework. Tests are only for keeping everyone honest.

I wish to highlight this because this is exactly what my current Java summer project is for. I'm not really learning Java unless I create programs in Java that work. Indeed, it's sad that Laura Lemay doesn't include p-sets in her online text (whereas other authors from that website -- including Jesse Liberty, who writes about C++, and others -- do include p-sets). This is why I must come up with my own projects here on the blog -- and I'm not always good at coming up with such projects.

OK, so I definitely agree with Steve with regards to computer science. But then he suggests that we extend this idea to math class -- p-sets should be the bulk of the math grade. Recall that I once had a college professor at UCLA who would teach 110C, the Abstract Algebra class (on field theory), exactly this way -- our entire grade would consist of solving 50 problems. And this scared me away so much that I decided not to take the class, since I knew the problems would be difficult.

And if I, a math major, was afraid of taking Math 110C, how much more will our students be frightened away from doing a class where homework is almost all of the grade?

At the old charter school, homework was defined as 15% of the grade -- this weight was built into the PowerSchool software. This is probably more than the homework weight in many math classes these days, though still less than what SteveH suggests. The Illinois State curriculum had online homework assignments, but these were only a few problems per week (that is, much less than you'd expect to be worth 15% of the grade). There was also a weekly review worksheet consisting of problems from all strands of the Common Core -- so at least four out of five problems would not be directly to the current chapter. Thus these worksheets wouldn't be "practice" in the way that SteveH desired.

The closest I could get to SteveH's ideal is if I let the kids take the "Student Journals" home, or make copies of the pages. Only these traditional texts contain enough problems for SteveH to count it as a full p-set. (Of course, Illinois State was a project-based curriculum -- the exact opposite of the class that SteveH wants to see.)

Shapelore Learning 14-3

Lesson 14-3 of the U of Chicago text is called "The Tangent Ratio." This means that it's finally time for me to decide what to rename the three main trig ratios.

First of all, I see that the Anglish website has changed, so that the link that I posted earlier is now a dead link. Here's the new link:

https://anglish.miraheze.org/wiki/Main_Page

(The old page used to have the title "Main Leaf," since "page" is a French word. But now it's simply called "Main Page.") And the new page no longer has an English-to-Anglish wordbook. Instead, we must go to the Anglish wordbook and search for the word we wish to translate.

Meanwhile, I notice that the most recent Numberphile video is all about trig:


In this video the presenter, Ben Sparks, suggests that it's better to define the trig functions using circles rather than triangles. And some of the commenters agree, for example:

Grizzly Gamer:
This annoys me quite a lot. I'm 36. I got great grades for Chemistry, Physics and Biology at GCSE but did abysmally in my maths exam and the best grade I ever achieved is a D. The exams at the time were full of trigonometry and I have NEVER been able to get my head around that one thing all my life. Seeing it applied to circles, rather than triangles has literally allowed me to understand the subject in the length of this video. I wish you were my GCSE maths teacher 😂

(Note: GCSE's are British exams. The OWL's that Harry Potter takes in his fifth year are based on the O-levels, which have since been renamed to GCSE's.)

Timothee Groleau:
I can still remember memorizing sin and cos values when I was in high school almost 30 years ago. It would have been so much easier to have been taught circle functions and tau. Why memorize when it's so easy to derive. So much time wasted 😢. At least younger learners will have an easier time. That said, I thought I would show these things to my kids and they will see the awesomeness, but I've had bad experiences so far with responses of "that's not what the teacher expects", and it makes me very sad 😞.

Johann Gunnarsson:
I learned more trigonometry in this 12-minute video than I have in 40 years...

These comments suggest that perhaps the solution to our "threenooklore" problem -- what to name the three trig functions -- is to name them as circular functions rather than in terms of right triangles!

So for today, let's think about a new name for the tangent ratio. For starters, notice that just because we renamed the tangent line to "touching" line (a French word), it doesn't mean that we must rename the tangent ratio to "touching" as well. (Notice that Ben Sparks does explain in the video above why the tangent line and tangent ratio have the same name.)

As far as the unit circle is concerned, the cosine is the x-value, the sine is the y-value, and the tangent is the slope of the terminal side of the angle. So maybe we should propose the names "circle-x" for cosine, "circle-y" for sine, and "circleslope" for tangent.

In the name "circleslope," we know that "circle" is Latin/French. As for "slope," I notice that while "slope" derives from an earlier word aslope, neither slope nor aslope appears in the new version of the Anglish wordbook. I'll still count is as Anglish, and we should keep it.

We are definitely grandfathering in "circle" since most non-mathematicians know exactly what a circle is. But still, we might wish to use another word for "circle" in the name "circleslope" -- after all, when we get to the lesson on right triangles, students might wonder why we're using a function with "circle" in its name to measure triangles.

A simple Anglish word for "circle" is ring. But I'm wondering whether we should use ring for circle considering that ring has another meaning in math (namely a system analogous to the integers). The Shapelore page at the Anglish website suggests umbeling for "circle," but I don't really like using that word here either.

I think that I'll keep "ring" anyway despite its use in Abstract Algebra, and so from this point forward, we'll be calling the tangent ratio ringslope from now on. We'll use ring in the names of the trig functions even though the circle itself will still be called a "circle."

This means that sine and cosine should be called "ring-y" and "ring-x," but now I'm wondering whether we should really use y and x in the names of ratios at all -- for example, do we really want the equations y = cos(x) and y = sin(x) to become y = ring-x(x) and y = ring-y(x)? An interesting way to name these functions are ringex for cosine and ringwhy for sine -- that way, we can write y = ringex(x) and not get confused with the two x's.

Some people might wonder whether a name with x (ex) or y (why) is truly Anglish, since the letters come from Latin and then back to Greek. The Anglish website mentions that Old English was written using the Latin alphabet, perhaps with an extra letter "thorn" to denote the "th" sound. There's also an old alphabet listed there called "Younger Futhorc," which contains thorn and other letters. But by now we're going overboard. It's considered OK to include Latin letters in our Anglish names (even more so in our Plain English names, which aren't pure Anglish anyway).

Then again, we're only dealing with tangent (ringslope) today -- I don't have to decide whether to keep ringex and ringwye for cosine and sine until my next post.

You might be curious about some other words related to trig and angles. First of all, I haven't said anything about cotangent, secant, or cosecant yet. Regarding the cotangent, I'm thinking about how cot x = 1/tan x, so perhaps ringoverslope -- as in 1/slope, 1-over-slope -- can be used. I must point out that in British English (including on some Numberphile videos), 1/slope isn't "1-over-slope," but is pronounced "1-on-slope" instead. I like that ringonslope is shorter than ringoverslope, but I wonder whether American students might be confused as to what "on" stands for (but hopefully less so than what "co" stands for in "cotangent"). We'll save secant and cosecant for after the names for cosine and sine have been decided.

For circular function trig, we often deal with radians. So should we keep the Greek letters pi and tau in a Plain English math class? Recall my blog tradition -- I continue blogging about the number tau each summer, from Tau Day up until Pi Approximation Day (and besides, notice that the commenter Timothee Groleau mentions tau in his post as well).

A class in pure Anglish would likely replace "pi" and "tau" with p and t -- there's already a precedent for using a single Latin letter as a number with e = 2.718..., after all. Most likely, we'll just keep pi and tau, since these are already known to be Greek letters. But I admit it might be interesting to replace theta -- the Greek letter used to denote an angle (for who knows what reason) -- with thorn.

Keep in mind that the purpose of our Shapelore project is just to determine the vocabulary used to teach math -- I'm not proposing changing what classes are taught when. The suggestion made by Sparks and his commenters is to teach circular functions before right triangle trig. But here we teach right triangle trig in Geometry, while circular functions are either Algebra II or Precalculus.

Then again, both right triangle trig and circular functions appear in Integrated Math III. Thus this is one advantage that Integrated Math has over traditional Algebra I, Geometry, Algebra II -- in the Math III class, we can choose to teach circular functions before right triangles, whereas we can't under the traditional sequence. But this again is beyond the scope of our Shapelore project -- we can't change the fact that our text is based on traditional Geometry, and so we're stuck with teaching right triangles first, even if the ratio is now called ringslope.

So what we name this subject -- is it threenooklore or threesidelore? I suppose threesidelore is preferred since we're calling triangles threesides. But now that we're naming the functions after circles rather than triangles, perhaps trig should no longer be elevated to the status of a "lore." The name of Lesson 14-2 -- "Lengths in Right Triangles," could be a good name for the entire unit on right triangle trig (Lengths in Right Threesides).

Let's begin our translation:

In Example 3 of Learning 14-1, measures of two angles and a non-inheld side in a threeside were given. That is the AAS condition. From this information, measures of all other angles and sides could be computed. In general, using threesidelore all sides and angles can be found whenever enough information is given for a threeside sizeshapelink condition. In this book you will learn how to do this with right threesides.

Consider two right threesides ABC and XYZ with a pair of sizeshapesame inward angles. The threesides might be formed by shapes and shadows at the same time of day. Following custom, in the drawing at the right the side withering angle A is called a, the side withering angle B is called b, and so on. You should be careful to write small letters differently from capital letters.

By the way, I'm wondering whether sizeshapesame -- admittedly a mouthful -- should be used for "congruent angles." After all, an angle and its dilation image are congruent. Perhaps it's better just to use shapesame for congruent angles and reserve sizeshapesame for objects with lengths. (And by doing so, we reinforce the fact that dilations preserve angles, but not lengths.)

The threesides are shapesame becames of AA Shapelink.
Since matching sides are dividelinkful ("proportional"), a/x = b/y.
By the Means-Swap ("Means-Exchange") Law, a/b = x/y.

The legs a and x are withering the shapesame angles A and X. (Recall that it's OK to keep "opposite" if withering is too confusing.) The legs b and y are neighboring angles A and X. This argument shows that in every right threeside, the dividing ("ratio") of lengths

leg withering angle A/leg neighboring angle A

is the same for the angle shapesame to A. This dividing is called the ringslope of angle A.

And here is the official definition:

In right threeside ABC with right angle C, the ringslope of A, written rm A, is

leg withering angle A/leg neighboring angle A.

Instead of "tan," our abbreviation for ringslope is "rm" -- r for ring, m for slope. (I know -- maybe we should get rid of m for slope while we're at it.)

Notice that the new name for tangent destroys the SOH-CAH-TOA mnemonic. Hmm, that's another possibility -- just use "soh," "cah," and "toa" as the new names for the functions. But then we'll have to explain what the t in "toa" stands for.

Here is our first example:

1. Estimate the ringslope of an angle of 25.

Answer: Draw a right threeside with a carefully measured 25-degree angle. Measure the leg withering that angle. Using the threeside below, that leg is 24 mm. Then measure the leg neighboring the angle; it is about 52 mm. The dividing of these lengths, 24/52, is an estimate of the ringslope of 25.

The estimate can be converted to a decimal: 24/52 = 0.46.

At this point, the text describes how to use a calculator. Most students know what a calculator is, so we can grandfather in the word calculator.

But this introduces another problem -- we came up with this great new word ringslope for the tangent ratio, but our calculators have a "tan" key, not a "rm" key!

Another idea is a back-formation -- just find an Anglish word that starts with "tan" and let it be the new name for tangent. Unfortunately, the only Anglish words on the website that start with "tan" are "tan" (the color) itself and its derivatives. (The word "tan" is Latin, but it was used during the Old English period.)

The calculator problem is something I must figure out at another time. But it's an important one -- the whole point of this project is to show students that "tan" is more than just a button on a calculator!

(Hmm, the Anglish website mentions a word tawne, meaning "to show" or "to manifest." Well, the tangent function does "show," or tawne, important info about the triangle -- and moreover, the extra w reminds of "withering," so the word is a mnemonic like "toa." Thus we could call the tangent ratio tawning and abbreviate it "tan," just like the button. But I don't recommend the name tawning.)

Here is our second example:

2. At a location 50 m from the base of a tree, the angle of lifting ("elevation") is 33. Determine the height of the tree.

Answer: The angle of lifting is A in the shape below.

rm 33 = leg withering A/leg neighboring A
rm 33 = BC/50

Timesing both sides by 50,

BC = 50 * rm 33
      = 50 "x" 33 "tan" "="
      = 32.47038
      = 32 meters

Here is our third example:

3. In the right threeside below, find tan D. (Don't worry -- you'll figure out the given info soon!)

Answer: rm D = leg withering D/leg neighboring D = EF/ED = 5/12.

And here is our fourth and final example:

4. Give an exact value for rm 60.

Answer: Draw a 30-60-90 threeside.

In Threeside GHI, rm 60 = rm G = leg withering G/leg neighboring G = HI/GH.
GH is the shorter leg. Call it x. Then HI = x sqrt(3).
Standing in ("substituting"), tan 60 = x sqrt(3)/x = sqrt(3).

Check: Press 60 "tan" on your calculator. You should get 1.732..., which is about sqrt(3).

We'll move on to some selected exercises -- the ones without a given diagram. (But some of them require the student to draw a diagram.)

1. Draw a right threeside with a 40-degree angle, measure its sides, and use those measurements to estimate rm 40. (Likely answers: about 4/5 or 5/6.)

3. Using a calculator, approximate rm 73. (Answer: 3.271.)

7. Give an exact worth for rm 30. (Answer: sqrt(3)/3.)

8. Give an exact worth for rm 45. (Answer: 1.)

9. Draw a right threeside with legs of 4 units and 6 units. Use this threeside to estimate answers to the following questions:
a. What is Angle A if rm A = 2/3? (Likely answers: about 30 or 35 degrees.)
b. What is Angle A if rm A = 3/2? (Likely answers: about 55 or 60 degrees.)

12. Without calculating, explain why rm 75 > rm 74. (Answer: This one doesn't need a drawing, but we can see the drawing from #11. Draw Threeside ABC with AC = 1, Angle C = 90, B = 74, and then D between B and C with Angle ADC = 75. So DC < BC, and so 1/DC > 1/BC. But we see that 1/DC is rm 75 and 1/BC is rm 74, so rm 75 > rm 74.)

A Rapoport Math Problem

The Geometry drought continues -- there's still no sign of any Geometry on the Rapoport calendar.


Today on her Daily Epsilon of Math 2020, Rebecca Rapoport writes:

3! * 5! = x!

Well, let's write these factorials out fully:

 3 * 2 * 1 * 5 * 4 * 3 * 2 * 1 = x!

We can do 3! in our head -- it's just 6:

6 * 5 * 4 * 3 * 2 * 1 = x!

And that, by definition, is 6 factorial! Therefore our desired answer is 6 -- and of course, today's date is the sixth.

I'm looking ahead on the July page of the Rapoport calendar, and I do see that there will be some Geometry later this month. I hope I'll be able to include a Geometry problem in my next post.

Music: "Packet Rap," "Measures of Center," "Christmas in July," "Triangle Song"

We now focus on the songs I sang at the old charter school during Weeks 15-16 of the school year.

The first song I performed was "The Packet Song":


THE PACKET SONG

1st Verse:
Your folks came up to us and said,
"Hey teachers, you can't hack it!
You make the claim you give our kids
Much work, but you can't back it."
So we got together and said,
"Let's stop all this racket!
We'll staple all our good worksheets
To make a ten-page packet."

2nd Verse:
Don't leave your packet behind,
Make sure that you backpack it.
Or if it starts to rain then
Hide it underneath your jacket.
Keep it in a folder so that
You can always track it,
Make sure that you never ever
Leave your ten-page packet.

3rd Verse:
When it's homework time then
Take it out and just attack it.
When there's extra time in class
Then you need to unpack it.
When it's time to turn it in
Make sure that you don't lack it.
To each and every teacher just

Turn in your ten-page packet.

I originally came up with a tune for this song, but I've since lost it. Instead, due to its rhyme structure, I decided to make it into "The Packet Rap."

In rap or hip-hop, rhythm is much more important than melody. Because of this, I might transform some of my other songs lacking tunes into raps.

The second song I performed is "Measures of Center Song":

MEASURES OF CENTER SONG
(to the tune of "Row, Row, Row Your Boat")

Mode, mode, mode, the most!
Average is the mean!
Median, median, median, median,
Numbers in between.

This song already has an established tune, so I don't need to add a new one. But I will post another verse or version of this song, all about adding integers:

Same sign, add and keep.
Different signs, subtract,
Keep the sign of the bigger number,
Then you'll be exact.

The third song I performed isn't really a song at all, but more parodies. At the time, the students in music class (including my seventh graders, who lost math time with me due to music) were preparing for a Christmas concert. But the concert was abruptly cancelled because, as a co-located charter, we were at the mercy of the district school that owned the campus -- and they wanted the auditorium in order to hold its own Christmas concert. And so I decided to make it up to my dejected students by singing math versions of the Christmas songs that they'd been preparing to perform.

It seems weird for me to post these Christmas songs in July. So let me instead declare today's post to be a "Christmas in July" celebration:


JINGLE ALGEBRA
(Tune “Jingle Bells”)
Dashing through my text,
It’s really not complex.
But if my mind runs slow
It gives me lots of woe,
Oh, Oh, Oh!
I study Algebra
My brain runs; I say “Go!”
So much I do not know
And so very far to go. Yo!
Properties, Quantities
Factor into play;
Points to plot,
I think a lot
Success should come my way!
Rantional ‘n Radical
Equations have a say.
Slopes and line,
I’ll make the time;
Math Power’s here to stay! Yea!
OH NUMBER PI
(TUNE: “Oh Christmas Tree”)
Oh, number Pi
Oh, number Pi
Your digits are nonending,
Oh, number Pi
Oh, number Pi
No pattern are you sending.
You’re three point one four one five nine,
And even more if we had time,
Oh, number Pi
Oh, number Pi
For circle lengths unbending.

Oh, number Pi
Oh, number Pi
You are a number very sweet,
Oh, number Pi
Oh, number Pi
Your uses are so very neat.
There’s 2 Pi r and Pi r squared,
A half a circle and you’re there,
Oh, number Pi
Oh, number Pi
We know that Pi’s a tasty treat.
Here's the link where I originally found these songs:

https://musingsofamathteacher.wordpress.com/2010/12/20/funny-christmas-math-songs/

And while I'm at it, let me post one more song from that link:


RUDOLPH THE STATISTICIAN
(Tune: “Rudolph the red-nosed reindeer”)
Rudolph, the statistician
Sampled data everywhere.
Mean heights and heart conditions
Calculated with great care.
All of his population
Gathered from coast to coast
Sought out his information;
He would always give the most.
Then one foggy Christmas eve
Santa came to say,
“Rudolph, with your pencil write,
What gifts I should take tonight.”

Quickly he polled the children,
Then Rudolph shouted out with glee:
“Stats did provide the answer:
Give Nintendo and Barbie!”
Actually, it's interesting how "Christmas in July" became a thing. If the idea is to have a second Christmas in summer, directly opposite the actual Christmas (that is, exactly one "thine" away -- thanks, Michael Hartl), then that should be in June, not July. (Indeed, Angel Stadium regularly holds a Christmas in June so that it would be during baseball season.)

I've read that the idea behind "Christmas in July" is for it to fall in the hottest month of the year, rather than the summer solstice. Due to the lag of the seasons, the hottest month of the year in many places is July. (Here in California, the hottest month is often August.)

The final song for today is "The Triangle Song," from Square One TV:



The original video that I posted for this song cuts off the first two lines, and I had to guess what these lines are. So instead, I post this full episode of Square One TV. The song starts at the 3:17 mark.

THE TRIANGLE SONG

Bet you when you see a triangle,
You think, they're all the same.
But depending how they measure up,
They have different names.

An equilateral triangle has all three sides the same length.
An equilateral triangle has all three sides the same.
Three sides measure the same! (Equilateral!)
None are different and three are the same.

An isosceles triangle has two sides the same length.
An isosceles triangle has two sides the same.
Two sides measure the same! (Isosceles!)
One is different and two are the same.

A scalene triangle has no two sides the same length.
A scalene triangle has no two sides the same.
None of the sides measure the same! (Scalene!)
All are different and none are the same.

You can measure the angles within each one.
You always get the same sum.
For even though there are different names for these.
Each one's angles together will measure 180 degrees.

So the next time you see a triangle,
Just measure its sides and you'll see.
That to figure out its name,
It's as easy as one, two, three!


Reblogging and Updating Old Music Posts

Notice that none of the songs I post today require any tunes. The first is a rap, the last is from Square One TV, and the ones in between are parodies with established tunes. So this a great time for me to post some other tunes related to Mocha music.

Meanwhile, I know that I'm not supposed to be reblogging during the summer. But there's an interesting post from July 6th three years ago -- just after I left the old charter school -- in which I discuss some music, including a song from the old charter school "Meet Me in Pomona." And so I'll reblog -- and update -- this old post.

Also, I reblogged another musical post on Tau Day where I discussed a possible musical instrument -- the Arabic lute -- based on the EDL scales as Mocha. Last year, I wrote that I wanted to explore the possibilities of an Arabic lute even further, but I simply reblogged that post without any updates or further insight. So let me update both of those old posts today.

In fact, let me start with the Arabic lute. As I mentioned in my last post, another name for the interval 18/17 is "Arabic lute index finger." This weird name suggested to me that the old Arabic lute, or oud, was fretted to an 18EDL scale -- that is, the frets divided the string into 18 equal parts. Then the index finger would indeed fret the interval 18/17 above the open string. The middle finger placed at the second fret would be 18/16 = 9/8 (major tone), the ring finger placed at the third fret would be 18/15 = 6/5 (minor third), and the little finger placed at the fourth fret would be 18/14 = 9/7 (supermajor third).

But we found out that if we take the standard tuning of a guitar, EADGBE, treat these as white notes (Kite's color notation), and then finger out the standard open guitar chords, then unfortunately, these don't correspond to just major or minor chords. The open notes and second fret notes are all white, and the third fret notes are all green, but no fingering gives the correct combination of notes to produce the correct chords in just intonation.

And so I decided to explore some other ways to tune the strings so that just major and minor chords become playable. Suppose we wish to explore a tuning of a stringed instrument, fretted to 18EDL, so that there are as many playable just major or minor chords as possible, with the following properties:

  • At least four (out of six) strings are played.
  • The lowest bass note played is the root of the chord. (Indeed, this root determines whether four, five, or six strings are needed.)
  • No more than four fingers are needed on the fret board. (So a five-string chord needs at least one open string, and a six-string chord needs at least two open strings.)
These properties are shared by the open chords on a standard guitar (such as D, C, G, and so on), so it's reasonable to demand the properties for chords on our 18EDL oud.

It turns out that the maximum number of playable triads is quite low -- only one major chord and two minor chords. It makes sense that there would be more minor chords than major, since the EDL system is based on undertones/utonal chords, and minor chords are utonal whereas major chords are based on overtones/otonal. Indeed, recall that a minor triad is 6:5:4 in utonal notation while a major triad is 15:12:10 in utonal. (In otonal notation, a major triad is 4:5:6.)

And as it turns out, this maximum is achieved for a simple "power chord" tuning -- that is, where the strings are tuned to a root note and its fifth, as in AEAEAE.

For this AEAEAE tuning, it's obvious that one of the possible minor chords is A minor. To play it, we only need to fret one of the A strings at the third fret for green C:

AEAEAE tuning:
A minor: 000030

The other playable minor chord is E minor. To play it, we fret two of the A strings at the second fret for white B. (The lowest string isn't played, since the bass note needs to be E.) Then we fret one of the E strings at the third fret for green G:

E minor: x02320

The lone playable major chord is C major. To play it, we fret all three A strings at the third fret for green C, and one of the E strings at the third fret for green C. The resulting chord is gC-wE-gG, which is indeed a green C major chord:

C major: 303330

This chord is playable yet admittedly difficult.

There are other playable just chords besides the minor and major triads. For example, both the A minor and E minor chords become supermajor if we fret them at the fourth fret instead of the third:

A supermajor: 000040
E supermajor: x02420

And likewise, if we move the C major chord up to the fourth fret, it becomes red C# subminor:

C# subminor: 404440

It's possible to combine some of these chords into songs -- for example, the E supermajor chord can serve as a dominant chord in A minor. (This is like the key of A "harmonic minor" -- that is, the natural minor with a raised seventh.)

I was first inspired to play the guitar when I was a young boy. I turned on PBS -- the same channel as the old Homework Hotline and French in Action -- and there was a show for guitar lessons, starring Belgian classical guitarist Frederick Noad. I had a four-string guitar and tried to play along, but Noad taught using standard six-string guitars, so I had to wait until I got a full-size guitar.

Anyway, one of the first simple songs he played consisted of all high E notes -- the exercise was to learn about quarter, half, and whole notes. As we students/viewers played the E string, Noad would play A minor, C major, and E major chords as an "accompaniment." These chords are all playable on our power chord oud, as A minor, C major, and E supermajor chords.

(Noad also played an accompaniment to a simple song where we played the lowest three strings of the guitar -- E, A, D. When we played the A string, Noad played an Am chord. When we played the D string, he played Dm, and when we played E, he played E7. The song for which he is best-known is his rendition of Greensleeves -- a song I played on my old toy keyboard as well. But Noad's version is different. In the key of A minor, his is the only version where a G chord is played at the start of the refrain, "Greensleeves..." -- all other versions play a C chord here. But I digress.)

So that's just one "song" that I can play using our power chord oud -- and it isn't really a song, but just a string exercise. I also prefer the idea of tuning our oud strings so that they're at close to the standard guitar tuning. If the high E for AEAEAE is tuned to the same E as a standard guitar, then the low A is a perfect fifth lower than the standard E string, while the next lowest E and A strings are the same as the standard E and A but one string off. It would be better if our oud tuning was EA?EAE, where the highest string and lowest two strings match the standard guitar tuning.

What notes could we insert on that fourth-highest string? Perhaps if we choose the correct note, we could play an additional minor or major chord.

We might try placing a B string there, since B is next on the circle of fifths after A and E. But unfortunately, the A minor chord is no longer playable. That's because the other notes on the new B string are white C#, green D, and red D#, and none of these fit in an A minor chord. (Notice that the first fret, our Arabic lute index finger, would give a new note called 17u or su B#. This produces an interesting minor-like chord, but it's not identical to the green C we need for a just Am chord. We'll get back to the "su" notes later on.)

The only other note that fits there is a D string. Notice that D also matches the standard tuning, so EADEAE now has four strings in common with the standard. This doesn't destroy any of the chords we have so far, since all of them can be played with the D fretted at the second string for E:

EADEAE tuning:
A minor: x02030
E minor: 022320
C major: x32320

But unfortunately, no new minor or major chords are playable. We can't play D minor with the new D string because no note on the E string fits with Dm (with the possible exception of su E#). The D fretted at the third string becomes green F, but F major isn't playable for the same reason (and su E# would definitely sound dissonant over the green F).

Meanwhile, E supermajor becomes 022420, which is difficult to play since it requires the little finger to be stretched away from the other fingers. It might be slightly easier to play it as 022024, though (that is, play red G# on the top string rather than the third-highest string).

Then again, with a D string, we might wonder whether an E7 chord is possible as 020420 -- due to the open string, the ring finger isn't needed, so the little finger can stretch.

This chord would be spelled out as wE-rG#-wB-wD. The interval from rG#-wD is a blue fifth (zo 5th) or the interval 112/81. At 561 cents, the blue fifth is much narrower than the 64/45 green fifth that we expect in a dominant seventh chord. It's also narrower than the 7/5 "zogu 5th" -- the most common 7-limit fifth.

We expect tritones to be dissonant, but the 112/81 interval will be even more dissonant. (Indeed, when Kite gives his list of possible fifths, the blue fifth is left out.) Therefore I don't expect this seventh chord to play well.

And so if our goal is to play a simple song like the Noad high E exercise with the EADEAE tuning, then we will have a problem when we get to the E chord. Either we play 022420 and have to stretch out the E finger, or we play 022024 and lose the high E that the exercise is based on, or we play 020420, the Er,w7 chord with its dissonant blue fifth.

As for the other chords involving red notes, C# superminor also requires finger stretching. The easiest chord to play will be A supermajor:

A supermajor: x02040

Thus as much as I like EADEAE with its resemblance to standard tuning, it might lead to problems when we try to play actual songs (not just chords).

The tuning EADEAE is called a sus4 tuning. The name "sus4" (suspended 4th) refers to a chord where the third is replaced with a perfect fourth -- in this case Asus4, A-D-E. (The Square One TV song "Rhythm" uses a sus4 chord as a dominant, because it's played in Mixolydian mode where the leading tone -- that is, the fifth of the dominant -- is unavailable.) The tuning EABEAE mentioned earlier is called a sus2 tuning, but we've seen that in sus2 tunings, the major chord and one of the minor chords become unplayable. Thus sus4 tunings are preferred for our oud.

A well-known sus4 tuning is DADGAD, often pronounced "dad-gad." It has three strings in common with the standard tuning. This is a Dsus4 tuning, and so the playable chords are D minor, A minor, and F major:

DADGAD tuning:
D minor: 000203
A minor: x02232
F major: xx3233
D supermajor: 000204

Finally, the oud tunings that I mentioned in my last post are similar to the guitar in that most of the intervals between strings are perfect fourths. The one exception on a guitar is a major third between the G and B strings. And for the oud tunings listed in that post, the one exception is a major tone (second) between two strings.

None of the oud tunings listed last time produce any minor or major chords. But suppose we were to place the major tone exactly where the major third is in standard tuning? In other words, instead of standard EADGBE, we obtain EADGAD -- the lowest four strings there match the standard. Are there any playable chords?

Well, the top five strings match DADGAD, and so at least four-string Dm chord exists. We can't extend this chord to the two low strings because there's no longer a low D as the bass note. The Am and F chords don't use all the strings anyway, so there's no difference from DADGAD there.

And so the low E string becomes useless. We can't use it play E minor because the open string above it is white G, not the green G needed for Em. Likewise we can't play G major because the bass G would be green. We might be tempted to tune it to yellow E instead of white E (that is, we allow an exception to the rule that all open notes are white). But then the Em and G chords based on that string would require an unplayable yellow B. The only true use of low E would be to play Am/E -- that is, an A minor chord even though the bass note is E. We might as well use DADGAD and at least have a six-string D minor chord.

Thus we should use either the power chord AEAEAE or sus4 EADEAE or DADGAD tunings. These are the only tunings that allow us to play anything approaching familiar music.

By the way, we haven't really explored that first fret and the 18/17 interval -- the Arabic lute index finger that inspired these tunings in the first place. As it turns out, "su" is a sort of "pseudo-yellow" that can be used to replace yellow in certain EDL chords.

Assume DADGAD tuning. The third string (from the top) at the first fret produces su G#, and the fourth (from the top) string at the second fret produces white E. The interval wE-suG# is a su third, which is 64/51. At 393 cents, the su third is about halfway between a just 5/4 (yellow third) and the 12TET third. (Here I use 12TET to refer to the standard fretting instead of 12EDO, since EDO can be confused with EDL.) So we expect the su third to be slightly more consonant than the 12TET third.

This allows us to add a E major chord to DADGAD, as well as an E7 chord:

E su: xx2122
E su,w7: xx2120 (or using all six strings as 220120)

(Actually, it's awkward to use "su" and "supermajor" together. If we use "su" chords, then we should replace "supermajor" with "red" or "ru.")

In EADEAE tuning, B su isn't available, but the B7 chord is playable as x21202. This is the exact same fingering as the same B7 chord in standard tuning.

Let's stay in EADEAE tuning and fret the third string (from the top) at the first fret. This produces the note su E#. The interval between this note and the string below it is wD-suE#, a su second, 81/68. At 303 cents, the su second is more like a minor third, though it's only marginally better than the equivalent in 12TET. Still, it produces an extra minor chord, Dm (xx0101). Unfortunately, this doesn't work in DADGAD because the equivalent chord Gm must either be a three-string chord or use D on the fourth string as the bass, Gm/D (xx0010).

Now, let's finally get to the reblog. This is what I wrote three years ago about music:

One song that appears in my songbook is "Meet Me in St. Louis, Louis." Notice that I changed this to "Meet Me in Pomona, Mona" as part of music break in my class leading up to the field trip to the LA County Fair in Pomona.

In this book, the song is written in the key of C major. Yet there are plenty of accidentals, and for all three reasons listed above:
  • There are plenty of accidentals. The line "We will dance the 'Hoochee Koochee'" is played with a series of secondary dominants: E7-A7-D7-G7-C. The first three of these require sharps.
  • There are several leading tones as well. The line "So he said 'Where can Flossie be at?'" contains an A# between two B's in the melody: G-A-B-A#-B-c-B-A-d.
  • There are two diminished seventh chords: Ebdim7 and F#dim7.
Notice that Ebdim7 and F#dim7 are actually the same chord in 12EDO -- the difference is that the note in the name of the chord is the bass note. But F#dim7 is spelled out as F#-A-C-D#, while Ebdim7 is spelled out as Eb-F#-A-C. Neither of this is strictly correct -- the dim7 chord should only contain minor thirds, so F#dim7 should be F#-A-C-Eb, while Ebdim7 is Eb-Gb-Bbb-Dbb -- that is with two double flats. (I notice that there are guitar chords shown in the score, and both Ebdim7 and F#dim7 have the exact same fingering on the guitar.)

I cut out the rest of this post, which is about converting this to another EDO (or TET) scale. This was back before I found out that Mocha music is based on EDL scales, not EDO/TET. So I should really finish this post by stating how to convert this song to EDO -- and in particular, how to play the chords on our oud.

In order to take advantage of open strings, I changed some of the chords to 7th or 9th chords. I also use the su notes in our dim7 chords:

DADGAD tuning (key of F major):
A7: x02042
D7: 004230
G7: xx3020
C9: x32330
F: xx3233
Bbmaj7: xx3300
Bdim7: xx3120

EADEAE tuning (key of C major):
E7: 020420
A7: x02340
D7: x00232
G9: x23303
C: x32330
Fmaj7: x33000
F#dim7: x01232

Even though I won't be refretting my guitar any time soon, I might retune my guitar to one of this type of tuning. I haven't quite decided the tuning yet. There's actually a good chance that it will be something other than DADGAD or EADEAE.

Calculating the Cosmos Chapter 8: Off on a Comet

Chapter 8 of Ian Stewart's Calculating the Cosmos is called "Off on a Comet." As usual, it begins with a quote:

"It may be said with perfect truth that a fisherman standing on the sun's surface, holding a rod long enough, could fling his line in no direction without hooking plenty of comets."

-- Jules Verne, Off on a Comet!

And the proper chapter begins:

"'When beggars die, there are no comets seen; the heavens themselves blaze forth the death of princes.'"

This chapter is obviously all about comets. The author opens this chapter with some Shakespeare -- the speaker here is Calpurnia, predicting her husband's death in Julius Caesar.

To the ancients, comets were indeed harbingers of death. But they were confused as to what they are:

"They looked a bit like clouds; they were fuzzy, not crisp like stars and planets. But they moved like planets, except for those sudden appearances and disappearances."

Stewart provides us here with the first picture of this chapter. It's of the Great Comet of 1577 over Prague, in an engraving by Jiri Daschitzky.

One British scientist's name is forever associated with comets -- Edmond Halley. He discovered that the comet named for him appears in the sky after regular intervals:

"Newton's law of gravity modified this statement a little: the motion would be almost periodic, but the gravitational attraction of other planets, especially the giants Jupiter and Saturn, would accelerate or retard the comet's return."

It's possible that comets explain the origin of water on our planet:

"There's convincing circumstantial evidence that lots of comets collided with the early Earth, in which case the ice would melt and collect to form oceans."

As for the shapes of their orbits, these tend to be conic sections. Either ellipses or hyperbolas are common orbits, but a first guess for the orbit of a newly discovered comet is a parabola:

"A parabola is close to both an ellipse and a hyperbola. This brings us back to the short-period comet that hit the headlines, named 67P/Churyumov-Gerasimenko after its discoverers Klim Churyumov and Svetlana Gerasimenko."

When the author says "back to" the comet, recall that this is the comet he first mentions in the prologue at the start of his book. Anyway, by studying its shape, astronomers can determine how the comet formed:

"Starting from a mathematical representation of the observed shape of the comet's surface, the team first worked out the positions and orientations of 103 planes, each providing the best fit to a geological feature associated with the observed layers, such as a terrace (flat region) or cuesta (a type of ridge)."

At this point Stewart includes several pictures of possible comet shapes. In the first, he shows two competing scenarios for the structure of 67P. On the left is the comet shape according to the collision theory, while the other is its shape according to erosion theory. Both pictures include a terrace and two layered cliffs. In the collision theory picture, there is a rubble neck between the two original objects that collided. In the erosion theory picture, there is an eroded neck.

The next picture is a schematic illustration of best-fitting planes to terraces and cuestas. Once again,  on the left is collision theory and on the right is erosion theory. The actual calculation was performed in three dimensions using a statistical measure for the best fit, and used 103 planes.

Recall that Philae was the name of the comet lander that we saw in the prologue as we read:

"Philae made a difficult, and as it turned out, temporary, landing on the duck's head. The landing did not go as intended."

The "duck" here refers to the shape of the comet -- indicating that the collision theory fits better. The problem was that the lander's solar panel was facing away from the sun, so it couldn't gain energy.

The Rosetta -- the spacecraft that sent out the lander -- still had enough power to gather comet data:

"Astronomers were startled by one of Rosetta's chemical discoveries: quite a lot of oxygen molecules in the gas cloud surrounding the comet."

As for the ultimate origin of comets, many might have started in the Oort cloud, named for its discoverer, Dutch astronomer Jan Oort:

"There are trillions of bodies a kilometre or more across in the outer halo, and the inner cloud contains a hundred times as many."

Oort's contemporary also has a "belt" named after him:

"In 1951 Gerard Kuiper proposed that a disc of small bodies might have collected in that region early in the formation of the solar system, but he thought (as many then did) that Pluto was about the size of the Earth, so it would have disturbed the disc and scattered its contents far and wide."

But as it turns out, Kuiper was wrong -- yet the disc is now known as the Kuiper belt. And this belt is the origin of many strange objects:

"Centaurs are bodies occupying orbits that cross the ecliptic between the orbits of Jupiter and Neptune; they persist for only a few million years, and there are probably about 45,000 of them more than a kilometre across."

The author's next picture of Shoemaker-Levy 9, a comet discovered on 17 May 1994. This comet would soon crash into Jupiter:

"In the event, the impact was even more dramatic than expected, leaving a chain of gigantic scars across the planet that slowly faded, remaining visible for months."

Indeed Stewart's final picture is of Jupiter. Dark spots are some of the impact sites from the fragments of Shoemaker-Levy 9. The author tells us that we should be grateful for Jupiter's presence:

"This aspect of Jupiter helps to protect the inner planets from comet and asteroid impacts, leading to the suggestion in Peter Ward and Donald Brownlee's Rare Earth that a large planet like Jupiter makes its inner worlds more habitable for life."

Indeed, it was right after this that the Simpsons episode "Bart's Comet" aired -- about the possibility that a comet could hit our planet. And on that note, Stewart ends the chapter by mentioning the asteroids close to our orbit:

"So far 872 have been detected, of which 153 might potentially hit us. Estimates suggest another 70 or so exist, but haven't yet been spotted."

Lemay Chapter 9: Graphics, Fonts, and Color


After not doing a chapter on Tau Day, I feel I've been moving too slowly through the Java text. Thus until further notice, I'll cover an entire chapter in each post.

Here's the link to today's lesson:

http://101.lv/learn/Java/ch9.htm

Lesson 9 of Laura Lemay's Teach Yourself Java in 21 Days! is called "Graphics, Fonts, and Color," and here's how this chapter begins:

Knowing the basics of how applets work is only the first step. The next step is to become familiar with the capabilities Java gives you for drawing to the screen, performing dynamic updating, managing mouse and keyboard events, and creating user interface elements. You'll do all these things this week. You'll start today with how to draw to the screen-that is, how to produce lines and shapes with the built-in graphics primitives, how to print text using fonts, and how to use and modify color in your applets.

We start with a reminder of how any applet that uses graphics must begin:

The Graphics class is part of the java.awt package, so if your applet does any painting (as it usually will), make sure you import that class at the beginning of your Java file:
import java.awt.Graphics;

public class MyClass extends java.applet.Applet {
...
}
And we learn that each pixel on the screen has a coordinate:

Java's coordinate system has the origin (0,0) in the top-left corner. Positive x values are to the right and positive y values are down. All pixel values are integers; there are no partial or fractional pixels. 

Lemay tells us that other graphics programs have the origin in the lower left -- that is, like Quadrant I of the Cartesian plane -- but Java uses a Quadrant IV system. It turns out that Mocha -- in its very primitive graphics code -- also uses a Quadrant IV system. (But I don't wish to post Mocha code here in the Java section of this blog.)

We proceed to learn how to draw lines:

To draw straight lines, use the drawLine() method. drawLine() takes four arguments: the x and y coordinates of the starting point and the x and y coordinates of the ending point. So, for example, the following MyLine class draws a line from the point 25,25 to the point 75,75. Note that the drawLine() method is defined in the Graphics class (as are all the other graphics methods you'll learn about today). Here we're using that method for the current graphics context stored in the variable g:
import java.awt.Graphics;

public class MyLine extends java.applet.Applet {
    public void paint(Graphics g) {
        g.drawLine(25,25,75,75);
    }
}
Rectangles are next.

To draw a plain rectangle, use either the drawRect() or fillRect() methods. Both take four arguments: the x and y coordinates of the top-left corner of the rectangle, and the width and height of the rectangle to draw. For example, the following class (MyRect) draws two squares: The left one is an outline and the right one is filled:
import java.awt.Graphics;

public class MyRect extends java.applet.Applet {
    public void paint(Graphics g) {
        g.drawRect(20,20,60,60);
        g.fillRect(120,20,60,60);
    }
}
There's also something called "rounded rectangles":

Rounded rectangles are, as you might expect, rectangles with rounded corners. The drawRoundRect() and fillRoundRect() methods to draw rounded rectangles are similar to regular rectangles except that rounded rectangles have two extra arguments for the width and height of the angle of the corners. Those two arguments determine how far along the edges of the rectangle the arc for the corner will start; the first for the angle along the horizontal plane, the second for the vertical. Larger values for the angle width and height make the overall rectangle more rounded; values equal to the width and height of the rectangle itself produce a circle.
import java.awt.Graphics;

public class MyRRect extends java.applet.Applet {
    public void paint(Graphics g) {
        g.drawRoundRect(20,20,60,60,10,10);
        g.fillRoundRect(120,20,60,60,20,20);
    }
}
The last type of rectangle we have is a so called "3D rectangle" -- in the U of Chicago text, we called such figures "boxes":

Finally, there are three-dimensional rectangles. These rectangles aren't really 3D; instead, they have a slight shadow effect that makes them appear either raised or indented from the surface of the applet. Three-dimensional rectangles have four arguments for the x and y of the start position and the width and height of the rectangle. The fifth argument is a boolean indicating whether the 3D effect is to raise the rectangle (true) or indent it (false). As with the other rectangles, there are also different methods for drawing and filling: draw3DRect() and fill3DRect(). The following is a class called My3DRect, which produces two 3D squares-the left one raised, the right one indented:
import java.awt.Graphics;

public class My3DRect extends java.applet.Applet {
    public void paint(Graphics g) {
        g.draw3DRect(20,20,60,60,true);
        g.draw3DRect(120,20,60,60,false);
    }
}
Not every figure we wish to draw is a rectangle -- there are other polygons as well:

As with rectangles, you can draw an outline or a filled polygon (using the drawPolygon() and fillPolygon() methods, respectively). You also have a choice of how you want to indicate the list of coordinates-either as arrays of x and y coordinates or as an instance of the Polygon class.

The array method is more straightforward:
import java.awt.Graphics;

public class MyPoly extends java.applet.Applet {
    public void paint(Graphics g) {
        int exes[] = { 39,94,97,142,53,58,26 };
        int whys[] = { 33,74,36,70,108,80,106 };
        int pts = exes.length;

        g.drawPolygon(exes,whys,pts);
    }
}
But, as we saw earlier, there is also a built-in Polygon class:
import java.awt.Graphics;

public class MyPoly2 extends java.applet.Applet {
    public void paint(Graphics g) {
        int exes[] = { 39,94,97,142,53,58,26 };
        int whys[] = { 33,74,36,70,108,80,106 };
        int pts = exes.length;
        Polygon poly = new Polygon(exes,whys,pts);
        g.fillPolygon(poly);
    }
}
We proceed with ovals -- which, as we find out, are Java's name for either circles or ellipses:

As with the other drawing operations, the drawOval() method draws an outline of an oval, and the fillOval() method draws a filled oval.
import java.awt.Graphics;

public class MyOval extends java.applet.Applet {
    public void paint(Graphics g) {
        g.drawOval(20,20,60,60);
        g.fillOval(120,20,100,60);
    }
}
The last figure that we learn to draw is the arc:

The drawArc() method takes six arguments: the starting corner, the width and height, the angle at which to start the arc, and the degrees to draw it before stopping. Once again, there is a drawArc method to draw the arc's outline and the fillArc() method to fill the arc. Filled arcs are drawn as if they were sections of a pie; instead of joining the two endpoints, both endpoints are joined to the center of the circle.

The author tells us that the angles are labeled just as they are in Circular Function Trig -- for the starting angle, 0 degrees is to the right, and 90 degrees is up. And for the drawing degrees, clockwise is negative and counterclockwise is positive. (And yes, these are degrees, so there's no reason to think about radians or the pi vs. tau debate.)
import java.awt.Graphics;

public class MyOval extends java.applet.Applet {
    public void paint(Graphics g) {
        g.drawArc(20,20,60,60,90,180);
        g.fillArc(120,20,60,60,90,180);
    }
}
The final example is an "arc of an ellipse":
import java.awt.Graphics;

public class MyOval extends java.applet.Applet {
    public void paint(Graphics g) {
        g.drawArc(10,20,150,50,25,-130);
        g.fillArc(10,80,150,50,25,-130);
    }
}
So now we finally reach the first listing. That's right -- everything we done so far are mere examples and not the official first listing:

Listing 9.1. The Lamp class.
 1: import java.awt.*;
 2: 
 3: public class Lamp extends java.applet.Applet {
 4: 
 5:    public void paint(Graphics g) {
 6:        // the lamp platform
 7:        g.fillRect(0,250,290,290);
 8:
 9:        // the base of the lamp
10:        g.drawLine(125,250,125,160);
11:        g.drawLine(175,250,175,160);
12: 
13:        // the lamp shade, top and bottom edges
14:         g.drawArc(85,157,130,50,-65,312);
15:         g.drawArc(85,87,130,50,62,58);
16: 
17:         // lamp shade, sides
18:         g.drawLine(85,177,119,89);
19:         g.drawLine(215,177,181,89);
20: 
21:         // dots on the shade
22:         g.fillArc(78,120,40,40,63,-174);
23:         g.fillOval(120,96,40,40);
24:         g.fillArc(173,100,40,40,110,180);
25:    }
26: }
This applet draws a lamp -- "or a mushroom," as Lemay tells us -- on the screen.

We're done with shapes -- let's move on to fonts. We must import java.awt.Font in order to use these fonts (or import java.awt.* which imports all of java.awt -- Lemay does this in her last listing but never explains it).

The current font is part of the graphics state that is kept track of by the Graphics object on which you're drawing. Each time you draw a character or a string to the screen, Java draws that text in the current font. To change the font of the text, therefore, first change the current font. The following paint() method creates a new font, sets the current font to that font, and draws the string "This is a big font.", at the point 10,100:
public void paint(Graphics g) {
    Font f = new Font("TimesRoman", Font.PLAIN, 72);
    g.setFont(f);
    g.drawString("This is a big font.", 10, 100);
}
Here is the second listing:

Listing 9.2. Many different fonts.
 1: import java.awt.Font;
 2: import java.awt.Graphics;
 3:
 4: public class ManyFonts extends java.applet.Applet {
 5:
 6:    public void paint(Graphics g) {
 7:        Font f = new Font("TimesRoman", Font.PLAIN, 18);
 8:        Font fb = new Font("TimesRoman", Font.BOLD, 18);
 9:        Font fi = new Font("TimesRoman", Font.ITALIC, 18);
10:        Font fbi = new Font("TimesRoman", Font.BOLD + Font.ITALIC, 18);
11:
12:        g.setFont(f);
13:        g.drawString("This is a plain font", 10, 25);
14:        g.setFont(fb);
15:        g.drawString("This is a bold font", 10, 50);
16:        g.setFont(fi);
17:        g.drawString("This is an italic font", 10, 75);
18:        g.setFont(fbi);
19:        g.drawString("This is a bold italic font", 10, 100);
20:    }
21:
22: }
The author explains that fonts can be added, so Font.BOLD + Font.ITALIC is indeed a bold italic font.

We learn about something called FontMetrics (which we must import, by the way) to give us information about a font:

For more detailed information about the qualities of the current font (for example, the length or height of given characters), you need to work with font metrics. The FontMetrics class describes information specific to a given font: the leading between lines, the height and width of each character, and so on. To work with these sorts of values, you create a FontMetrics object based on the current font by using the applet method getFontMetrics():
Font f = new Font("TimesRoman", Font.BOLD, 36);
FontMetrics fmetrics = getFontMetrics(f);
g.setFont(f);
Here I fix an error in Lemay -- she writes setfont instead of setFont.

Here is the third listing, where FontMetrics is used to center the text based on the font size:


Listing 9.3. Centering a string.
 1: import java.awt.Font;
 2: import java.awt.Graphics;
 3: import java.awt.FontMetrics;
 4:
 5: public class Centered extends java.applet.Applet {
 6:
 7:    public void paint(Graphics g) {
 8:        Font f = new Font("TimesRoman", Font.PLAIN, 36);
 9:        FontMetrics fm = getFontMetrics(f);
10:        g.setFont(f);
11:
12:        String s = "This is how the world ends.";
13:        int xstart = (size().width - fm.stringWidth(s)) / 2;
14:        int ystart = size().height / 2;
15:
16:        g.drawString(s, xstart, ystart);
17:    }
18:}
The author tells us that size returns a Dimension object, but my compiler issues a warning that using the size method is "deprecated." I like how the text is automatically centered even as I manually change the size of the window.

The final topic for this lesson is color. Once again, we must import colors first. We learn that colors are typically specified using three RGB values (0-255) for red, green, and blue. There are also several colors that are built in (such as white, black, gray, red, and so on) that we can specify without having to give the RGB values.

The methods setColor, setBackground, and setForeground are used to change the color.

Here is the fourth and final listing, which chooses colors at random:


Listing 9.4. Random color boxes.
 1:  import java.awt.Graphics;
 2:  import java.awt.Color;
 3:
 4:  public class ColorBoxes extends java.applet.Applet {
 5:
 6:      public void paint(Graphics g) {
 7:          int rval, gval, bval;
 8:
 9:          for (int j = 30; j < (size().height -25); j += 30)
10:             for (int i = 5; i < (size().width -25); i += 30) {
11:                 rval = (int)Math.floor(Math.random() * 256);
12:                 gval = (int)Math.floor(Math.random() * 256);
13:                 bval = (int)Math.floor(Math.random() * 256);
14:
15:                 g.setColor(new Color(rval,gval,bval));
16:                 g.fillRect(i, j, 25, 25);
17:                 g.setColor(Color.black);
18:                 g.drawRect(i-1, j-1, 25, 25);
19:             }
20:     }
21: }
As Lemay tells us, each time I manually maximize or minimize the window, the random colors keep on changing. The TI calculators do the same thing each time we go back and forth between the graph and table for, say, the rand function.

More About Approximating Tau in Java

I was hoping that in this lesson, I'd finally see a draw method that would allow me to implement the applet that I saw in that Coding Train video I posted on Tau Day. But instead, just as I feared, Lemay simply continues on with using the paint method that she explains in her last lesson. Thus many of the things I saw in that video still won't work.

And indeed, even the random function that appears in the fourth listing is the one that's more like TI's rand function and not the randInt that we see in the video. We notice that the floor and (int) are there to force the double returned by random() into an int -- our graphics still can't use the floats that I saw in the video.

So let's try to create our own version of the Approximating Tau applet, using the Graphics that Lemay has taught us so far.

The program in the video takes uses the Monte Carlo method to approximate the circle constant, either pi or tau. It chooses a point at random and displays it on the graph if it lies within a circle, which has radius 200. We can't draw a single point -- instead, we must drawLine with the same point as its endpoints.

Here is the program I wrote:

import java.awt.Graphics;

public class ApproximatingTau extends java.applet.Applet {
int r = 200;

int total = 0;
int circle = 0;

double recordTau = 0;

public void paint(Graphics g) {
for (int i = 0; i < 10000; i++) {
int x = (int)Math.floor(Math.random() * r);
int y = (int)Math.floor(Math.random() * r);
total++;

int d = x * x + y * y;
if (d < r * r) {
circle++;
g.drawLine(x,y,x,y);
}

double tau = (double)8 * (double)circle / (double)total;
System.out.println(tau);
double recordDiff = Math.abs(2*Math.PI - recordTau);
double diff = Math.abs(2*Math.PI - tau);
if (diff < recordDiff) {
recordDiff = diff;
recordTau = tau;
System.out.println(recordTau);
}
}
}


}


Since our coordinates must be positive, only a quarter of the circle is graphed. And just like the Lemay listings earlier, each time I change the size of the applet window, new random points are graphed, so I can continue to get more estimates. Each time, tau works out to be approximately 6.3.

Conclusion

Well, we're back on track with Shapelore, music, and the rest of my summer projects. And all of my projects will continue in the next post.

1 comment:

  1. i read a lot of stuff and i found that the way of writing to clearifing that exactly want to say was very good so i am impressed and ilike to come again in future..
    arabic oud instrument

    ReplyDelete