Linux Format 263 (Sampler)

Page 1

EE FR

The top five tested: 1 SparkyLinux 2 Q4OS Trinity 3 Void Linux 4 Emmabuntüs 5 Feren OS Classic

0OOKS £5 EB

OF

BEST 32-BIT DISTROS!

PLUS!

HOW TO…

!

USE THE ARDUINO GET ONLINE PRIVACY SOLVE YOUR LINUX WOES

The #1 open source mag

, replace e r a w d r a r old h 2-bit Save you dows and keep 3 rnel dying Win with the Linux ke alive systems

FREE!

Worth £50 5 top bookazines Over 770 pages Linux Foundation

Dan Cauchy on how Linux will power a new generation of smart cars

A-MAZING!

Escape mazes with Go code

CLASSIC GAME CODING Recreate your own classic side-scrolling platformer

3.7GB

DOWNLOAD

Linux Mint DE 4 Bodhi 5.1 & antiX 19

pages of tutorials & features

60

Get organised with your own online Kanban board Encrypt all of your cloud data for secure backups Improve your video editing with OpenShot


Contents

NEW GIFT SUBSCRIBE NOW! Page 72

REVIEWS

AntiX 19

15

Jonni Bidwell is all for lightweight distro antics, but projects that make their initial letter lowercase are frowned upon at LXF Towers…

FuryBSD 12.1

16

As he attempts another BSD-based desktop, Mayank Sharma is as furious with himself for picking review candidates without first taking them for a spin.

Bodhi Linux 5.1

17

Although Mayank Sharma would have you believe that he’s a grown man and this is just a distro. But he can’t seem to wipe that grin off his (beautiful) mug.

Argon One for Pi 4 Les Pounder is trying to keep his cool, but another case and cooling solution for the Raspberry Pi 4 has him a little hot under the collar.

45

POWER UP YOUR OLD PCS Jonni Bidwell explores the open-source options for 32-bit users on page 26. ROUNDUP

32-bit distributions The number of distributions targeting 32-bit machines is rapidly shrinking. If you need one, Shashank Sharma has some interesting recommendations.

4     LXF263 June 2020

INTERVIEW

18

Tux Racer!

34

Dan Cauchy brings Jonni Bidwell fully up to speed on Automotive Grade Linux, coming soon to a car – or even a (narrow) boat – near you!

www.linuxformat.com


CONTENTS

£50

Pi USER Raspberry Pi news

OF FREE EBOOKS!

44

LOCKDOWN! The Pi Foundation outlines how it’s dealing with events and its store now that Covid-19 is here.

Argon One for Pi 4

Your free ebooks

45

Les Pounder is trying to keep his cool, but another case and cooling solution for the Raspberry Pi 4 has him a little hot under the collar.

If This Then That…

TUTORIALS

46

Les Pounder shows us how to use webhooks to trigger online services to communicate with one another and fire off Telegram messages.

Arduino for Pi users

TERMINAL: Extending Vim

48

WEKAN: Kanban boards

54

Nick Peers discovers how to implement Kanban boards to help get organised and speed up project management for personal or work purposes.

DUPLICATI: Secure cloud backups 64

CODING ACADEMY

Nick Peers reveals how to use your cloud backup storage as a watertight back-up location for your key data by wrapping it all up in encryption.

74

Armchair arcade warrior Calvin Robinson guides us through creating a side-scrolling platform game in Python. Are you ready, Player One?

Solving mazes

52

Being quite versatile himself, its no wonder Shashank Sharma has such fondness for the highly extensible Vim and he’s going to make it even better!

Get used to the Arduino series of boards with the help of Les Pounder and the Raspberry Pi, and build better projects.

Coding a platformer

9

Claim your free five ebooks and discover how you can get your digital download and what the heck to do with an ISO file!

OPENSHOT: Video editing

68

Some chap called Nick Peers is getting his whole family involved in creating knock-off Harry Potter videos. We hear J. K. Rowling don’t like that sort of thing.

78

The a-mazing Mihalis Tsoukalos reveals how graph algorithms and backtracking can be used to quickly provide a solution to a maze.

REGULARS AT A GLANCE News

6

Back issues

24

In your new and exciting Covid-19 reduced news section we’re looking at Zoom insecurities and how open source is better, Razer backlighting, Tux in Windows and UBports is on the PinePhone.

They’re selling out fast!

Your free ebooks

Alexander Tolstoy hasn’t got time to go socialising, he doesn’t want to leave his house or his family – he’s far too busy getting close up and personal, rubbing up to the finest open source software like: MyPaint, Fontpreview, VokoscreenNG, APK Editor Studio, G’MIC, Strawberry, XanMod, Regards, Nmap, GZDoom and Typer.

Mailserver

9 10

We try and help out buying or building a new Linux packing PC, the Archive rises its ugly head, we remember we’re on Zinio and try and help escaping Apple, but fail.

Answers Get to grips with Systemd services, how to update all the Raspberry Pis, testing microSD cards and smart TV streaming.

www.techradar.com/pro/linux

12

5 for 5 subscriptions

25

We’ve got a Covid-19 special offer!

HotPicks

58

Subscriptions

72

Next month?

98

IN-DEPTH Unpeeling Tor

40

Neil Mohr unpeels himself from his sofa and heaves his ever-growing bum up after weeks of isolation to explore how Tor keeps your web browsing private and secure.

June 2020 LXF263     5


ANSWERS

Answers

Got a burning question about open source or the kernel? Whatever your level, email it to lxf.answers@futurenet.com or stopped Q Disabled I noticed that on my laptop

running Fedora 31 under Xfce, Bluetooth is automatically activated upon starting up. I looked around for a way to disable it by default, but frankly the terminal’s output when checking whether the Bluetooth service is still running puzzles me. It tells me the service is still active, see below the terminal output. Is this correct and to be expected? root@XFedora:~# systemctl disable bluetooth.service Removed /etc/systemd/system/ bluetooth.target.wants/bluetooth.service. Removed /etc/systemd/system/dbus-org. bluez.service. root@XFedora:~# systemctl status bluetooth.service bluetooth.service - Bluetooth service Loaded: loaded (/usr/lib/systemd/ system/bluetooth.service; disabled; vendor preset: enabled) Active: active (running) since Sun 202003-15 13:14:52 CET; 2h 53min ago

Jude Lee

A

Sometimes systemd’s use of English can be a little counterintuitive. You start and stop services using the start and stop commands for systemctl. The enable and disable options refer to what happens at boot, they do not affect the currently running instance. So $ systemctl stop bluetooth.service

Balena is excellent for maintaining a fleet of Raspberry Pis but it requires some initial setup work.

12     LXF263 June 2020

will stop the service, but it will be restarted at the next boot, while $ systemctl disable bluetooth.service

prevents it starting at next boot, but does not stop the running instance. To stop it and prevent it restarting, you need to issue both of the commands. However, this may not be enough to prevent a service from running, as systemctl units can have dependencies. So if foo.service contains Wants=bar.service

or Requires=bar.service

then starting foo will result in systemd trying to start bar as well, even if you have run systemctl disable bar. This is usually a good thing, as it means you only need to specifically set the service you need to start and the dependencies take care of starting anything they need, but there may be times you really don’t want a service to start. One way of dealing with this is to find which services want it and stop them. So if Bluetooth is still starting up, you can use $ systemctl list-dependencies --reverse bluetooth.service

to see what it asking for it. There is also a stronger, brute-force variant of disable, which is mask: $ systemctl mask bluetooth.service

This creates a unit file that is a symlink to /dev/null, making it impossible to start the service (unmask undoes this). This will certainly stop the service running, but use

Neil Bothwick self-isolating with a Pi and an SD card full of Linux tutorials.

it with caution as it could cause any services depending on this one to fail.

updates Q Bulk I am looking for a recommendation for automatically pushing updates/ upgrades to multiple Raspberry Pis. I’ve looked at Mender, Ansible, Balena, and UpSwift, but I am looking for a simple tool that will just push the updates and give me feedback if it was successful or not… maybe that part isn’t critical either. We (my company) are starting to use more and more of these devices for display boards and they work great for this purpose, and we are looking to possibly add over 200 more, so it would be really nice to have a good way to manage these without remoting in and issuing a sudo apt update && sudo apt upgrade -y

Tim Bauer

A

You mention some of the most useful tools already. Until recently I would have used Ansible for this, but I have lately been using Balena a lot and am very impressed. Expect a full tutorial on this once we’re Post Covid-19. All of these tools have the same issue – you are trading ease of initial setup against ease of use. Creating an Ansible playbook to update all of the devices at once takes some work, but running it is easy, provided you have SSH access to all of the devices at the time you run the playbook. Balena takes more work to set up, as you have to create the initial image for the application, unless you are using an existing one someone else has built. However, because of the way Balena manages its devices, once you have done that there is virtually nothing else to do. If you update the image, all of the devices will pull updates from the server with no interaction on your part. Similarly, adding devices is as simple as inserting a Balena SD card into the device, plugging it in and adding it to your application on the web interface. You don’t even need static IPs for the Pis as they will find the server themselves. Of course, if you are running

www.linuxformat.com


ROUNDUP 32-bit distros WE COMPARE TONS OF STUFF SO YOU DON’T HAVE TO!

Roundup Emmabuntüs Feren OS Q4OS SparkyLinux Void Linux

Shashank Sharma By day Shashank is a New Delhi trial lawyer, but by night he’s an open source vigilante!

32-bit Linux distros The number of distributions targeting 32-bit machines is rapidly shrinking. If you need one, Shashank Sharma has some interesting recommendations.

HOW WE TESTED… All distributions were tested on the same dual-core machine with 4GB RAM, and we’ve selected the latest stable releases for all the distros. The recommended RAM for these is much less, and they claim to be able to run on even much older hardware, so we expect them to be fairly responsive. We’re also going to rate the distributions on the installation process. A complicated process will automatically alienate new users, unless there’s plenty of documentation to guide users along, which is another key test. Just as important is software management and the kind of apps that are shipped with the distribution. Apart from these, the distribution also needs to be easy to use to be able to help you put the aging machines back into use. We also want the distribution to be customisable, to enable you to make changes and mould it to your taste. Like Void, Q4OS also has a text-based installer, but its on par in terms of friendliness with the graphical installer featured in the other distributions.

18     LXF263 June 2020

nlike muscle cars of the 1970s, which still remain popular and are quite the collector’s items, old computers from even a decade ago aren’t all that desirable. Part of the reason for this is the lack of computing power, which restricts what these machines can be used for. Another reason is the cost of providing support for them. This is why popular distributions such as Ubuntu no longer produce official install media for 32-bit systems and are looking to entirely drop support for 32-bit packages in the future. Despite the seemingly bleak outlook, there’s still hope for aging machines in the

U

form of the distributions featured here. Our list is by no means exhaustive, and there are several other distributions that are determined to help you keep your 32-bit machines working in the coming years. You’ll find a mention of some of these in our Also Consider section at the end of this Roundup. With the exception of high-performance gaming and other, similarly resource-intensive work, there’s little that these machines can’t do, thanks to the vast repositories of open source software. If nothing else, these machines can be the perfect test bed for new Linux users to learn the internals, without fear of breaking anything.

www.linuxformat.com


BACK ISSUES

BACK ISSUES

MISSED ONE?

ISSUE 262 May 2020

ISSUE 261 April 2020

ISSUE 260 March 2020

Product code:

Product code:

Product code:

In the magazine We show how to keep your Linux system safe, from protecting your data to rocksolid login solutions. There’s advice on how to construct an FM radio receiver, make the most of systemmonitoring tools, and a look back at over 20 long years of Linux Format!

In the magazine We take an in-depth look at virtualisation to ease our installing woes. We also explore the world of FreeBSD. Plus, learn how to use LibreOffice Calc for serious mathematical work, and how Zabbix can solve an enterprise’s monitoring needs.

In the magazine Sensing the coming of spring, we rouse ourselves from semi-hibernation with a feature full of glorious maker projects. We also look at firewalls, set beginner distros against each other, and show you how you can move from Evernote to Joplin.

DVD highlights Manjaro 19.0.1 (64-bit) and IPFire 2.25 Core 141 firewall distro (32- and 64-bit)

DVD highlights Solus 4.1 (64-bit), as well as OpenMandriva 4.1 (64-bit).

DVD highlights Mint 19.3 (64-bit), Elementary OS v5.1 (64-bit), and BlackArch 2020 (64-bit).

ISSUE 259 February 2020

ISSUE 258 January 2020

ISSUE 257 December 2019

Product code:

Product code:

In the magazine As Windows 7 reaches its end of life, we opportunistically swoop in to lead you to Linux’s desktop paradise. Plus, learn the best ways to back up everything, set up an audiobook streaming server, how to build a processor, and how to use Grafana.

In the magazine We venture into the murky realm of hacking, taking a look at some of the ways hackers operate, how to prevent it, and how to set up a hacking playground. Plus, we chart the rise of Blender, look at music notation software and building micro:bit walkie-talkies.

In the magazine Tired of a laptop that’s slow off the mark? Discover how to make Linux lighter and faster. Also, bring deleted files back to life, quickly edit videos, create great HDR photos with open source tools, and create smaller apps with React.

DVD highlights Pop!_OS 19.10 (64-bit), Rescatux 0.37 (32/64-bit) and Bodhi 5.0 Lite (32-bit).

DVD highlights Kali Light (64-bit), Fedora 31 (64-bit), and MX Linux 19 (32-bit).

DVD highlights Ubuntu 19.10 (64-bit) and NixOS 19.09 (32-bit).

LXFDB0262

LXFDB0261

LXFDB0259

LXFDB0258

LXFDB0260

SOLD OU T!

Product code:

LXFDB0257

SOLD OU T!

To order, visit myfavouritemagazines.co.uk Select Tech from the tabs of magazine categories, then select Linux Format. Or call the back issues hotline on 0344 848 2852 or +44 344 848 2852 for overseas orders.

Quote the issue code shown above and have your credit or debit card details ready 24     LXF263 June 2020

www.linuxformat.com


*

BIG SAVINGS ON OUR BEST-SELLING MAGAZINES SAVE

93%

SAVE

93%

SAVE

92%

SAVE

92%

SAVE

88%

SAVE

92%

For great savings on our best-selling magazines, visit online

myfavouritemagazines.co.uk/spring Order Hotline 0344 848 2852

* TERMS AND CONDITIONS: This offer entitles new UK subscribers to receive their first 5 issues for 5 for UK readers. After your trial ends, your subscription price will be adjusted to reflect a 10% saving against the RRP price. This offer is also open to overseas readers, 5 issues for â‚Ź5 for Europe and 5 issues for $5 for ROW. After these issues, standard subscription pricing will apply. The biggest savings are compared with the overseas RRP. For all savings details see online offer page. You can write to us or call us to cancel your subscription within 14 days of purchase. Payment is non-refundable after the 14 day cancellation period unless exceptional circumstances apply. Your statutory rights are not affected. Prices correct at point of print and subject to change. Full details of the Direct Debit guarantee are available upon request. For full terms and conditions please visit: bit.ly/magtandc. Offer ends 31st May 2020.


THE END OF 32-BIT?

Working from his fortress of solitude, Jonni Bidwell investigates the options for 32-bit users now  that future versions of Ubuntu won’t be  supporting them.

buntu 20.04, the longawaited Long Term Support (LTS) edition of one of the world’s most popular distros, is coming, and you can’t install it on a 32-bit PC. Neither can you upgrade 32-bit Ubuntu 18.04 to this edition. And all those distros that get rebased off the new LTS? You can’t run those either. So does this mean the end of 32-bit Linux? Not at all. Are we then guilty of misleading headlines? Maybe a little bit. For one thing, there are lots of 32-bit platforms that aren’t going away – Ubuntu is only dropping support for the 32-bit x86 architecture – 32-bit ARM devices (including Raspberry Pis) for example are still supported. Debian (and plenty of other distributions) will continue to support

U

32-bit x86 machines until at least 2024. The previous Ubuntu release (and its derivatives, such as Mint 19) will be supported until 2023, so there’s no need to panic just yet. Most importantly, nothing is going to happen to 32-bit support in the kernel any time soon.

pleasant Firefox experience, no matter how lightweight you make the underlying desktop. But there are other ways to browse the web, and there are other use cases beyond the desktop where modest hardware can still be useful. So if you are running 32-bit machinery, or contemplating resurrecting your old dusty tower, we’ll give you some helpful ideas. We’ll go in depth with the Linux Mint Debian Edition, which is the natural place for Mint users (and anyone else seeking a user-friendly, reliable distro) to seek refuge. And we’ll talk about some even more lightweight offerings that are out there. We’ll also look at how Linux does support old hardware for as long as it’s reasonable to do so, and we’ll take a look at where 32-bit code is still required.

32-BIT KEEPS ON GOING “There’s no need to panic just yet. Most importantly, nothing is going to happen to 32-bit support in the kernel any time soon.”

26     LXF263 June 2020

That being said, such hardware isn’t really suited to running modern applications. A single CPU core and a hard 4GB memory limit do not make for a

www.linuxformat.com


Saving 32-bit

Reasons and recourse Why would Ubuntu stop supporting 32-bit? Which gentle distros will take in the exiled users? Let’s find out… n 1991 Linus Torvalds took to the newsgroups to announce a free hobbyist operating system, which would later come to be known as Linux. The humble machine that he used to make this toy OS was a 33MHz 386 with four megabytes of memory. Indeed, that famous Usenet posting says that Linux was for 386 and 486 AT clones, and that it was categorically not portable to other architectures because of the 386-specific processor features it exploited. However, by 1995 Linux was running on DEC and Sparc platforms, and others soon followed. In 1997 Linus was awarded his master’s degree for a thesis entitled “Linux: A Portable Operating System”. The architecture-specific bits of the kernel had been largely separated from code that would be common across platforms. Linux had acquired the portability that would be key to its subsequent taking over of the world. Fast forward to 2012 and the release of kernel 3.8, and we see Linus wishing “good riddance” to the 386 as it is summarily dropped from the kernel. Linux had outgrown its humble beginnings, and that particular 32-bit architecture was no longer being made and was barely being used. Letting the 386 code go made parts of the kernel a little simpler, and meant that the remaining architectures could be treated more uniformly going forward. Occasionally, archaic or barely maintained architectures are dropped from the kernel, and you can get an insight into that process by studying Jonathan Corbet’s write-up at https://lwn.net/ Articles/769468. We don’t want you to worry that 32-bit x86 code will go the same way. Because it won’t, not anytime soon anyway – hardware from this era doesn’t really require any special treatment in the same sense that the 386 did. The main reason Ubuntu is dropping support for it is purely pragmatic. Since 2004 they’ve maintained two desktop editions, and the vast majority of people (some

I

98% according to https://ubuntu.com/desktop/ statistics) are using the 64-bit edition. The effort to maintain what is in effect a whole separate distro, and in particular to test the 40,000 packages found in the Ubuntu repositories, is simply not tenable. Plenty of applications now depend on 64-bit instructions (e.g. virtualisation), and plenty need more than the 4GB a processor running on a 32-bit system can address. Ubuntu isn’t alone in dropping 32-bit support. Fedora let it go officially in version 27, released in November 2017, although a 32-bit netinstall was available up until version 30, released in April 2019. Arch Linux has been 64-bit only since 2018, but a community-driven Arch Linux 32 port is available. Debian will continue to support 32-bit Buster until 2024, and we’ll hear nearer the time whether its successor (codenamed Bullseye) will support the older architecture. Mint 20 won’t have a 32-bit edition, but Mint fans wanting to keep their 32-bit systems minty should check out Linux Mint Debian Edition. As chance would have it, the next two pages cover just that.

AntiX strikes a balance between lightweight and usable with remarkable accuracy. It’s on our virtual DVD, and on the internet.

PARTY LIKE IT’S 2038 The year 2000 problem didn’t end the world, but in the years since, developers have become increasingly concerned that an aclockalypse in 2038 might. Unix time is an arbitrary standard used by Linux and other systems that measures time as the number of seconds since 1 January 1970. This used to be stored as a 32-bit signed integer, meaning it could represent any time up to some 2.1 billion seconds into the future. The exact date is 19 January

www.techradar.com/pro/linux

2038, a time when many devices – industrial ones rather than your decrepit 486 – will still be running Linux. Efforts to address this impending issue began back in 2014, where the core timekeeping code was updated to use a 64-bit value on 64-bit systems. This isn’t the end of the story though, as the rest of the kernel (older filesystems in particular) and userspace applications still need to be updated to support longer time.

For 32-bit systems (not just x86 ones), Linux 5.1 introduced a special time64 syscall to remedy the situation, but again the kernel and userspace still need to be updated to use it where appropriate, lest they all go back to 1970. Writing on the kernel mailing list, developer Arnd Bergmann cautiously notes that the imminent kernel 5.6 “should be the first release that can serve as a base for a 32-bit system designed to run beyond year 2038.”

June 2020 LXF263     27


TUX RACER Dan Cauchy brings Jonni Bidwell up to speed on Automotive Grade Linux, coming soon to a car – or even a boat – near you!

34     LXF263 June 2020

www.linuxformat.com


Dan Cauchy INTERVIEW

an Cauchy is executive director of Automotive Grade Linux at the Linux Foundation. Before that he was VP of Automotive at MontaVista, which was a pioneer of embedded Linux. And before that he was a board member for the GENIVI Alliance, which was instrumental in getting car manufacturers to adopt open source, standards-based IVI (invehicle infotainment) systems. AGL isn’t so much about self-driving cars as powering its infotainment and instrumentation systems. We actually met Dan before, back in LXF218. But you can imagine things move fast in the world of cars, and also we like Dan, so we thought a catch-up was well in order. As luck would have it, both he and roving reporting unit Jonni Bidwell were at October 2019’s Open Source Summit in Lyon, where the following exchange ensued…

D

Linux Format: How did you get into open source and automotive software? Dan Cauchy: I was a general manager and VP of the automotive business at MontaVista Software. MontaVista was a really pioneering company, in that it was the first to identify that Linux could be put into devices. Things like Canon printers, Sony ebook readers, the PlayStation 3… these are all things that Montavista did the kernel for. They were known as a Linux kernel guru company. Eventually, among those things we got into automotive and I ran that whole division. We were the first to put Linux in a vehicle, I can’t mention which vehicle any more, but your readers can easily look that up on the Internet. I was on the board of directors for the GENIVI Alliance and I was the chairman of the compliance programme. So that more or less propelled me into this whole Linux-incars world, and AGL became an obvious thing for me. LXF: Propellers you say? This reminds me, I own a narrowboat. Do you think one day I can power it with AGL? DC: A narrowboat? Cool. We will absolutely support other types of vehicles. We’re actually working with the government of France and one of our members has been funded to do some work on boat Linux. And it would be 100 per cent AGL-based because the requirements are the same. There might be new features that are boat-specific, but it makes total sense.

www.techradar.com/pro/linux

And by the way, one of the guys working on this has a 50-foot sailboat so he’s all excited about that as well. So yes, absolutely, it’s coming. LXF: So we last met in Berlin in 2016, I believe. I guess an awful lot has happened with Automotive Grade Linux (AGL) since then. Can you summarise what’s new? DC: We’ve literally exploded in the

up SAIC from China. So in 2016, when I last talked to you, people thought we were a Japanese-only consortium, because most of our partners were from there. We can now safely say we’re a worldwide consortium. We’ve had Daimler signed up for a long time, but the addition of the Volkswagen Group means we’re quite big in Germany and the rest of Europe. Adding Ford means we now have this ecosystem in the US, and adding

DEALING WITH IN-CAR AV STREAMS “If the navigation is trying to talk to you and a phone call comes in and the lane departure warning needs to tell you something, you need to have that capability.” past three years, in terms of member participation. We now have 155 member companies; when we last spoke that number was probably less than half of that. The most important part is the automotive manufacturers: we now have 11 OEMS on board. And if you look at the market share of these OEMS it accounts for approximately 60 per cent of annual worldwide vehicle shipments. So these are the big ones: Toyota, Mazda, Daimler, and we recently signed up Volkswagen Group, so that’s the whole group including Audi, Porsche, Scania, Skoda, Lamborghini, Bugatti and I’m still missing a few. We recently signed up Ford, and on top of all of that we signed

SAIC means we can start building our ecosystem in China. So the growth is still going and I don’t see it stopping any time soon. Oh, Hyundai signed up a year ago too, so that’s key for South Korea as well. LXF: Olly, my trusted photographer, drove us to the airport, which involved judicious sat nav use. So I was telling him that this might well be powered by AGL. He was shocked to hear Linux isn’t just for people who want to make their desktop computing lives difficult. There’s a whole world of embedded systems that use it. Maybe we talked about this side of things last time, but being an infotainment system means there are

June 2020 LXF263     35


GET LINUX FORMAT FROM £4.17 A MONTH

LXF ARCHIVE! Get access to 15 years’ worth of magazine issues

This offer is ONLY available via our online shop

www.myfavouritemagazines.co.uk/lind/DIGCSP20 Available on iOS and Android www.techradar.com/pro/linux

June 2020 LXF263     39


IN-DEPTH Tor

UNPEELING THE ONION BROWSER Discover how you can mask your web browsing and how governments track you, with a little help from Neil Mohr.

hey’re watching you. They’re watching everything you do online. You’d think we were being paranoid, but it’s part of their mission statement; the international Five Eyes (https:// en.wikipedia.org/wiki/Five_Eyes) is a group made up of Australia, Canada, New Zealand, the United Kingdom, and the United States, which have worked together since World War II to collate and share intelligence – and that includes internet use by you. In the digital age, that means intercepting, storing, and analysing all

T

SITE.COM USER/PW DATA LOCATION

internet traffic. Don’t be fooled into thinking that local laws can stop a nation state from spying on its own citizens. If you’re one of the Five Eyes, just get your mates overseas to do the spying, then report back. Tempora (https:// en.wikipedia.org/wiki/Tempora), a UK programme, splices off the undersea fibreoptic backbone of the internet, duplicates all the data transmitted over it. The data is then shared with the USA's NSA. Damn crafty us Brits, described by Edward Snowden as “worse than the US.” In the USA, programmes such as PRISM created a legal framework for the

SITE.COM« »USER/PW« »DATA« LOCATION

NSA to spy on targeted US citizens, immunising co-operating US companies from prosecution. Or take MUSCULAR for bulk copying Google and Yahoo! data to outside US territory, for the NSA and the UK's GCHQ to rifle through at their leisure. And who knows what Russia, North Korea, and China are up to. It’s not paranoia if it’s actually happening. But the good news is that the open source community has brought together a host of privacy technology to offer a verified solution: Tor.

SITE.COM« »USER/PW« »DATA« LOCATION

SITE.COM« »USER/PW« »DATA« LOCATION

SITE.COM« »USER/PW« »DATA« SITE.COM« USER/PW« DATA« LOCATION

LOCATION

SITE.COM« »USER/PW« »DATA« LOCATION

Image credit: EFF, CC BY 3.0 US

SITE.COM« USER/PW« DATA« LOCATION

SITE.COM« »USER/PW »DATA LOCATION«

KEY HIDDEN BY TOR « HIDDEN BY HTTPS » INTERNET CONNECTION EAVESDROPPING DATA SHARING TOR NETWORK

40     LXF263 June 2020

SITE.COM USER/PW DATA LOCATION« SITE.COM

»USER/PW »DATA LOCATION«

SITE.COM USER/PW DATA LOCATION«

SITE.COM

»USER/PW »DATA LOCATION«

SITE.COM USER/PW DATA LOCATION«

Take a look at how much privacy protection Tor and HTTPS offer when used together. Without these at every step in the process, anybody with access can snoop on all your activity, including the destination site, your username and password, user data, and location. Using HTTPS protects user data, usernames, and also passwords at all stages. Using Tor masks your destination site, username and password, data, and, to a certain degree, location. Adding a VPN would further protect your location details, but we should point out that there could be government bodies directly accessing ISP data or the site. com services via unknown snooping programmes.

www.linuxformat.com


TUTORIALS If This Then That

IFTTT

Sensor-triggered Telegram alert system Les Pounder shows us how to use webhooks to trigger online services to communicate with one another. n this month’s tutorial we will be creating a project that will alert us to any movement via a passive infrared (PIR) sensor. This will trigger a message to be sent to a service called IFTTT, which is used to receive inputs from various other services and then send outputs to other services. This message to IFTTT will trigger an output and image to be sent to a Telegram account alerting us to an intruder. With the Raspberry Pi powered off, connect the PIR sensor to the GPIO using the three jumper wires. Connect GND to GND, VCC to the 5V pin of the Raspberry Pi. Lastly, connect the output pin of the sensor to GPIO17 of the Raspberry Pi. Now connect the camera to the CSI port, just next to the Ethernet/USB ports. You will need to gently lift the plastic clip and slide the cable in with the blue tab facing the USB ports. Then secure the cable with the plastic clip. Ensure that the camera does not touch the Pi at any time as it may cause a short circuit. Power up your Pi and from the main desktop go to Preferences > Raspberry Pi Configuration and once there click on the Interfaces tab and enable the Pi Camera interface. When prompted reboot and wait for the Pi to return to the desktop.

I

OUR EXPERT Les Pounder is a freelance maker who works with organisations such as the Raspberry Pi Foundation to promote maker skills. He also blogs at bigl.es

YOU NEED

Software setup

Any Pi Keyboard/ Mouse/ Power/HDMI Raspbian Official PiCamera PIR movement sensor 3x Female to female jumper wires Code: https:// github.com/ lesp/LXF262/ archive/ master.zip

On the Raspberry Pi, open a web browser and visit https://web.telegram.org and create a new account. Keep the Telegram web app window open, as this will be used to debug and view the output of the project. Now open a new browser window/tab and visit https://ifttt.com sign up for a free account. IFTTT stands for IF This, Then That, and it is used to trigger actions based on inputs. In this project we will create a webhook, a real-time link from our code to the web that will trigger a message on Telegram that alerts us about an intruder. To create the trigger, click on your account avatar icon in the top right of the screen, then select Create. Now click on If + and type in webhook, and click on the blue icon to launch. In the next screen click on Receive A Web Request, and then on the next screen give the event name as “trigger”, without the quotation marks. Next, click on Then + and search for Telegram. Click on the selection and then click on Send Photo as the

46     LXF263 June 2020

Telegram is a great real-time communications tool, and here we are using it to send images from our Raspberry Pi sensor trap!

action. In the next screen the target chat should be with @IFTTT, however, as this is the first time we have used it we need to connect IFTTT with Telegram – just follow the process and it will connect up. Once connected it will take us back to the previous screen, so ensure that the target chat is with @IFTTT and then in the Photo URL section click on Add Ingredient and select Value1. Ensure that Value1 has a capital V. In the Caption section, change the caption to “Movement detected” and then click Create Action, then on the next screen click Finish to create and start the service. Now click on Home, and in the Filter services box type Webhooks and click on the filtered icon. In the next screen click on Documentation and you will see how the webhook is constructed. In the Make a POST or GET section click on {event} and change it to trigger. Now on the bottom line, which starts curl -X POST, select from https to the end of the line, then copy the link and save it in a notepad for later use. When you’re done click < Back to service. The last step in the setup is to create an account with www.filestack.com, which will be used to store images uploaded from the Pi. These images are then attached to the Telegram message. Sign up for a free account, and when logged in to the Dashboard your API key will be in the top right corner. We will need this later. To use filestack with Python we need to install the library. In a terminal type the following and then press Enter to run: $ sudo pip3 install filestack-python

Then close the terminal.

www.linuxformat.com


TUTORIALS Using Arduino

EMBEDDED

A Pi user’s guide to coding the Arduino

Get used to the Arduino series of boards, with the help of Les Pounder and the Raspberry Pi, to build better projects. he Arduino is a powerful board. It may not have the same processing power as a Raspberry Pi – in fact it cannot even match the original Raspberry Pi – but it has power in its simplicity and connectivity. It has protocols such as I2C, SPI, UART and serial, in addition to digital IO (on/off) and analogue IO. But why is this important? With an Arduino we can write the code on our computer, in this case a Raspberry Pi, and then flash the code onto the Arduino where it is stored. We can remove the Arduino from the Pi, and as long as we can supply power to the project, it can run quite happily with no screen. With the newer batch of Arduinos we can connect to the internet and networks, send data over said networks and even send data back to the Arduino. The power of the Arduino is that it can be independent and gather data for you in the field. Sure, the Raspberry Pi can also do this, but why use an entire Linux computer just to gather data when you can run a tiny, power-efficient microcontroller? In this project we are going to create a simple motorcontrol project that will control the speed of a motor using a rotary encoder, and the status of the motor will be displayed to the user via an LCD screen. As we move through the project, we will also compare the Arduino programming language to Python, the typical language used on the Raspberry Pi.

T

OUR EXPERT Les Pounder is a freelance creative technologist who works with companies such as Raspberry Pi Foundation, Cisco, and Micro:bit Foundation to promote maker skills to all ages.

YOU NEED Arduino Uno I2C LCD Screen L298N motor controller Rotary encoder DC motor Additional 5V power supply for motor 6x femaleto-male jumper wires 5x maleto-male jumper wires Code: http://bit.ly/ LXF262pi 48     LXF263 June 2020

The LCD screen is a simple and effective output device. We get all of the information that we need to run the project.

Hardware setup The Arduino should be connected to a free USB port on the Raspberry Pi via a known good-quality data cable (not all USB cables carry data lines). Using four male-tofemale jumper wires, connect the I2C LCD screen to the Arduino’s I2C pins (5V, GND, SCL and SDA). Then connect the rotary encoder to the Arduino via a breadboard and three male-to-male jumper wires. The centre pin of the three connects to GND. We then need to connect pin 9, our motor pin, to IN1 on the L298N motor controller, and then connect GND from the Arduino to GND on the L298N and to IN2. This will force the motor to spin in one direction only. Connect a 5V power supply to the L298N, and ensure that the GND connection of the power supply is connected to the GND of the L298N, and the Arduino. This creates a “Common Ground” used as reference for all voltages. Double-check all of the connections via the circuit diagram – a high-resolution version is available in the download for this project.

Software installation An I2C backpack is a much better solution to connecting all 16 wires needed for the LCD screen to work.

We start the software aspect of the project by first visiting the Arduino website at www.arduino.cc and clicking on Software > Downloads. For all models of the Raspberry Pi, even the Pi 4, we need to download the 32-bit ARM Linux version of the Arduino IDE. Once downloaded, extract the contents of the file to your

www.linuxformat.com


TUTORIALS VIM

Extending VIM functions with plugins Being quite versatile himself, it’s no wonder Shashank Sharma has such fondness for the highly extendable Vim. ack in LXF258 we introduced you to Vim, a fiercely popular and featureful text editor, and discussed how you can enhance your Vim experience by enabling some advanced options such as auto-completion, smart search, and even polish your writings by using a thesaurus and dictionary. While all that can be done with a vanilla Vim installation, albeit with some modifications to the configuration file, with different plugins you can get additional useful features such as creating bullet lists, and can even transform Vim into a password manager, and more. Before we do that, however, it’s imperative to learn how to install plugins. The easiest way is to download the individual files into a dedicated directory, and update the ~/.vimrc file. The downside to this approach is that you have to manually install updates for each of the plugins as they become available. This is still not a problem if all you have is half a dozen plugins, but what if you had more? There are dozens and dozens of plugins that you may wish to use at one time or another, and manually fetching each is unnecessarily painful. You

B

OUR EXPERT Shashank Sharma is a trial lawyer in Delhi. He’s pained at having to abandon the noble quest of growing a yeard.

Any mention of running a command beginning with a : implies that it needs to be run from within Vim, and not from your terminal. You can simply launch Vim, and execute the :PlugClean and the :PlugStatus and the other commands as mentioned in this tutorial.

can instead use a plugin manager, which makes installing, updating, and deleting plugins a breeze.

Using Vim-plug Our favourite plugin manager is vim-plug, which is quite straightforward to set up and use. To begin, open a terminal and run the curl -o ~/.vim/autoload/plug.vim https://raw.githubusercontent.com/junegunn/vimplug/master/plug.vim command. If you already have a

~/.vim/autoload directory, you can alternatively navigate into this directory and download the plug.vim file with the wget https://raw.githubusercontent.com/ junegunn/vim-plug/master/plug.vim

The next step is to inform Vim to use vim-plug plugin manager. You need to edit the ~/.vimrc file and add the following lines: call plug#begin(‘~/.vim/plugins-placeholder’) call plug#end()

Leave the rest of the ~/.vimrc file unchanged for now. In the first line, you must provide the complete path to a directory where Vim-plug will store all the downloaded plugins. The project suggests using any name for this

Vundle and Pathogen are also quite popular plugin managers for Vim, and work much the same way as vim-plug.

52     LXF263 June 2020

www.linuxformat.com


TUTORIALS Better project management Credit: https://wekan.github.io

WEKAN

Build and organise a Kanban board Nick Peers reveals how to implement Kanban boards to help speed up project management, either for personal or work purposes. roject management is a tricky skill. What can start out as a relatively simple task can spiral out of hand when you get underway and discover new angles, fresh requirements and who knows what else. It’s hard enough managing a project on your own, but what if your project involves other people, too? It doesn’t matter whether you have a project for personal or work purposes, these days the recommend approach to project management is an Agile one. Agile allows for frequent changes to the spec – both minor and major – and aims to prioritise delivery of the project in manageable chunks. There are various forms of Agile project management available, and we’re focusing on Kanban in this tutorial – see the box for a detailed description. The logic behind a Kanban board is that it provides an overview of both the project process and its progress, encouraging you to pull tasks from the board when you’re in a position to allocate time to them rather than the other way round.

P

OUR EXPERT Nick Peers finally has a tool he can use to craft the perfect post-apocalyptic server. Sure, he’ll starve to death, but at least there’s lots of media to consume.

Standalone boards All Kanban tools work on the principle of being accessed through your web browser, which usually involves

installing a server component, configuring it for local or remote access and then going on from there. If you’re planning a larger project involving more than one person, then skip to the section on Wekan. If you’re looking for a simple, fuss-free option for your sole use, then My Personal Kanban meets your needs. It’s basically a one-page HTML/Javascript application that runs through your web browser from inside a single folder – note, everything is kept offline, so you don’t even need an internet connection to use it. Head over to https://greggigon.github.io/ my-personal-kanban and click Download .zip. Once done, extract the my-personal-kanban folder somewhere suitable – your Home folder for example – and then double-click the index.html file inside to open it in your web browser. Start by clicking the Kanban drop-down menu in the right-hand corner and choose New. Give your board a name, choose how many lists you want (anything from two to nine is supported) and click Create new. Your lists will be created as blank columns. Click the spanner icon to the left of one to rename it, select a colour and set a limit for how many cards the list can

Navigate your Wekan boards 5

1

Board controls Here you’ll find options to make the board permanently visible. Set it to Public (read-only) or Private Access and set Notifications.

1

6

List view Lists are displayed in columns, with individual card titles displayed with any labels assigned to them.

2

2

4

Swimlanes These horizontal bands offer an extra layer of organisation, making it easy to split tasks into whichever categories you see fit.

3

Card details Click a card to review and edit its details. Assign it to a user, apply labels, set deadlines and even set up subtasks.

4

3

Customise view Click this button to choose your view – the option for creating rules is also hidden in this drop-down menu.

5

Board settings Click the hamburger ( ) icon to reveal the slide-out settings pane where you can invite other users and customise labels.

6

54     LXF263 June 2020

www.linuxformat.com


HOTPICKS THE BEST NEW OPEN SOURCE SOFTWARE ON THE PLANET

HotPicks

Alexander Tolstoy has discovered another portion of powerful, stunning and super-useful OSS applications.

MyPaint Fontpreview VokoscreenNG APK Editor Studio G’MIC XanMod Regards GZDoom Typer Nmap Strawberry DRAWING SOFTWARE

MyPaint Version: 2.0 Web: http://mypaint.org n mid-February MyPaint clicked over to version 2.0, and we could not pass it by. This drawing software is a prominent and well-recognised tool for digital artists, and in some ways it is also the main rival to Krita, another core FOSS drawing suite. We reviewed the earlier version of MyPaint here in LXF209, but since we have the major new release, it’s time to revisit the app. This application continues to be a very user-focused software for anyone fond of digital drawing, painting and sketching. MyPaint features an ‘endless’ canvas, which saves you from worries about running out of pixels and megabytes – but watch that RAM usage if your canvas is really large. In most cases, getting started is piece of pie. Select the brush you want from the vast assortment of gorgeous MyPaint brushes, and you are ready to go. Panels, settings and all other auxiliary parts of the interface tend to stick to sides, keeping the main painting area in the centre clutter-free. The new things introduced in the updated MyPaint are most visible to seasoned users, so to feel the difference you need to at least draw something. The default empty layer now has the ‘pigment’ type instead of ‘normal’, which changes the way brush strokes feel. The underlying compositing and blending mechanism in MyPaint has also been changed, which results in different perception of what you draw. The developers claim that in MyPaint 2.0 artwork feels more like it has been made using traditional media, which is certainly a matter of taste and dispute. Luckily, there is an appropriate compatibility switch in the MyPaint settings that lets you return to the previous blending engine. It makes a lot of sense, since MyPaint saves artwork to the OpenRaster format (ORA), which is more advanced than a typical bitmap format. The same file opened in MyPaint 1.x and 2.0 will look different due to those blending and compositing changes,so the switch for preserving the ‘old-style’ look is a very welcome inclusion.

I

58     LXF263 June 2020

MyPaint brushes feel very natural and invite you to paint something with your graphic tablet, mouse or finger. (wash your hands first!–Ed)

Exploring the MyPaint interface... 1 5 2

4 3

Main toolbar Start by choosing the right tool – paintbrush, inking tool, eraser, colour picker, fill bucket, etc.

1

and media, and it does it really well! Choose the style you want to go with.

2

The endless canvas Forget about pixels - just draw as you want, and MyPaint will automatically extend the canvas when required.

3

Sketch with the Scratchpad Don’t miss that small ‘second canvas’ you always have at hand for sketches, notes and any other marks.

Precise colour selection There are several ways of picking the desired colour, including the RGB sliders and the colour wheel. Don’t get lost in the brush catalogue! MyPaint can mimic most real-life tools

4

5

www.linuxformat.com


TUTORIALS Duplicati backups

DUPLICATI

Easily secure your cloud backups The ever security-conscious Nick Peers reveals how to use your cloud back-up storage as a water-tight back-up location for your key data. ou can’t have too many backups, and that at least one of those backups should ideally be stored offsite – which typically means in the cloud. But can you trust the cloud with your sensitive data? Can you be sure your cloud provider is telling the truth when it says your data is fully secure and private? What happens if its servers are hacked? Who controls the encryption keys that stand between you and your data being opened to government agencies? The solution is to employ a secondary layer of encryption to your data before uploading it. This layer remains under your control, which means those encryption keys aren’t in anyone’s hands other than your own. You can employ this secondary layer several ways – the box (bottom right) reveals a quick technique for individual files – but another approach is to employ a virtual container inside which your files are stored. The obvious solution here is VeraCrypt’s encrypted file container, but it’s not optimised for remote storage. Instead, try a free tool called Cryptomator (www.cryptomator.org). This is similar to VeraCrypt in that you create an encrypted container, or vault, inside which all your sensitive data is copied. The vault resides in your local cloud folder – so works with any cloud provider – and is optimised for remote storage by the fact it’s a regular folder inside which your files and subfolders are encrypted individually. This means

Y

OUR EXPERT Nick Peers is now able to take his NAShosted backup using NextCloud and place a secure copy of it online beyond the reach of hackers and governments.

adding new files or editing existing ones uses less bandwidth than ones where all changes result in a single large virtual volume being re-synced time and again.

Enter the Cryptomator

Cryptomator can be run either as a standalone AppImage from www.cryptomator.org/downloads or you can add the PPA in Ubuntu 18.04 or later for a build that updates automatically. Just type the following commands into the Terminal: $ sudo add-apt-repository ppa:sebastian-stenzel/ cryptomator $ sudo apt-get update $ sudo apt-get install cryptomator

Once installed, launch Cryptomator from the Launcher and enable updates if asked. From here it’s a simple case of picking a suitable location – inside one of your synced cloud folders obviously, then giving your vault a suitable name (this will become its folder name) before assigning it a strong password that you store securely elsewhere like in your password manager. After clicking Create Vault, click More Options to tweak various settings, including unlocking the vault automatically on startup. Once done, click Unlock Vault and it can be used like any other folder – for security purposes all files copied or edited are encrypted on your computer before being uploaded to the cloud.

Manage your Duplicati backups 3

2

4

1

6

5

Key controls Use these to create and restore backup jobs, plus tweak Duplicati’s core settings. Click About to access system logs.

1

2

Track progress This progress bar shows how your backup is processing.

3

Set bandwidth limits Set appropriate upload and download limits here.

4

Configuration Edit the back-up job, plus export it as a file for back-up purposes.

Advanced features Verify your backed-up files, compact or repair the underlying database and access command-line options for the backup job.

5

6 64     LXF263 June 2020

Backup summary Get an overview of this backup job here.

www.linuxformat.com


SUBSCRIBE Save money today!

SUBSCRIBE

Sign up today and get this fantastic

KLIPSCH T5M WIRED EARPHONES Enjoy What Hi-Fi? 5-star awardwinning audio quality with these   in-ear Klipsch earphones. Top-rated   for comfort, sound, build, and winner of the Best in-ear headphones 2019 category! Who could ask for more?

YOUR GIFT! WORTH £70.00

Don’t miss out,   subscribe now!

“The Klipsch T5M Wired in-ears are up there with the very best at this kind of money and will make a big difference.” What Hi-Fi? July 2019

Top features Premium in-ear headphone with moving coil micro speaker Patented contour ear tips and IPX4 water/sweat resistant Wired in-ear headphone with detailed, impactful sound Patented contour ear tips Full bass, dynamic driver

SUBSCRIBE NOW! www.myfavouritemagazines.co.uk/lin/klp1

Call: 0344 848 2852 72     LXF263 June 2020

www.linuxformat.com


5 for 5 saver p25 Go digital! p39

PLUS: Exclusive access to the Linux Format subs area! 1

! DON’T MISS s ar ye Now with 5 & r se U x of Linu Developer issues

CHOOSE YOUR PACKAGE! ANNUAL DIGITAL ONLY

ANNUAL PRINT AND DIGITAL

PLUS!

SAVE!

Only

44%

£50.00

13 digital issues over 12 months  by Direct Debit (NO GIFT)

2-YEAR PRINT AND DIGITAL

Only

£72

SAVE!

58%

Annual print and digital  by Direct Debit

PLUS! Only

SAVE!

£136

61%

2-year print and digital  one-off payment

This offer is only available for new UK subscribers. Gift is subject to availability (MSRP £70.00). In the event of stocks being exhausted we reserve the right to replace with items of similar value. You can write to us or call us to cancel your subscription within 14 days of purchase. Payment is non-refundable after the 14 day cancellation period unless exceptional circumstances apply. Your statutory rights are not affected. Prices correct at point of print and subject to change. Full details of the Direct Debit guarantee are available upon request. Due to the current challenges we have extended the expiry date on this offer for a further two months. For full terms and conditions please visit: bit.ly/magtandc. Offer ends: 31/08/2020

www.techradar.com/pro/linux

June 2020 LXF263     73

1) Only available to MyFavouriteMagazines.co.uk subscribers.

1,000s of DRM-free  PDF back issues and articles! Get instant access back to issue 66 (May 2005) with tutorials, interviews, features and reviews.  At linuxformat.com


CODING ACADEMY CODING ACADEMY Platform gaming

PYTHON

Code series

Don’t miss next issue, subscribe on page 72!

Platformers in Python Armchair arcade warrior Calvin Robinson guides us through creating a side-scrolling platform game in Python. Are you ready, Player One? ide-scrolling video games are usually action based, with a side-view perspective on a player character traversing a two-dimensional world. As the character moves left or right, the game world moves with them. Timeless classics include Sonic The Hedgehog and Super Mario Bros. More contemporary takes would include Broforce, Super Meat Boy, Braid, Rayman Legends, Limbo… all fantastic titles! There’s a debate to be had about the first sidescrolling arcade game, released sometime in the 1970s, but the first game to enable the world to extend beyond a single screen was 1981’s Defender, a side-scrolling shooter. Before this worlds were restricted to a single screen, showing only what was on the monitor. A game called Jump Bug came out that same year, which was the first side-scrolling platform shooter, offering players the ability to jump on platforms, with levels that scrolled now only horizontally but also vertically. For our game, we’re going to dial things down a step and work with 2D shapes to begin with. This project is all about getting the game world, player character and relevant physics programmed. Let’s start by loading up Python IDLE or your favourite text-based editor and setting up the basic parameters for our game world:

S

OUR EXPERT Calvin Robinson is a computer science teacher, former deputy head teacher and currently consulting as a subject matter expert for the National Centre for Computing Education.

import pygame BLACK = (0, 0, 0) WHITE = (255, 255, 255) RED = (255, 0, 0) GREEN = (0, 255, 0) BLUE = (0, 0, 255) SCREEN_WIDTH = 1024 SCREEN_HEIGHT = 768

Consider taking away the boundary checks so your player character can fall through the floor, just as Mario can in places, resulting in death and a restart of the current level.

74     LXF263 June 2020

Pygame is a module that offers a handy toolset. It takes care of shapes and physics, so that we can focus on building our game rather than putting a lot of time and effort into re-inventing the wheel. We’re initialising several variables here: these colours will be used for objects in the game environment, Feel free to change the RGB values as you see fit. As for resolution, we’re running quite low-res on 1,024x768 by default but you could change this to high definition with 1,280x720 for 720p or 1,920x1,080 for 1080p. Now that we have the basics setup, we can start coding. We’re going to take an object-oriented approach, with classes and objects. By setting up a class for levels first, we can then implement a child class for each subsequent level later.

Here’s the main while loop that keeps our gameplay ticking.

class Level(): def __init__(self, player): self.platform_list = pygame.sprite.Group() self.enemy_list = pygame.sprite.Group() self.player = player self.world_shift = 0 def update(self): self.platform_list.update() self.enemy_list.update() def draw(self, screen): screen.fill(BLUE) self.platform_list.draw(screen) self.enemy_list.draw(screen) def shift_world(self, shift_x): self.world_shift += shift_x for platform in self.platform_list: platform.rect.x += shift_x for enemy in self.enemy_list: enemy.rect.x += shift_x There are a number of methods here. Draw spawns

our ‘sprites’ (be them 2D vector graphics) on the screen while Update keeps them updated. That may seem self-explanatory, and that’s precisely why we use good naming conventions. Since our game is a side-scrolling platformer, our player character will mostly be moving from left to right, across the screen. There are a few ways we could implement this, but it’d look quite odd in this instance if we let the player move all the way from the left of the screen to the right – unless our levels were really that small. To give a larger sense of scale, we’re going to enable our player character to move freely to a point, then keep them in the centre of the screen and switch to moving the game world behind them, instead of the player themselves.

www.linuxformat.com


9000

CODING ACADEMY Solving mazes The code

Get it at: linuxformat. com/archives

GRAPH THEORY

How to solve mazes using Go and maths The a-mazing Mihalis Tsoukalos reveals how graph algorithms and backtracking can be used to provide a solution to a maze his month, we’re going delve into solving maze and dungeon puzzles with the help of graph theory (well, we are all in isolation–Ed). The purpose of such puzzles is to determine whether there’s a path that connects two places and find that path, keeping in mind that not all maze puzzles are solvable! A maze is a path or a collection of paths. When we say that we want to solve a maze, we mean that we should find a way of going from the start cell (entrance), which is predefined, to the end cell (goal), which is also predefined. A similar way of thinking about solving a maze is routing through obstacles of various types from your current place to a given location. A maze might have multiple solutions, too. To solve a maze, you just have to find a trail between the start and end points of the maze. Note that mazes can be implemented using undirected graphs and that if a maze contains isolated nodes or too many wall cells then it might not be solvable. The way you represent a maze has nothing to do with the maze itself – it’s just a practical way of working with a maze in your computer programs. The diagram (right) shows a graphical representation of a maze that’s appropriate for humans along with its solution, which is represented by a red line. A popular way of representing a maze using code is by using an array: a data structure that can be found in almost every programming language. As a result rectangular mazes can be viewed as grids. The biggest disadvantage of arrays is that they can’t be customised, which means that you can either do your job with an array or you can’t – there’s no middle ground. As a result, if the requirements of a problem change, an array might not do the job and you’ll end up doing code changes to support a different and more advanced data structure that’ll be used instead of the array. For the purposes of this tutorial, arrays will do just fine.

T

OUR EXPERT Mihalis Tsoukalos is a data scientist and technical writer. He’s also the author of Go Systems Programming and Mastering Go, 2nd edition.

The Design and Analysis of Computer Algorithms by Alfred Aho, Jeffrey Ullman, and John Hopcroft is a classic book that contains information about graphs. You can also check the https:// en.wikipedia. org/wiki/ Graph_drawing Wikipedia page about graphs.

78     LXF263 June 2020

Seeing the Matrix It’s time to expand your mind and realise how a rectangular maze puzzle can be represented in a computer program as a grid. This time we’ll begin with an example:

A conventional view of a maze and its solution. PCs and programming languages use different representations for a maze and its solution.

011 111 110

This output represents an array that represents an undirected graph. The logic behind the array follows two main rules. If node 0 is connected to node 1, then both (0, 1) and (1, 0) places in the array are marked with 1 (or another value that says that they are connected). Otherwise, they’re marked with 0. Last, cells are able to connect left, right, up and down. In the previous example both (0,0) and (2,2) are wall cells – all other cells are connected to each other. This tutorial will use 0 and 1 for representing walls and valid cells, respectively. Although this has the advantage that we can use boolean values instead of integer values in our maze representations, it’s considered a good practice to only think of 0 as a wall cell and of everything else as a valid cell, which means that we’re going to use integer values for representing our mazes.

www.linuxformat.com


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.