Programming and Spirals
This week we combined 2 Scratch Projects:
- The Programming project that we did last week
- The Spirals project that we did a while ago
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 working though, there is a process to follow to get the Programming project to draw the same Spiral as the Spirals project.
- Open the Spirals project
- Run the Spirals Project so it populates the Commands to run
- Right Click the List and Export the list of Commands to a file.
- Open the Programming project
- Right Click the List and Import the list of Commands from the file created in step 3
- Run the Porgramming project and it will draw the same Spiral as the Spirals project.
And this is how we did it….
The Programming Project:
This project turns Scratch in to a Programming language which can draw different things. You “Program” it using the List where you can either write command manually or, as we did, get another Scratch project to write the commands.
Our Programming languge has some rules that we need to follow:
- Each “Command” would be 1 Upper Case letter
- The Command would be followed by a colon (:)
- Following the colon would be any Value that the Command might need
For example, the get the Sprite to Move 10 steps you would put this in the list:
We put code in place so it would understand all the following Commands:
|Scratch Command||Our Command||Value|
|MOVE||M:||The number of steps to Move|
|TURN||T:||The number of degrees to Turn|
|Go To X||X:||The X position the Sprite should move to|
|Go To Y||Y:||The Y position the Sprite should move to|
|Erase All||E:||Erase, although this is not strictly necessary|
|Change Pen colour||C:||The vlaue the colour should be changed by|
So, for example, if you wanted the Sprite to draw a square, you could put the following commands in to the list:
The Sprite would draw a square with each side being 100 steps.
You can see though, that writing all the commands in to the list by hand could take quite a while, so wouldn’t it be a good idea if we could get another Scratch Project to write the Commands for us? So that is exactly what we did.
The Spirals Project
We took the Spirals project that we wrote a while ago and made a few simple changes:
- We added a List variable
- When we told the Sprite to Go To X,Y we added an X:… and Y:… command to the list
- When we put the Pen Down we added a P:Down command to the List
- When we Moved the Sprite we added a M:… command to the List
- When we Turned the Sprite we added a T:… command to the List
We then ran the Spirals project which generated a long list of cammnds to be run, this could be several thousand, depending on how many sides the Spiral had for example.
This is what the code looked like after our changes:
Once the list had been generated, you can then “right” click on the list and Export it to a file.
Once you have the file, you will need to re-open the Programming project, “right” click on the list and Import the file.
I have loaded both of the projects that we used to Scratch.mit.edu
If you don’t have your own User Id and Password, you can access the projects using:
User : athenryadvancers
Pass : Advancers