I love the combination of music and technology. My major in college was Music Theory that gave me the opportunity to orchestrate music for different sets of instruments and to compose music. This is something that I really enjoy doing, especially orchestrating music. Most music software allows you to drag and drop the musical notation into a score. You can assign the instruments from a menu. This paradigm is good because it allows the musician to think like a musician and work within an environment that he or she is use to. However, sometimes coding provides a better way. The coding language can make it easier to enter the notes and to reuse sections of music that repeat at different parts of the composition. I plan to write a series of articles about coding music. In this post I am going to introduce you to Trinket.io’s music program. It provides an easy way to create short musical pieces. You enter the name of the notes that define the pitches. It is not really coding but it is a method that some other sites also use. The goal is to provide an easy, fun way for people to enjoy music. The following example is from their website. To enter the notes cdefgab in the bass, use the note name but capitalize it, CDEFGAB. To enter these pitches in the treble clef, use the lower case, cdefgab. You can create chords by entering the notes of the chords within angle brackets, for example, here is a C major triad <c e g>. The following images display the other things that you can do with this program.
The previous code puzzles were written with two coding languages, Block and Scratch, that teach children coding concepts. When programmers want to write an app or program, they use text-based coding languages, for example, Python. Our first code puzzle displayed the message “Hello world”, asked the user his or her name, and then displayed the name the user typed in. Here is the same example written in Python. How the code works
Here's the output. Computers are good at making decisions. They can do something based on the state you are from, by your age, and any other information that distinguishes one person form another or one product from another. Here is a code snippet that makes a simple decision. What does the code do? This code is written in Block from trinket.io. The code asks the user what city he/she is from. If the user types Boston, the code displays the message, “The Boston Red Sox are your favorite baseball team." If the user types any city but Boston, the code displays, “You like another team.” How does the code work? The code begins by displaying the text “What city are you from?" and saves the user’s answer in the variable myCity. The code checks to see if the user entered Boston. If the user did, the code displays the text, “The Boston Red Sox are your favorite baseball team.” If no, if the user typed in a city other than Boston, the code displays the message, “You like another team.
Today’s puzzle is similar to yesterday’s. It does the same thing but uses a different introductory, free coding language called Scratch, developed by MIT. How the code works
Scratch, Blocks, and other coding languages Our first coding puzzle used a coding language called Blocks and this puzzle uses a coding language called Scratch. Blocks and Scratch are designed to teach beginners, especially children, how to code. There are many other coding languages, some created for specific purposes and others for general use. We’ll explore them in future code puzzles. Puzzles are fun. Some people like crossword puzzles and some people like Sudoku. Solving a puzzle is rewarding, it gives you a sense of accomplishment. I like coding puzzles. They provide a logical challenge to solve a problem and learn a bit of coding. I’m writing coding puzzles to provide you a gentle introduction to coding using a variety of coding languages. After each puzzle, I’ll give you the opportunity to solve the puzzle and then share the answer with you. I’ll also explain how the code works. What does this code do?
How the code works This example uses a beginner's language called Blocks that you can access free of charge on the Trinket website. The code does the following:
Here is the output after running the program. I typed in the name Alan.
|
AuthorTechnology and education are my passion. I make my living as a technical writer and creating wikis on Sharepoint. Archives
April 2020
Categories |