Congratulations to our Ninjas at Coolest Projects 2019

Congratulations to everybody from CoderDojo Athenry who participated in the CoderDojo Coolest Projects International in the RDS Dublin on 04 May 2019.

We had three projects which all sparked a lot of interest with the public at the event. Adam presented his game “The MegaMaker”, David and Michael presented “FidoFinder” and “Go With The Flow” was presented by Mark.

 

Special congratulations to Adam who was runner up in the Games category and the Go With The Flow team represented by Mark who were runners up in the Hardware category.

 

Creators – Quiz and Hacking

Screenshot 2019-05-02 at 00.23.50.png

This week we had a quiz. There were three rounds on Technology, Creators 2019 and Pop Culture. There was a very high proportion of correct answers on all questions. The quizes can be found here, for anyone that wants them:

Creators 2019

Pop Culture

Technology

 

After that we set everyone a programming challenge: make an animated scene. People got busy and there was some good progress. We will continue with that next week. Mark and I (Kieran) got in on the action figuring out how to draw clouds. My attempt is shown in the image at the top of this post. The code can be found, as always, on the CoderDojo Athenry Creators 2018 GitHub.

Explorers Week 10 – Scrolling Backgrounds

Hi everyone

Thank you to everyone who came on Saturday.

We did scrolling backgrounds and this is very useful in any type of game and can add an extra dimension to your game whether its a driving game or a flying game.

We were scrolling horizontally so we were using the xpos but remember you can just as easily scrolling vertically by just using the ypos

Here are the notes in PDF form

CDA-S8 Week_10-scrollingbackgrounds.pdf

 

Enjoy the long weekend and we will see you all the week after.

Martha

Julie, Eoin and Ruaidhrí

Bodgers – Cool Projects

Hello again everyone.

In the Bodgers group we’re starting to put our projects together for the Coolest Projects Showcase.

“Coolest Projects International is a world-leading showcase for young innovators who make stuff with technology. If you’re up to 18 and you’re making something with technology for fun, to solve a problem, or as a creative outlet, then we want you to come out and share your project with us! This free event will take place in the RDS Main Hall, Dublin, Ireland on 5 May 2019.”

Find out more here: https://coolestprojects.org/

If you have any questions you can contact me at coderdojoathenry@gmail.com.

Don’t forget we’re off for the next 2 weeks, we’re back on 27-Apr-19.

see you all then.

Declan, Dave and Alaidh

Creators: Drumtown!

Today in Creators we played a bit more with sound and built a type of musical instrument using Javascript.  The project was called “Drum Town” because it was based on the idea of a music mad building and when you wake up one of the resident’s by clicking their window, they would play a particular sound every time some traffic cruised past.  Each floor consists of people with the same instrument.  What else would they do?

Play the finished Project by clicking here! – Make sure to TURN UP THE SOUND!!

drumtown

How did we build it?

The awesome thing at this stage is that the group has become so competent at javascript that as soon as we had the idea, some people put their heads down and started building without a whole lot of direction!!  I won’t go into the ins and outs here, but the code is up on our repository and you can go through it!

Interesting bits!

Some of the interesting bits of the project are:

  1. Classes:
    As usual we needed a few classes – this time we used classes for the Car and the Window.  The basic idea was to have a car moving at a constant speed left to right and to have windows that play a sound whenever the car goes past.
  2. Unicode Sprite Characters!
    We learned that now text is getting more and more graphical – we can see it on our phones with emoticons.  There are a large amount of emoticons in standard fonts and if you enable the windows keyboard (right-click taskbar and choose “Show Keyboard” you get on onscreen keyboard that can type all sorts of characters – we used these for our cars:  and could write crazy looking code like:  this.carList= [🚗, 🚚, 🚛, 🚕, 🚜]; .  This will make it REALLY easy for us to write games with nice looking costumes without messing with images.
  3. Sounds:
    I handed out some sounds for us but you can put whatever sounds you like in your own version.  I got my sounds from this website here which has TONS of free instrument sounds!  We named the sounds 0-6.wav to make it easier to use loops to reference them.

That’s it!  Take a read through the code, I finished it off a little before pushing (mainly added a title).  It would be great to make your own version with a different them and a different set of sounds perhaps.  Also – maybe this can give you ideas for other types of musical instrument that you can create, perhaps with a completely different model. Have fun with the emoticons too 📯🎷🎺🎸🎻!

Bodgers – RFM69 Radio Modules

 

DSC00227

Hello again everyone.

This week we looked at the Adafruit RFM69HCW Radio Module, these modules allow us to send messages between Arduinos without using Wifi or Bluetooth.

Adafruit have a tutorial here on setting up the module. The basic steps are:

  1. Solder on the header pins.
  2. Solder antenna or wire cut to the the proper length for the module/frequency
    • as our frequency is 433 MHz  we cut the wire to 16.5 cm.
  3. Wire up modules to your Arduinos
  4. Download the RadioHead library to your Arduino IDE.
  5. Load the RadioHead69_RawDemo_TX code from this library to the Arduino you’re using to transmit.
  6. Load the RadioHead69_RawDemo_RX code from this library to the Arduino you’re using to receive.
  7. Test

Next Saturday we will be putting all of the different components from our projects together and testing out how they work.

see you all then.

Declan, Dave and Alaidh

Creators – Flying Over Dynamic Terrain

 

This week we creating a game where a tiny plane flies over dynamically generated terrain picking up as many boxes as possible. The player scores a point for every box, but that also makes the plane fly faster, making the game more challenging.

Perlin Noise

Normal random-number generators produce values that jump around all over the place. Perlin noise is different. It is also random, but it varies smoothly. This makes it great for mimicking the sort of randomness we see in nature.

1D Perlin Noise Landscape

Our smooth and changing landscape is generated using a one-dimensional Perlin noise value generated by the P5.js function noise(xoff).

We start with a loop that goes across from 0 -> width across the screen. We’re looking to generate a set of [xy] points that define our shape.

We use these values:

  1. xstart: A starting value for xoff
  2. xinc: An amount to increment xoff by for every new location
  3. ymin: The smallest y value we want for our landscape – something a little below the top of the screen
  4. ymax: The largest y value we want for our landscape – something a little above the bottom of the screen

Each call to noise() generates a single value in the range 0-1. We use the P5.js function map() to change this value in the range 0-1 into a value in the range ymin-ymax.

Changing the size of xinc controls how choppy or smooth the landscape is. We tune it to a value that gives approximately two peaks and two valleys across the screen, and looks right for our game.

Moving the Landscape

Moving the landscape is achieved by changing the starting value of xoff (aka. xstart) each time we update the screen. By making it a little larger each time, the effect is that the landscape seems to scroll from right to left.

Other Parts of the Game

The other parts of the game are very standard. We define a simple plane shape (drawn using rect() calls)  that can move up or down in response to the arrow keys.

We define “cargo” containers that are randomly generated on the surface of the landscape and move right-to-left at the same speed.

The cargo containers have an active property that is false if they move beyond the left-edge of the screen or get sufficiently close to the plane to be “picked up”.

We added a function to the landscape class (Ground.js) that checks for a given [x, y] location to see if that point us under the ground by checking what the height of the landscape is at that x value. If the plane is below the ground we consider it crashed.

We added a simple scoring mechanism that tracks how many boxes were collected and makes the plane move faster (really – the ground scroll faster) every time a box is collected.

Download

The files for this week can be found on our GitHub repository.

Bodgers – Texts & Emails

This week we looked at sending texts and emails from our python scripts.

To send text messages you will need to set up an account on Twilio which is a platform that allows coders to make and receive phone calls, send and receive text messages from their programmes. You then install the Twilio python library which will allow us to send texts from our script using code like this.


# Download the helper library from https://www.twilio.com/docs/python/install
from twilio.rest import Client

# Your Account Sid and Auth Token from twilio.com/console
# DANGER! This is insecure. See http://twil.io/secure
account_sid = 'your account_sid'
auth_token = 'your auth_token'
client = Client(account_sid, auth_token)

message = client.messages \
                .create(
                     body="Hello Bodgers",
                     from_='+440123456789',
                     to='+353123456789'
                 )

print(message.sid)

To send an email we use smtplib which is an email library that’s built into python and which works well with Gmail. We need to change our Gmail setting to allow insecure apps and then we can use the code below to send our message.


import smtplib

server = smtplib.SMTP('smtp.gmail.com', 485)
server.starttls()
server.login("my.email@email.com", "myPassword")

msg = "Hello World"
server.sendmail("my.email@email.com", "some.email@email.com", msg)
server.quit()

See you all on Saturday

Declan, Dave and Alaidh

Creators: Autonomous Agents!

This week in Creators we did a very fun project – we learned how to simulate creatures with a kind of basic artificial intelligence and their own hopes, dreams and aspirations!  We made an app where a bunch of creatures desired to spell the word “Creators” and were also scared of the mouse.

Click on the image below to play with our completed animation.

creature-steering

All the code is on the creators github as usual! Pretty cool eh?  How did we get it working?

The evolution of Consciousness
At the start we chatted about an interesting channel on youtube called Kurzgesagt which contains short videos on all sorts of interesting topics.  A recent video I watched discussed the notion of consciousness and how it might have evolved and it inspired the project.  Though a lot is speculation about this topic, the video made a reasonable argument that consciousness evolved as a survival tool to allow simple creatures to seek energy (food) and flee from creatures that wanted to eat them.  Watch the video, it’s very good!

Though we aren’t quite at the stage where we are ready to code up conscious beings – it was interesting to think about how we might add needs and desires to a character, so that’s what we looked at!

Reynold’s Steering Behaviours for Autonomous Characters
Having decided that we wanted some creatures that moved to the beat of their own drum, we next needed to figure out how to implement it.  There are LOTS of pretty complicated strategies for simulating intelligence, but we looked at a brilliant research paper published in 1999 by a playstation programmer called Craig Reynolds called Steering Behaviours for Autonomous characters – read the full paper here.  In this paper, Reynolds describes a simple but fantastic way to model “autonomous” characters using forces.

steering2

An “Autonomous” character is one that controls or powers itself – i.e. there is no remote control here! There is a lot in Reynolds paper but the basic idea is to think of some “behaviours” that a creature might exhibit – these could be:

  • Flee: perhaps the creature might want to escape from someone?
  • Seek: perhaps the creature might want to get somewhere really quickly?
  • Arrive: perhaps a creature might want to get somewhere and stay there (i.e. slow down to “arrive” there.
  • Be close to other creatures: perhaps a creature might want to be close to creatures like them
  • etc – basically anything you can think of nearly!

In Reynold’s paper, creatures generally have a limited vision, and can have more than one behaviour happening at once – i.e. I really want to get food, but want to avoid the predator in the way.

The simple but powerful that Reynolds came up with is the idea of using forces to describe these behaviours and letting newton sort it out.  To model a Reynolds behaviour, you:

  1. Determine your DESIRED velocity for this behaviour – this is a force describing how badly you want to escape the predator, or pursue the target, or avoid the obstacle, etc
  2. You STEERING force vector is worked out as:

steering = desired – velocity

With this simple looking formula, and behaviour rules you combine, you can create some great behaviours that can seem to have realistic looking intelligence behind them.

The Code
Because Reynolds uses force, we had an object which could be a good starting point developed way back in Week 8 – our fun with forces model was a perfect starting point since we already had a “Mover” object that had an applyForce function to allow you to add a force to it.

seek-fleeOur movers “seek” home and “flee” the mouse

All we needed to do was to add some “personality” to our Mover so that it decided itself where it wanted to move to.  These are called “behaviours” in Reynolds brilliant paper.  We decided that our first Mover would have a “timid, homebird” personality and it would have two desires: to get home (some location that is dear to it!), and to stay away from the mouse.  We decided that when it is “afraid” of the mouse we should add something visual to let us know it was afraid – we coloured it red.

The first and easiest code to add was the code to make the Mover want to go home:

 goHome(){
    // i want to go home
    let desired = p5.Vector.sub(this.home, this.position);
    desired = desired.limit(this.maxSpeed);
    let steering = p5.Vector.sub(desired, this.velocity);
    this.applyForce(steering);
}
This is a good example of the process – first we create a Vector that describes where we want to go (home – location), next we limit it to the maximum speed of the Mover.  Next we use the magic formula of Steering = Desired – Velocity to find what the steering force should be.  (This looked okay for us, but in Reynold’s paper he recommended a maximum steering force so it doesn’t steer too quickly – good idea but we didn’t bother with it!).  We called this “goHome” but Reynolds calls this the “Seek” behaviour.
 flee(){
     // i am scared of the mouse
     let mousePosition = createVector(mouseX, mouseY);
     let desired = p5.Vector.sub(this.position, mousePosition);
     let dist = desired.mag();
     if(dist < 100){
         desired = desired.limit(this.maxSpeed);
         let steering = p5.Vector.sub(desired, this.velocity);
         this.applyForce(steering.mult(10));
         this.isAfraid=true;
     } else {
         this.isAfraid = false;
     }
}
The next steering behaviour was fear of the mouse.  We added this as per the above “flee” method.  We imagined that our little creatures can see the mouse when it’s 100 pixels away, and if it is, then it’s afraid and a very strong “flee” force is present.  In the show method we decided to show the fear by turning it red (we should have drawn e.g. a scared face or something).
Finally, we add a function which calls the behaviours in turn:
applyBehaviours(){
    this.flee();
    this.goHome();
}
In each draw loop instance, we call the applyBehaviours, just like we call the “move” method and the “show” one.
That’s it!  That’s all it took to give our creatures the desired behaviours!
Drawing a message:
The code to draw a message came from a hidden feature of the font class in p5 – the ability to get points from text with textToPoints.  This allowed us to get a bunch of points to set as home which spelled a message.   Depending on your computer, it could run a little slow so you might want to just add every 2nd points (takes a while to paint on my phone, but looks quite good on my laptop!).
function preload(){
    font = loadFont("fonts/AvenirNextLTW01-Medium.ttf");
}

function setup() {
    createCanvas(innerWidth, innerHeight);
    textFont(font);
    points = font.textToPoints("Creators", 100, height/2, 300);
    
    for(let i=0; i< points.length; i++){
        let startPosition=createVector(points[i].x, points[i].y);
        movers.push(new Mover(random(10,30), startPosition));
    }
}