Office Lens is awesome

office lens.PNG

I had a need to scan a document today. Nothing too tricky about that, except that it meant finding the scanner, turning it on, running a program, etc etc. 

Too much like work. 

Then I remembered I had Office Lens on my phone. It's awesome. Point the camera at a page of text and it works out where the edges are, takes a picture, tidies it up and then offers to share it just about anywhere, including on my One Drive disk as a pdf file.

If you've not got this on your phone you're missing out. 

Not for sale

36219656392_f10ac27d5f_z.jpg

I keep getting emails from people who like my blog and want to put some sponsored content it. I've been offered up to 35 dollars for a slot (assuming these things are for real)

Go me. 

However, at the moment I'm afraid that space on these hallowed pages is not for sale. I don't really want to turn my blog into a profit centre. I write the posts manly for my own amusement. At least, I'm the only one that laughs at most of the jokes. 

Monday Snaps are going to be on holiday over the next couple of weeks while I write about Python. 

Traction Engines at Whitby

Gentlemen, start your engines....

Gentlemen, start your engines....

Expect to find a lot of pictures of traction engines and cars appearing in my blog over the next few days. Today we went to the Whitby Traction Engine Rally. It was awesome. There were traction engines, classic cars, funfair rides and stalls selling spanners.

Spanners

Spanners

The weather was kind to us (it only rained once for a bit) and a good time was had by all. I took my camera with some ancient lenses and took some pictures I'm really quite happy with. 

36219658872_da1019e527_z.jpg

Monday Snaps: Cheese Physics

Last week we got the cheese moving around the screen using the cursor keys. It wasn't very good. The cheese just moved as long as you held the key down. This kind of movement is fine for some kinds of game where the action is fast and frantic, for example the paddle in a breakout game. So, feel free to steal that movement code for any of your game object that need immediate movement.

However, for Cheese Lander the skill is actually in controlling the speed of the cheese. And one way to do this is to add a bit of physics. To understand what we are going to do, we have to understand a bit about speed and acceleration.

Speed is the rate of change of my position. Each time round the game loop I could add a speed of 1 pixel to my cheese. After sixty times round the game loop my cheese would have moved sixty pixels. 

Acceleration is the rate of change of the speed. Each time round my game loop I could add an acceleration of 0.1 to my speed value. So after ten ticks the cheese would be moving at the rate of 1 pixel per game loop. After ten more ticks the cheese would be moving at a rate of two pixels per game loop, and so on. 

The game needs to store the acceleration and velocity values as real numbers this time, because the acceleration value will be quite small.

double cheeseXSpeed = 0;
double cheeseYSpeed = 0;

double cheeseXAccel = 0.01;
double cheeseYAccel = 0.01;

The initial value of the speed will be zero because the cheese is not moving. The acceleration value that you see above works quite well with a game updating 60 times a second.  

void updateCheese()
{
    cheese.Left += cheeseXSpeed;
    cheese.Top += cheeseYSpeed;

    if (SnapsEngine.GetRightGamepad())
        cheeseXSpeed += cheeseXAccel;

    if (SnapsEngine.GetLeftGamepad())
        cheeseXSpeed -= cheeseXAccel;

    if (SnapsEngine.GetDownGamepad())
        cheeseYSpeed += cheeseYAccel;

    if (SnapsEngine.GetUpGamepad())
        cheeseYSpeed -= cheeseYAccel;
}

This is the part of the updateCheese method that implements our physics. The first thing it does is update the position of the cheese by adding the speed of the cheese to its position. Then it reads the gamepad to determine if the speed needs to be changed in any particular direction. This code is very similar to the code in the previous version of the game, but instead the speed values are updated, not the position of the cheese.  Pressing a key in a particular direction causes it to accelerate in that direction. 

The final refinement is to make the cheese "bounce" when it hits the edge of the screen. In the previous version of the game we "clamped" the cheese so that it could not move off the edges. In this version we are going to reverse the speed of the cheese when it hits an edge, giving a great "bounce" effect.

if (cheese.Left < 0)
{
    cheese.Left = 0;
    cheeseXSpeed *= -1;
}

if (cheese.Right > (SnapsEngine.GameViewportWidth))
{
    cheese.Right = SnapsEngine.GameViewportWidth;
    cheeseXSpeed *= -1;
}

if (cheese.Top < 0)
{
    cheese.Top = 0;
    cheeseYSpeed *= -1;
}

if (cheese.Bottom > SnapsEngine.GameViewportHeight)
{
    cheese.Bottom = SnapsEngine.GameViewportHeight;
    cheeseYSpeed *= -1;
}

This is the same code that we saw last week, with the one change that the speed value is reversed after the cheese has been put back on the screen.

This code is great for user controlled physics based objects. It's also great for chasing aliens who can be made to accelerate in the direction of the player. 

Next week we'll take a look at the game win condition, where we have to touch the cheese down on the bread really, really, gently.

Remember that the Monday Snaps are brought to you by my book.....

 

 

Begin to Code Python Snaps

Creating pretty menu screens, Snaps style

Creating pretty menu screens, Snaps style

As you might know, I'm working on Begin to Code Python. You can order a copy below. It will be out once I've finished writing it....

When I wrote the Begin to Code with C# book (which you can buy now - see below) I wrote a library of functions I called Snaps. The idea was to use these to make it easy for people to create impressive applications right from the start. Snaps for C# became an enormous library that you can find on GitHub here. I'm using it for my Monday Snaps which you can read each, er, Monday. 

Anyhoo, when I started the Python book I wondered about writing a Snaps library for Python. I've always been concerned that people might think that they are getting a book about Snaps, not programming, and so I wasn't sure whether another library would be a good idea. And the libraries do take a while to build. 

To cut a long story short, I've decided to make some Snaps for Python. They're much more lightweight than the ones I wrote for C#. They're built on the pygame framework so that I can get some nice graphical and audio elements with minimal effort. I've put the first version of Python Snaps, along with all the sample programs for the first five chapter's worth of examples, on GitHub here.

I must admit I'm really (and I mean really) enjoying writing Python at the moment. As a language that lets you go quickly from idea to implementation I think it is very hard to beat. It requires a different approach to programming from a language like C#.  but that's not a bad thing. 

Amazon Echo in Hull

Our Amazon Echo works really well. Except sometimes. The radio service, on TuneIn, frequently stops or breaks up.

If we ask again for the station it plays again for a while and then stops. It used to do this a lot a while back, but it seemed to have settled down.

I'm not sure if it is the WiFi in the house or the networking in Hull. Anyone else in Hull with an Echo had a problem with radio playback?

Baby Driver is a great film

Baby Driver is a great film. Perhaps a bit more driving would have been nice, but not really necessary. It has shades of Reservoir Dogs, Cape Fear and Hot Fuzz. All in a good way. Snappy direction, driving music and even a happy ending (spoiler alert - too late...). 

We managed to track down a screening last week. It might be a bit harder to find now, but it is well worth seeking out. 

Monday Snaps: Steering the Cheese

Welcome to this week's Monday Snap. We're re-creating the game Cheese Lander using the Snaps game framework. You can find earlier episodes here. Last week we put the bread and the cheese at their start positions. This week we're going to get the cheese moving. 

Games work by repeatedly updating the game engine and then re-drawing the display. In a Snaps game we use a C# loop to do this:

void gameLoop()
{
    while (true)
    {
        SnapsEngine.DrawGamePage();
    }
}

At the moment the gameLoop method just repeatedly draws the game page. The DrawGamePage method also pauses the loop so that it runs at the selected frame rate, which for our game is 60Hz. I'm going to add a call of a method to update the cheese position.

void gameLoop()
{
    while (true)
    {
        updateCheese();
        SnapsEngine.DrawGamePage();
    }
}

The cheese is controlled by the player. The idea is to land it on the bread. This is my first version of the updateCheese method.

int cheeseXSpeed = 2;
int cheeseYSpeed = 2;

void updateCheese()
{
    if (SnapsEngine.GetRightGamepad())
        cheese.Left += cheeseXSpeed;
    if (SnapsEngine.GetLeftGamepad())
        cheese.Left -= cheeseXSpeed;

    if (SnapsEngine.GetDownGamepad())
        cheese.Top += cheeseYSpeed;
    if (SnapsEngine.GetUpGamepad())
        cheese.Top -= cheeseYSpeed;
}

The SnapsEngine exposes methods that  program can use to test the state of the gamepad.  You can use the cursor keys on the keypad, a connected Xbox 360/Xbox 1 controller. Alternatively you can use the on-screen touchpad with a mouse, lightpen or finger. If any of the methods return true a speed value is used to update the position of the cheese in that axis. Remember that the Y axis goes down the page. Increasing the Y value of the cheese position will move it down the screen. 

This method lets the player move the cheese right off the screen, so perhaps we should fix that. 

if (cheese.Left < 0)
    cheese.Left = 0;
if (cheese.Right > (SnapsEngine.GameViewportWidth))
    cheese.Right = SnapsEngine.GameViewportWidth;

if (cheese.Top < 0)
    cheese.Top = 0;
if (cheese.Bottom > SnapsEngine.GameViewportHeight)
    cheese.
Bottom = SnapsEngine.GameViewportHeight;

These statements "clamp" the cheese movement so that it can't move off the screen. Add them to the updateCheese method after you have updated the cheese position.

You can now steer the cheese around the screen and land it on the bread. Unfortunately this is far too easy. So next week we'll put on our scientists white coats and add some Physics. 

And remember, the Monday Snaps are brought to you by Begin to Code With C#, available from all good booksellers. 

Happy Birthday Me

I'm now officially and properly old. Bus passes beckon. Thank heavens I've still got my youthful good looks (although I've forgotten where I put them).

However, I've just had the most fantastic of birthdays, starting with a trip out for coffee in the morning and then a slap up Sunday Lunch at 1884 Dock Street Kitchen.  They do a roast beef that is just perfect (pro-tip, have the sausage roll snacks as starters, lovely). The meal was a surprise treat, and a great time was had by all. Particularly as a whole bunch of family members turned up, some of whom I wasn't expecting. 

So, we headed home after the meal and I reflected what a great day I'd had. And then it started all over again. The family, who's reputation for subterfuge has gone up several levels, had arranged to fill our house full of friends to do the surprise party thing, even down to the hiding of cars in distant car parks and stealthy arrangement of shoes and coats so that the big reveal was just that.  I had a great time, and we even ordered Domino's Pizza for tea. 

Thanks so much to everyone who attended. We played some games, I blew out some candles, cake was eaten and a wonderful time was had. If this is what birthdays are like when you're sixty, sign me up. 

Tons of Culture in Hull

Oh to be in Hull in the summer time. This summer is astonishing in terms of the range and quantity of goings-on in the city. We wandered up town on Saturday for lunch at Nibble (wonderful place, you should try it) and found ourselves listening to a BBC Prom being broadcast from the stage right next door. Full orchestra action. The city was also alive with a whole bunch of folk acts around the town, numerous Morris Dancers and a Gay Pride march. 

Blimey.

Splatoon 2 is wonderful

Of course I went out and got Splatoon 2 today. Very good game. I enjoyed the first one on the Wii U, and this one keeps up the standard, while adding some great new touches. We've been playing it on full screen TV and it looks lovely. The controls take a bit of getting used to, what with tipping the controller to aim, but I'm getting the hang of it slowly but surely. The single player campaign is fun, there's a new thing called Salmon Run, where a bunch of you collaborate to collect eggs while under attack from a variety of strange and nasty beasts. 

If you have a switch you should get this game.