Sunday, November 24, 2013

Lesson 39 - King of Polygons

Today it was time to get back into action and actually implement the function for drawing a polygon with an arbitrary number of edges.

We started by recapping how to calculate the vertex angle:

    360 / n, where n is the number of vertices

She has indeed forgotten all about this calculation, but she remembered the number 360.

Then we started working on the actual function. After maybe 15 minutes of discussion and typing (5 mins allocated for picking a name as always) we came up with

    let polygon k=r k (s [fd 50,rt (360 /k)])

Dead simple for a coder but daunting for a 4-year old. When explained, it's not very complex yet. To draw a polygon with k number of edges, you repeat the following k times:

  1. Move forward 50 pixels
  2. Turn right (360 / k) degrees
So, it was hard but it paid off. After struggling with the first polygon as in

    polygon 6

She got crazy and drew all polygons up to 14 edges. Then they didn't fit into the Turtle Roy display anymore and we had to change her program a bit using the Turtle Roy "editor mode": we added fd 20 and lt 180 to the start so that she can squeeze in a couple more polygons. You can check out the end result here.

She was indeed so enthusiastic about polygons that she gave Mom a lesson too. Together they hacked the program so that it moves only 10 pixels at a time, so that they can draw the King of Polygons: the Hectogon. It looks like a circle, actually.

Saturday, November 23, 2013

Lesson 38 - Geometry and Math

Today she was totally against the idea of having a lesson. So we decided to discuss our goals instead. What do you want to learn to do? She drew a snowmanlike figure on the paper and told me she'd like to be able to draw the same thing with Turtle Roy. 

Then we discussed geometry. How many degrees in a circle? Agreed on 360 and that it's a big number. Practised writing it. Then discussed the priciple of drawing a circle with a computer: go forward just a notch, then turn left a notch. Repeat until done.

To my surprise she wanted her snowman to be made of hexagons instead. How to do that? What are the angles of the vertices? Back to basic arithmetics then. What if you had 4 wieners and had to split them for 2 people. She solved that just fine. Then I wrote down


And explained that when you divide 4 by 2, you write it down like this and the computer will be able to solve the problem for you. So, if you want to know the angles in a hexagon, you're gonna have to split the full circle (360) into 6 equivalent parts. We practiced writing


On the paper. Then she wanted to know the answer and "asked the computer". She was quite sure though that a decagon does not exist. I told here that anygon is in fact reality, i.e. you can draw a polygon with an arbitrary number of equivalent vertices. We agreed to create a program for drawing a polygon with any number of vertices tomorrow. That, in fact, is a great exercise in programming!

Then, on her request, we click on all of my bookmarks (we used my computer this time) and I explained what they do. Google Maps was especially interesting. We discussed continents, countries, borders and such. Now she knows that Richard is in fact from Africa, because Cameroon is a part of it. I guess she's starting to grasp the notions of country and continent.

Any Publicity is Good Publicity

I just realized that it's been more than a week since our last proper, documented Lesson.

Since our previous lesson, stuff has happened, though.

We had our 2nd Reaktor Code School on the 12th, with a room (a bit more than) full of kids and parents hacking on Turtle Roy.

Then we've had a couple of interviews with the newspapers. Mila got to demonstrate her proficiency on both Helsingin Sanomat and Hufvudstadsbladet. She had a good time talking about computers and stuff with the reporters.

But I think it's time to get back to business today. The question is though, what next?

Monday, November 11, 2013

37 - hiiri

Yesterday I told her that she can send a link to any of her Turtle Roy programs by email to her friends. She got quite excited and wanted to send links to her cousins immediately. The problem was she didn't have an email account so I promised we'll do it later.

Today I set up a Gmail account for her use and configured Apple Mail to use it.

Then we asked mom to send her an email. And so she received her first email from mom. She replied to it with ease. It seemed that the email program was quite easy to use for her. But hey, what would you expect from a vim user?

Then she wanted to send daddy a message too. I showed her how to do that and she typed my email address and all quite well. Then I explained the idea of the subject field and the message body and asked her what she wants to write. I suggested that if she doesn't have anything particular in mind, she could simply use "hello" as the subject. 

In fact she did have something particular in mind.

Just "hiiri". No questions asked.

Sunday, November 10, 2013

Lessons 35-36 - Parametericity

Yesterday we continued with our music project by defining functions taa and titi, so that we can now play an eight and quarter notes as well as a double eight-note. Like

    let ti n = play n 500
    let taa n = play n 1000
    let titi n = s [ti n, ti n]

Today we recapped on that after discussing functions, parameters and other topics. Then she suggested we define yet another function "taa-a", that would be a half-note. And when I asked whether it should have a parameter, she said yes. Did she understand the question?

Anyway, she started typing

   let taaa

Then I asked her what the parameter should be called. First she said "lintu" which means the E string of the violin, but then thought a bit and corrected: we should use n so that we can play any note. The name of the parameter doesn't matter of course, but I think she's starting to grasp the concept of functions and parameters already.

Then she implemented the rest of the function, with some tips from me:

    let taaa n=play n 2000

She remembered the function play. When I asked her which note we should play, she said n. I think that's quite incredible. She almost got the number two-thousand right, too. As in 200.

Sunday, November 3, 2013

Lesson 34 - Wheel of fortune

Am I running out of descriptive titles for posts?

Today we continued on our professional audio API project.

The goal is to create functions for playing the familiar "taa" and "ti" notes (quarter-note, eight-note) with different pitches. This requires us to write functions with parameters, which isn't actually entirely new to us. So, we want a function that can be used to play an eight-note of any pitch. For example to play C:

    ti c

The "c" here actually refers to the frequency of the C note (261.63 Hz) and is a parameter of the function "ti".

We wrote the "ti" function like

    let ti n = play n 100

This translates to "to play an eight note of frequency n, you should plan the n note for 100 milliseconds". I explained the idea of a function parameter to her so that when you call the function, the parameter n will be replaced by the note you give to the function. And used a couple of examples.

Then we tried the function like

    ti e

And it worked like a charm. Then she wrote the similar function "taa" mosly by herself. It worked too. I'm glad she used a different arbitrary name for the function parameter, to illustrate that the computer doesn't really care about the names; they are merely for us humans to care about.

Then she saved the file.

    save "nakki"

Arbitrary names seems to be the way to go. We'll continue our program next time.

Why Wheel of Fortune? It's just the movement she makes with her hand while looking up the letters on the keyboard. Circling around the keyboard like an eagle looking for prey. Not that she misses often.

Saturday, November 2, 2013

Lesson 33 - Little Star

Tonight, after her violin lesson, while eating oatmeal, I reminded her that the violin notes are indeed sequences of actions, where each note is an action. She then asked me whether she could make a "karhu titi" program in that Turtle Roy thing. She meant a program that would play two short notes using the lowest string (G) on the violin. And I was like, yes you can.

So we started by opening our previous work "kielet" in Turtle Roy:

    open "kielet"

Now we had a function named "karhu" at use. This function plays the note G. She knew that we need a sequence of two "karhus" to complete our program and she started by defining a new function "karhutiti". It, once again, took quite a while to decide on the final name of the function, but we finally settled with "kt". Actually the long discussion on naming got her to lose her focus... and she didn't remember what to do after

    let kt

So I had to remind her of the equals-sign that follows. Then it was time for function implementation. She remembered that the "s" function can be used to make a sequence, so

    let kt = s

Surprisingly she didn't remember that square brackets are used in lists. I guess she wasn't in the "zone" anymore. But after reminding her about the square brackets, she hacked the function together pretty quickly:

    let kt = s [karhu, karhu]

She tried it and it worked! After another long discussion on naming, we saved the work using

    save "sei"

I asked her are we done, and she wanted to do more. Particularly she wanted to add more pictures to her HTML scrapbook, but I refused that as a too heavy a task just before bedtime and suggested some simple drawing with Turtle Roy. 

Then she asked me what I'd like her to draw. I suggested a right angle and she started writing a new sequence of things, but we were interrupted by her baby sister who wanted to perform Twinkle Twinkle Little Star in both Finnish and English. 

That was indeed pretty cute.