Peel on Sunday
/Peel in the Isle of Man is lovely. We went there for an ice-cream. You should to.
Rob Miles on the web. Also available in Real Life (tm)
Peel in the Isle of Man is lovely. We went there for an ice-cream. You should to.
So, today we went to the Isle of Man Royal Manx Show. Wonderful. Rather like the Traction Engine rally of last week, but with more cows. We didn't expect to stay all day, but a combination of good weather and plenty of things to see took us all the way to the Grand Parade at the end. They had dog agility, pony club express, bright blue sheep (and a Bo Peep to go with them). They probably had a kitchen sink somewhere too. And very probably it was beautifully decorated.
One of the highlights was the Stampede Stunt Company. They did a fantastic routine showing us the "Way of the Cossack Warrior". Which apparently is all about the Dzhigits of the Cossack people. The pronunciation of which for some reason had me thinking of this video. Anyhoo, they were awesome. Of course I had a camera with me. Of course I took some pictures.
After a lovely evening yesterday the weather has turned, well, less nice. So we went off to the Isle of Man Motor Museum to look at cars. There are a lot of awesome cars there. They have a particularly nice selection of large american gas guzzlers with lovely chrome detailing.
I took quite a few pictures and one or two came out. If you ever find yourself on the Isle of Man, you should check out the museum. If you're driving an electric car (I wasn't) you'll be in for very pleasant surprise. They have a row of shiny chargers there for you to top up.
Of on my holidays today. By boat. This is the view from the ferry.
This is the view as we docked.
Red vs. blue..... I think were going to like it here...
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.
In the good old days, which I can remember more and more of these days, a man used to come round to our house and read the meter.
Today, it seems I have to do this myself. I don't mind doing this, but I do mind getting repeated email reminders to go and do it. It's as if they think I work for them.
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.
Oh joy. You can now write Python in Visual Studio 2017. Just install the updates and then you can add it as a language. There's a nice set of web pages that describe how to get started here.
I've had a play and it seems to work quite well.
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.
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.
It seems to me that the only thing I'm getting better at as I grow older is snapping my fingers. Nothing much ever happens when I do though.
Another lovely evening at c4di talking hardware, Visual Studio, how to build a brand and lots more besides.
The only bad news was that Rob is heading for Coventry. Their gain, our loss. Have a great time down there you two, and feel free to come visit any time you like.
The next meeting of CodePen Hull is at 6:00 pm on August 14th at the c4di. I'm not speaking at this one, but I really want to go along to listen to everyone else.
Developers in the Hull area are very welcome to come along too. Sign up here
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.....
Â
Â
The orchids in the kitchen seem to be doing quite well.
Just typed this into a Python class. I think it's time to stop for the day....
Â
Â
Went out to the pub on Wednesday night. I took the camera. As you do. The light was quite good and I grabbed some pictures of Cottingham Church.
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.
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. 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.
Rob Miles is technology author and educator who spent many years as a lecturer in Computer Science at the University of Hull. He is also a Microsoft Developer Technologies MVP. He is into technology, teaching and photography. He is the author of the World Famous C# Yellow Book and almost as handsome as he thinks he is.
Begin to Code with JavaScript is now available for purchase and download. You can find it here