Programming and Spirals This week we combined 2 Scratch Projects: Introduction We did a lot of jumping around, from one project to the other, as we had to make changes to both projects to get everything working. Once everything was … Continue reading
The Snake project has changed a little bit from Saturday. I had to add another Sprite to get the “touching colour” code to work. So now there are 3 Sprites that move around.
- The one that you move around with the Arrow keys.
- One that follows 0.2 seconds behind, this one now draws the tail and is not touching the first one.
- This one follows 2 seconds behind and erases the tail.
I also changed the first Sprite to Move “2” steps not one, this speeds it up a little. I have uploaded the completed project to the AthenryAdvancers account on http://www.scratch.mit.edu so you can take a look and have a go.
My challenge to you is to beat my high score of 1200
I have uploaded a Gravity project with one single Sprite to the AthenryAdvancers account on http://www.scratch.mit.edu.
You can use this Template project to create your own Magnify project, think of an idea and draw out the Sprites you will need on a bit of paper, give the Sprites Names on this bit of paper, it doesn’t have to be a masterpiece, any rough old picture will do.
Then you need to get one Image for each of your Sprites, save them all to the same Folder on your Computer.
Once you have your diagram and all your images you can download a copy of the Magnify Project and save it to the same folder as all the images.
The steps (process) to follow to use this Project are:
- Rename the StartSprite to the Level 1 Sprite in your diagram
- Update the Variables, for this one you only need to update the MyName variable
- Change the Costume by uploading your image for this Sprite, delete the original costume
And then to add More Levels and Sprites use these steps:
- Copy the Level 1 Sprite
- Update the new Sprites name
- Update the new Sprites variables, the MyParent needs to match the MyName of the Sprite from the level above
- Update the MyX and MyY variables to where you want this Sprite to appear on the screen, you may have to test a few different places to get it right
- Change the Costume by uploading your image for this Sprite, delete the original costume
Don’t forget to Save and Test often.
To access the Scratch website use the following details:
Username : athenryadvancers
Password : Advancers
For the final week we are going to convert the Christmas Card into a Christmas Game.
We will be starting with the Christmas Card that we made last week, if you weren’t there or want to start with the same one that I will be using, have a look at the bottom of this document, I have added instructions on how to get it.
The Plan for this week.
We will be adding some additional Sprites. We will be using Scratch Sprites rather than drawing our own to save time.
- A sprite for Santa’s sleigh
- This will move backwards and forward across the top of the screen
- A sprite for the Presents
- This will fall from Santa’s sleigh to the bottom of the screen, not directly down though.
- This sprite will have many costumes.
- As sprite for you
- You will be able to move Left and Right across the bottom of the screen to try and catch the falling presents.
The Sleigh Sprite
Scratch does not have a sleigh sprite, so I used the reindeer.
He needs to start on the top left of the screen and move all the way to the top right of the screen and then turn around and go back to the top left, he will just keep doing this.
The code might look something like this:
The Present Sprite
We might have to draw this one.
The present Sprite will start from wherever the Sleigh Sprite is glide down to a random place at the bottom of the Screen, you can make the Present a random size as well to make it more interesting.
The is a Scratch block to put one Sprite in the same place as another Sprite So the code to move down the screen will look something like this:
There will also be code to count the number of presents caught. So, if the Present Sprite touches you, it will count as being caught, so you can increase your score.
When the present is caught you can change to a random costume to display the unwrapped present.
I’ll let you figure out this code as a little challenge (I haven’t done it yet 😊 )
This is the one that catches the presents. I used the Scratch cat, finally.
Not much code for this one, he just needs to move left or right using the left or right keys on the keyboard. So, something like this:
Getting the Christmas Card project.
Login with user name AthenryAdvancers and Password Advancers
Select My Stuff and then click the See Inside button for the ClassVersion-ChritmasCard
You will then have to save it to your device, select File – Save to your computer, so you can work on your version.
Now you will have to open Scratch 3 on your device and open the file you just saved.
This will be an interactive Christmas Card.
- A nice background with Snow, Christmas Trees, a house.
- We might use different Sprites for the Trees.
- Flashing lights on the House and the Tree.
- Falling snow.
- Snow building up on the ground.
- An animated Snowman.
To make it even more interesting, we are going to make the snowflakes different sizes and fall at different rates depending on how big they are.
We will use the clone functionality to make the snowflakes.
Each clone will pick a random size and will glide to the bottom of the screen, how fast if glides will be related to how big or small it is.
The snowflake is going to be quite hard to draw as it will be a small white dot on a white background, so we will be careful.
The building up on the ground part, is quite easy, we just pick a random Y value to stop at, as long as it is close to the bottom of the screen we should be ok.
Flashing Lights or Tree Sprites
Again, these might be quite difficult to draw as we have to draw them over the background and get them to be over the Trees?
If we draw the complete Tree in the Sprite I think it is going to be a lot easier.
Flashing light code
I know Windows has a Calculator, but we are going to build our own. This will give you an idea of how real Calculators actually work.
The Calculator should be able to:
1. Add, Subtract, Multiply and Divide 2 numbers.
2. Be able to work with decimal points (2.5 for example).
3. Display the sum and the result on the screen.
4. Have a “clear” button to reset everything ready for the next calculation.
Let’s look at the steps that you need for a calculation
1. Clear the variables.
2. Click on the numbers for the first number.
3. Click on the operator you want to use.
4. Click on the numbers for the second number.
5. Click on the equals button.
6. Display the result.
Hint: When you click on the Operator, this indicates we have got the first number and need to start storing the second number. See variable 6.
It sounds like there is a lot to do, but if we are smart with the way we work, there is a lot of code that is very similar and we can copy and paste it and then modify it slightly.
You will need 6 variables (for all Sprites) to share:
1. The first number in the calculation (NumberOne), not visible.
2. The second number in the calcualtion (NumberTwo), not visible.
3. The complete sum (Question), visible.
4. The operator (+,-,x,/) for the calculation (Operator), not visible.
5. The result of the calculation (Result), visible.
6. A variable to indicate what number we are working with (SecondNumber). not visible.
Hint: When you press clear, all the variables should be set to blank, except the SecondNumber which should be 0
You will need 17 Sprites, don’t panic! Remember copy and paste is your friend:
11 Number Sprites 0,1,2,3,4,5,6,7,8,9 and the decimal point.
4 Operator Sprite +,-,x and /.
1 Equals (=) Sprite.
1 Clear Sprite.
Scratch code blocks that will be used:
Operators, we will use the join operator a lot as well as the +,-,x and /.
If Else block with variable 6 to decide what number to update.
set variable blocks – lots of these!
Start by creating the variables.
Start with just 4 Sprites, 1, +, clear and Equals
Once you can get 1 + 1 working, the rest is quite easy.
The answer is 2 (not 11) by the way, just in case.
Here is some of the code that we will be using:
This is the code when you click on a number Sprite, this example is for the number 1, can you see what needs to change if this was the number 2 sprite?
This is the code for the + Sprite
And this is the code in the = Sprite
And finally, the CLR sprite
This weeks challenge is to build a working clock.
This is not just an ordinary clock though, we are going to build a clock that works in the same way as the Railway clocks works in Switzerland.
These clocks work in the following way:
- The Clock waits for a signal from the master clock
- When it gets the signal, it moves the minute hand on by one minute (and the hour hand if necessary)
- then the second hand moves round once in about 58 seconds
- It then waits for the signal again from the master clock.
This means that all the clocks on all the Stations are synchronised exactly.
In Computer speak this is called Event Driven Programming, where the code simply waits for an Event before doing anything.
So what’s the plan?
We need 4 Sprites
- For the Clock Face
- For the Hour Hand
- For the Minute Hand
- For the Second Hand
You can create them however you want but this is what the Swiss railway clocks look like and I will try and create something similar.
Remember one thing, when creating the Sprites make sure they are centred correctly.
So, the clock face should be perfectly centred and then the hands should be centred near one end something like this, I have highlighted where the centre is, with the green circle.
Remember this will be event driven, so we will be using Broadcasts a lot. We will also have to calculate how far to move each hand, this means we will be using the number 360 a lot as that is one complete circle.
So just to let you know how far each hand should move:
- The Second hand will move 360 degrees for each event.
- The Minute hand will move 6 degrees for each event (360/60 minutes)
- The Hour hand will move 0.5 degree for each event (360/60 minutes/ 12 hours)
The first event will be broadcast from the Stage:
The Minute hand will receive this broadcast and move 6 degrees it will then broadcast another 2 events, one to the Hour hand and one to the second hand so they can move.
This is the code for the Minute hand which should be enough to work out the rest of the code as well.
The extra code above is to make sure the Minute hand starts in the correct position.
And one final thing which might be a little tricky, but I’ll leave it as a challenge for you, the Second hand should only take 58 seconds to go all the way around.
Hello again everyone.
It was great to speak to you all last Saturday.
Here are some notes with information all about CoderDojo Athenry in PDF form.
Here’s a quick recap of everyone’s notes;
Martha told us all about the Explorers group, you can contact Martha at Martha@coderdojoathenry.onmicrosoft.com and you can find her slides here.
Oliver spoke about the Advancers group and you can contact Oliver at Oliver@coderdojoathenry.onmicrosoft.com
I talked about the Bodgers group, you contact me at Declan@coderdojoathenry.onmicrosoft.com and you can read all about the Bodgers group here.
Kieran then spoke about the Modellers group. Here is his presentation.
Kieran can be contacted at Kieran@coderdojoathenry.onmicrosoft.com.
Finally Michael spoke about the Hacker Group which will be starting in the new year. Here are his slides
Mike’s email is, yes you guessed it is, Mike@coderdojoathenry.onmicrosoft.com
We will be posting information for our first session next Saturday in the next day or two, so keep an eye out for that.
Looking forward to seeing you all again next Saturday.
Declan and the CoderDojo Athenry Mentors
We started with a basic plan:
- 1 Piano Sprite
- 3 Button Sprites
- 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.
In order to make the Piano a bit more usable we added 3 Buttons:
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.
Note: My version of the project has been uploaded to https://scratch.mit.edu you can Sign in using the following details:
- Username : cdadvancers1819
- Password : advancers
- Project Name is : Class-Piano
This week in Advancers we looked at the Greenhouse Effect which is a process that occurs when gases in Earth’s atmosphere trap the Sun’s heat. This process makes Earth much warmer than it would be without an atmosphere. The greenhouse effect is one of the things that makes Earth a comfortable place to live.
We started by creating sprites for the Earth, atmosphere, space, the Sun and we used an arrow to represent the flow of heat from the Sun to the Earth and back out to space. We used a costume change on the heat sprite to represent the difference between shortwave radiation from the Sun (yellow) and longwave radiation from the Earth(red).
We made our own blocks so we could reuse some of our scripts and we used the Clone blocks to give the effect of a stream of arrows flowing from the Sun to Earth and back out to space.
Oliver will be back when we return on 09-Nov-2019.
See you all then, happy Halloween!
Declan and Eoin
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 Button Sprite – to start the drawing.
- A Simple Sprite to do the drawing.
- 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