Off on my holidays...
/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...
Rob Miles on the web. Also available in Real Life (tm)
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.
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
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.
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.
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.
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.
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.
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.
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.