Creators: Introducing Force

Last week in Creators, we looked at Vectors and how they can be used to specify things like position, velocity and acceleration.  This week, we looked at what can actually cause something to accelerate – FORCE!  First we talked and played a bit with force and then we created a simulation of something that we could apply different forces to.  We wanted to think about a scene where we had lots of objects and different forces acting like wind, gravity, friction, etc.

What the heck IS force?

We started off by looking at the laws of motion from Sir Isaac Newton, who was the first guy to think hard about this (or at least to come up with good theories).  Everyone knew about the apple but not many about what it made him think of.  We googled his laws of motion and arrived at a NASA web Page that had a nice short explanation:

newton

Newton’s laws of Motion (NASA)

Like all great ideas, these look obvious when you know the answer, but were huge ideas at the time!  I’ll butcher the above laws by trying to re-word them to capture the interesting thing about them from our point of view!

Continue reading

Week 8 2018 Explorers – Paint Program

Hi everybody,

our drawing program. We made good use of costumes this week to make it look like we were dipping our paint brush in each of the different colours.

We also used a variable similarly to how we used in the Piano Game we made. We made it into a slider and then code select the Pen Size we wanted.

Here are the notes in PDF. CDA-S7-Week_08-Paint.PDF

 

 

Martha

 

Bodgers – Finishing Our Game

Hi again everyone.

This week we put the final touches to our game.

uwin

We added some code to increase the speed of the alien sprite as the score increased to make the game a little more difficult.

We then added some code to control what happens when the game is over.

You can find our code on Dropbox here: https://www.dropbox.com/sh/ccfaycpa1zluh8l/AAAA4dQH8EPNJicsQj7RwGgsa?dl=0

Next week we will do a quick recap of this game and then we will start looking at hardware on the Raspberry Pi.

See you all then.

Declan, Dave and Alaidh.

Advancers – Calculater

Introduction

Todays project is a Calculator that will be able to do simple addition, subtraction, multiplication and division.

There will be a Sprite for each number button and for each type of sum, plus an equal and a clear button, so lots of Sprites. The finished Calculator might look something like this:

CalculatorFull

The Plan

As always, it’s a good idea to have a think about what Sprites, Variables and Code you might need, having a think about the Calculator, we came up with the following list:

  • Sprites
    • 1 Sprite for each number button and one for the decimal point, so 11 in total.
    • 1 Sprite for each of the sum buttons, +, -, X and / so 4 in total.
    • 1 Sprite for the equals button.
    • 1 Sprite for the clear button.
  • Variables
    • 2 Variables, one for each number in the sum.
    • 1 Variable for the sum type.
    • 1 Variable for the full sum being calculated.
    • 1 Variable for the answer.
    • 1 Variable to indicate which number variable we should use.
  • Code
    • Code for a number buttons.
    • Code for the sum type buttons.
    • Code for the equal button.
    • Code for clear button. 

We also thought that it would be a good idea to complete only 1 number button and 1 sum type button and make sure that was all working before adding the rest of the buttons.

The Variables

We created all the variables we would need first:

Variables 

  • Variables
    • NumberOne – this is for the first number in the sum
    • NumberTwo – this is for the second number in the sum
    • Flag – this is to indicate which number we should be using when a button is pushed.
    • Operator – this is to indicate what sum, + – X or / we should be doing.
    • Question – this is to hold the complete sum, e.g. 10+23
    • Answer – this is to hold the answer, e.g 33

The First 3 Sprites

To get things started we created a number Sprite, a plus (+) Sprite and an equal Sprite

All the Sprites are very simple, just a square with text in the middle, just remember to make sure that there is a background colour as well, so the When Clicked code will work correctly.

The code for the Number Sprite looks like this:

NumberCode

The code will check the Flag variable and then add 1 to either the NumberOne or NumberTwo variable, it will also add 1 to the Question variable.

Note that the number 1 is added to whatever is already in the number or question variables.

 

The code for the + Sprite is very simple:

OperatrorCode

We just set the Flag to indicate that we should move on to NumberTwo, we set the Operator to + and finally we put the + in the Question as well.

 

 

The code for the equal Sprite again is quite simple as we only have one sum type.

EqualCode

We check the value of the Operator and if it is + we add the NumberOne and NumberTwo variables together and put the result in the Answer Variable.

 

The other Numbers and Sum types

Once we had the number one, the + and the equal Sprites working it was quite simple to copy and create the other number Sprites. The process was:

  • Right click on the Number One Sprite and Copy it.
  • Change the Costume of the Sprite to the next Number.
  • Change the code of the new Sprite to the next Number.

The bits of the code that we changed are circled in red here:

NumberCodeChanges

The other sum types we did the same way, copy the + Sprite and adjust the code circled in red:

OperatrorCodeChanges

As we added the different sum types we also had to add more code to the Equal Sprite, which ended up looking like this, where there is one IF for each sum type:

EqualCodeAll

The Clear Button

In order to do more sums we also added a clear button, again it is a simple Sprite with some text on it, the code looked like this:

Clear

This code was placed on the Stage, as we needed to run it when we clicked on the Green Flag as well as when we clicked on the Clear Sprite.

Notice that most of the variables start with nothing in them, so they are blank, it is only the Flag that needs to have 0 in it.

 

 

 

Notes

The project that we built is available on the Scratch Web Site:

User Name : cdadvancers1819
Password : advancers

Project : Class-Calculator

Remember, you can put your own projects up there as well if you want.

Advancers – Programming

Introduction

We used Scratch to build our own Programming Language

Scratch used different blocks for different commands, so we decided to write our own Programming Language that would then call the different blocks. This may sound strange, but what it means is that we can have a simple and generic Scratch Program that can run code written in a simple file.

The Plan

  • Describe how our language would work.
  • Create a List variable to hold all our commands.
  • Create a variable to hold the parameter value.
  • Write some test commands to the List variable.
  • Write some code to get the parameter from our commands.
  • Write some code to translate our commands to Scratch commands.

First job was to describe how our language would work with Scratch, we decided that our Programming Language would be able to Draw pictures using the Pen Down, Move, Turn and Pen Up controls.

So we needed 4 commands in our Language, we decided that all the commands would use the same format:

  • First Letter would indicate the command
  • Second Letter would be a colon “:”
  • The rest of the command would be the parameter to use with the corresponding Scratch command.

For example to Move the Sprite 10 steps we would use:

M:10

 To Turn the Sprite 90 degrees we would use

T:90

To put the Pen Up or Down we would use:

P:1 for Pen Down
P:0 for Pen Up

And then we wrote some test code to put some of these commands in to our list variable.

TestCommands

If you look closely you can see that the commands should draw a square, Pen down, Move 100, Turn 90 and so on until we have the square drawn.

 

 

 

This code was put under a When Green Flag temporarily for testing.

We then moved on to the code that would get the parameter value from the command, for example the command M:100 the Parameter is the 100 part. We used a Custom Block for this called P1. Which looked like this:

P1

We send in the full command (M:100 for example) and then we read each letter and if we are on the 3rd letter or more, we add the letter to the P1 Variable, this is similar to what we did for the Calculator numbers.

 

 

 

The last piece of the puzzle was to add some code to read every item in the List and process each command, again this was very similar to the Calculator where we have an IF block for each possible command. Something like this:

Play

 

We read all the items in the Program List and we check the first Letter, this will tell us what Scratch block that we need to use to run the code.

You can see for each item in the Program List we call the P1 block to get the Parameter value, which we then use in the Scratch Block.

 

 

 

 

This is what the project looks like when you run the Test Program:

FinalRun

Notes

The project that we built is available on the Scratch Web Site, note that I added a couple more commands Pen Colour and Pen Width as we may need these at some point.

User Name : cdadvancers1819
Password : advancers

Project : ClassVersionProgramming

Remember, you can put your own projects up there as well if you want.

Creators: Objects and Vectors!

This week in Creators we covered a few very important concepts which we will likely need to run over a few times until we get them solid!

What are Vectors?

First we looked into a concept called Vectors, in particular 2D Vectors.  We saw that at the most basic, a Vector is a simple way of holding an x and a y in one variable.  This is useful for keeping track of the position of an object as you only need to keep one variable e.g. “rocketPosition” rather than two “rocket_x, rocket_y”.

vector-add3

The other thing we talked about is how this X and Y can represent a change in a given direction – i.e. a vector with x=10 and y=5 can mean “change X by 10 and y by 5”.  This way it’s useful for ANYTHING that might be in a given direction – things like velocity and acceleration for example!

The other thing cool about the vector object in p5 is that it has a bunch of functions that allow you to add, subtract, etc them.  This would allow you to e.g. add a velocity vector to a position vector to come up with a new position vector!

This web page has some nice details on the maths behind vectors.

 

Position, Velocity and Acceleration

We saw that position, velocity and acceleration are really common uses of vectors.

Continue reading

Bodgers – Making a better game

Hello again everyone.

We continued working with Pygame Zero this week, we began by getting everyone up to date with where we were with the game. I forgot to mention we were following the tutorial at https://pygame-zero.readthedocs.io/en/stable/introduction.html. We then changed the screen size and added a score to make our game more fun.

Capture6

Next week we will add some elements to make our game more difficult and even more fun.

I don’t have any slides this week but the code for both versions of the game are available here: https://www.dropbox.com/sh/ccfaycpa1zluh8l/AAAA4dQH8EPNJicsQj7RwGgsa?dl=0

See you all next week.

Declan, dave and Alaidh.

 

Week 7 2018 Explorers – How fast can you type?

Hi everyone,

Thank you all for coming on Saturday.  A lot of us had to fit into the Advancers Room but we managed. We should be back to our own room next. Thanks to Oliver and his crew for moving to another room for us.

This week we did a new game, How fast can you Type? This week we used Backgrounds as Sprites. Just to mix it up!

We used a variable as our Timer, as we did with our Maths Guessing Game!

Full notes from today are here in PDF CDA-S7-Week 7-How fast can you Type.pdf

And my own game from today is up on the scratch.mit.edu website.

See you all next week.

Martha

Julie and Ruaidhrí

Bouncing around in Javascript

This week we looked at animations, and how to make objects move in p5.js.

We covered:

  • How to animate things in p5
  • Some mouse interaction

Animation in javascript (or all programming really!) is basically changing some variables in the draw function before we actually draw the object.  If we change each variable by a little bit, it looks like smooth movements, just like a cartoon!

To save some typing, there is a video below with a quick overview of what we did:

Okay, it’s pretty simple stuff and not exactly the most exciting animation in the world, but you guys did some playing around and came up with several interesting variations and now we know how to do it, the sky is the absolute limit on what we can build  🙂 !

As usual, the code is up on the github to be pulled down and played with or changed to your heart’s content!

 

Bodgers – Making With Pygame Zero

logo

Hello again everyone.

This week in the Bodgers group we started working with Pygame Zero. Pygame Zero allows us to write our own games quickly and easily by doing a lot of the work involved in setting up and running a game in the background. This allows us to focus on the more creative aspects of the game.

You will have to install Python and Pygame Zero if you’re going to use Pygame Zero at home, details on how to do this are in my slides. A few of us had installation problems on Saturday, so don’t worry if you have issues we will help sort it out when we return after the break.

We followed the first few parts of this tutorial: https://pygame-zero.readthedocs.io/en/stable/introduction.html. I gave everyone a folder with images and sounds for our game which you can find here: https://www.dropbox.com/sh/3q14pg3huev4pwb/AADjDuB0FBVZXM4ChqN8qRx2a?dl=0. Copy this folder on to your own computer and you’re ready to go.

Here are my slides from Saturday: day 5

See you all on the 10th of November.

Declan, Dave and Alaidh