## We started with a basic plan:

• 1 Piano Sprite
• 3 Button Sprites
• Record
• Stop
• Play
• A list to store all the possible Piano notes.
• A list to store the tune being played.

Luckily Scratch comes with a Piano Sprite, which we used and expanded it to fill the width of the screen.

Next step was to create the list of all the notes, there are 14 keys on the Piano so we need at least 14 notes in our list.

We found out what notes are possible by using one of the Sound blocks and looking at what was possible

This gave us our list of possible notes:

Now on to the code…

We needed to work out what key on the Piano had been clicked, and convert it to a number between 1 and 14 so we could play the correct note from the list.

This required some tricky calculations, to convert the Mouses “X” position to a positive integer between 1 and 14.

• First we added a number to make X always positive
• Second we divided that by the size of a note.
• And finally we rounded it up, using the ceiling function.

This ended up with the following code and a couple of Variables to store the “Extra” number to make X positive and the size of a note:

Once we had the positive integer we could use it to select the correct note to play from the list:

We did start some of the Buttons, and we will complete them next week. Notes for the buttons will be included then.

## Buttons

In order to make the Piano a bit more usable we added 3 Buttons:

1. Record
2. Stop
3. Play

All three Buttons had two costumes, we used the second costume to change the colour of the Button, this made it easy to see if you had clicked the button or not.

The Record button, simply set a Data Flag to indicate to the Piano code that it should “record” the notes being played in a List variable.

It also flashed while recording was “on”, this is the code for the Record Button:

We also had to add some additional code to the Piano to make sure the notes were recorded:

The Stop button was quite simple, we just set the Data Flag back to 0, and changed the costume for a short while to make it clear that the button had been pressed.

The Play button was a little more complex as it need to read all the items in the List and play the correct notes. It also flashed while playing. This is the code from the Play button:

The Final project looked something like this, you can get a copy from the Scratch Web Site, see the Notes below.

# Notes:

Note: My version of the project has been uploaded to https://scratch.mit.edu you can Sign in using the following details:

• Project Name is : Class-Piano

This week Eoin led the Advancers group, we looked at drawing in Scratch, using the Pen blocks and some simple maths to draw some patterns.

As always, we started with a Plan:

A Plan

1. A Button Sprite – to start the drawing.
2. A Simple Sprite to do the drawing.
3. Some maths to make it draw a Spiral

We started by drawing a square, to draw a square in Scratch we used the Pen down, Turn and Move blocks.

To get a spiral effect we had to make sure that we moved a little bit further each time we drew our square.

We also decided that we should be able to make spirals with different shape so we  needed some variables to help:

• Shape – This would tell us how many sides the Spiral should have
• We made this in to a Slider on the screen so it was adjustable.
• Min value was 3 and Max value was 100
• Degrees – This would tell us how much extra to turn, this made the patterns a lot more interesting.
• Again, we made this one into a Slider so we could adjust it.
• Min value was 0 and Max value was 360
• Size – This was an internal variable, which we used to keep track of how many Steps to move each turn, we also added a little bit to it each turn to make the Spiral pattern.

## The drawing Sprite

This was the Sprite that did all the work. To work out how far we should Turn each time, we divided 360 by the number of Sides, we then added the degrees value to get the strange effects working.

The code ended up looking like this:

## The Button Sprite

We used this sprite to start drawing, we used a broadcast so out button sprite could “talk” to out drawing sprite.

Oliver will be back next Saturday.

See you all then Declan and Eoin

# ModderDojo Topic 4: Moving from Scratch to JavaScript

Note: some individual topics are short: we got most of the way through the first 3 in our taster session. See this post: https://cdathenry.wordpress.com/2015/09/27/minecraft-modding-taster-session-week-1/

JavaScript is a well-established programming language, mainly used in web development. ScriptCraft is a Minecraft mod that allows you to write JavaScript code for building structures in Minecraft and writing new Minecraft mods. (So it’s a mod for creating other mods.)

## Steps 1-3: Install ScriptCraft, Learn how to Connect to a Server, and Create a First Mod

We covered these steps in the first two weeks:

To try out ScriptCraft, look back at the introductory posts here: https://cdathenry.wordpress.com/2015/09/27/minecraft-modding-taster-session-week-1/

## Step 4: Comparing JavaScript to Scratch

Some people criticise Scratch as being “childish”, but I don’t agree. While it is designed so that even 8 year olds can use it, it is still has all of the key features of ‘adult’ programming languages, as listed in the image at the top of this post.

(Technically, any programming language with variables, decision and loops is Turing Complete.)

This means that, if you already know how to write a Scratch programs that use these features, you will be able to apply that knowledge to any other language, such as JavaScript. The syntax of JavaScript is different, but it uses the same computational thinking.

Notes:

• Even though they have basic ideas in common, every programming language has its own specific commands that relate to its purpose: Scratch is focused on 2D games and animations, while ScriptCraft is focused on operating inside Minecraft, and JavaScript generally is used for interactive websites.
• the echo command that features in these slides is not a standard JavaScript command, it is just used in ScriptCraft to display things on your screen in Minecraft.  Everything else is standard JavaScript.

# ModderDojo Topic 5: Moving from Scratch to JavaScript

Reminder: JavaScript is a well-established programming language, mainly used in web development. ScriptCraft is a Minecraft mod that allows you to write JavaScript code for building structures in Minecraft and writing new Minecraft mods. (So it’s a mod for creating other mods.)

## Steps 1 and 2: Try out ScriptCraft commands and write simple mods

Please look back to last week’s notes for now to do this: https://cdathenry.wordpress.com/2013/10/05/modderdojo-week-1-getting-started-with-scriptcraft-and-javascript/

## Step 3: Comparing JavaScript to Scratch

Some people criticise Scratch as being “childish”, but I don’t agree. While it is designed so that even 8 year olds can use it, it is still has all of the key features of ‘adult’ programming languages, as listed in the image at the top of this post.

(Technically, any programming language with variables, decision and loops is Turing Complete.)

This means that, if you already know how to write a Scratch programs that use these features, you will be able to apply that knowledge to any other language, such as JavaScript. The syntax of JavaScript is different, but it uses the same computational thinking.

Notes:

• Even though they have basic ideas in common, every programming language has its own specific commands that relate to its purpose: Scratch is focused on 2D games and animations, while ScriptCraft is focused on operating inside Minecraft, and JavaScript generally is used for interactive websites.
• the echo command that features in these slides is not a standard JavaScript command, it is just used in ScriptCraft to display things on your screen in Minecraft.  Everything else is standard JavaScript.