Wednesday, January 31, 2018

15 Fantastic Funk & Groove Music Kits for Your Next Project

5 Trending After Effects Projects for Creative Video (February 2018)

How to Draw a Bear

Code a Measuring App With ARKit

What Is Gulp?

Hotshots: Mystical Fairytale Forest Photograph

A Look Ahead: Web Design Predictions for 2018

18 Professional Business Resume Templates for 2018

Exception Handling in Laravel

Exception Handling in Laravel

In this article, we're going to explore one of the most important and least discussed features of the Laravel web framework—exception handling. Laravel comes with a built-in exception handler that allows you to report and render exceptions easily and in a friendly manner.

In the first half of the article, we'll explore the default settings provided by the exception handler. In fact, we'll go through the default Handler class in the first place to understand how Laravel handles exceptions.

In the second half of the article, we'll go ahead and see how you could create a custom exception handler that allows you to catch custom exceptions.

Setting Up the Prerequisites

Before we go ahead and dive into the Handler class straight away, let's have a look at a couple of important configuration parameters related to exceptions.

Go ahead and open the config/app.php file. Let's have a close look at the following snippet.

As the name suggests, if it's set to TRUE, it'll help you to debug errors that are generated by an application. The default value of this variable is set to a value of the APP_DEBUG environment variable in the .env file.

In the development environment, you should set it to TRUE so that you can easily trace errors and fix them. On the other hand, you want to switch it off in the production environment, and it'll display a generic error page in that case.

In addition to displaying errors, Laravel allows you to log errors in the log file. Let's have a quick look at the options available for logging. Again, let's switch to the config/app.php file and have a close look at the following snippet.

As Laravel uses the Monolog PHP library for logging, you should set the above options in the context of that library.

The default log file is located at storage/logs/laravel.log, and it's sufficient in most cases. On the other hand, the APP_LOG_LEVEL is set to a value that indicates the severity of errors that'll be logged.

So that was a basic introduction to the configuration options available for exceptions and logging.

Next, let's have a look at the default Handler class that comes with the default Laravel application. Go ahead and open the app/Exceptions/Handler.php file.

There are two important functions that the handler class is responsible for—reporting and rendering all errors.

Let's have a close look at the report method.

The report method is used to log errors to the log file. At the same time, it's also important to note the dontReport property, which lists all types of exceptions that shouldn't be logged.

Next, let's bring in the render method.

If the report method is used to log or report errors, the render method is used to render errors on a screen. In fact, this method handles what will be displayed to users when the exception occurs.

The render method also allows you to customize a response for different types of exceptions, as we'll see in the next section.

Finally, the unauthenticated method handles the AuthenticationException exception that allows you to decide what will be displayed to users in case they're unauthenticated to access a page they are looking for.

Custom Exception Class

In this section, we'll create a custom exception class that handles exceptions of the CustomException type. The idea behind creating custom exception classes is to easily manage custom exceptions and render custom responses at the same time.

Go ahead and create a file app/Exceptions/CustomException.php with the following contents.

The important thing to note here is that the CustomException class must extend the core Exception class. For demonstration purposes, we'll only discuss the render method, but of course you could also customize the report method.

As you can see, we're redirecting users to the errors.custom error page in our case. In that way, you can implement custom error pages for specific types of exceptions.

Of course, we need to create an associated view file at resources/views/errors/custom.blade.php.

That's a pretty simple view file that displays an error message, but of course you could design it the way you want it to be.

We also need to make changes in the render method of the app/Exceptions/Handler.php file so that our custom exception class can be invoked. Let's replace the render method with the following contents in the app/Exceptions/Handler.php file.

As you can see, we are checking the type of an exception in the render method in the first place. If the type of an exception is \App\Exceptions\CustomException, we call the render method of that class.

So everything is in place now. Next, let's go ahead and create a controller file at app/Http/Controllers/ExceptionController.php so we can test our custom exception class.

Of course, you need to add an associated route in the routes/web.php as shown in the following snippet.

And with that in place, you can run the http://your-laravel-site.com/exception/index URL to see if it works as expected. It should display the errors.custom view as per our configuration.

So that's how you are supposed to handle custom exceptions in Laravel. And that brings us to the end of this article—I hope you've enjoyed it!

Conclusion

Today, we went through the exception handling feature in Laravel. At the beginning of the article, we explored the basic configuration provided by Laravel in order to render and report exceptions. Further, we had a brief look at the default exception handler class.

In the second half of the article, we prepared a custom exception handler class that demonstrated how you could handle custom exceptions in your application.

For those of you who are either just getting started with Laravel or looking to expand your knowledge, site, or application with extensions, we have a variety of things you can study in Envato Market.

I would love to hear from you in the form of queries and suggestions!


Trend Watch: Retro 90s Design

A Beginner's Guide to Siri

New Short Course: Customizing WordPress With Child Themes

How to Adjust White Balance in Videos Using Adobe Premiere

How to Create a Vintage Photo Collage in Adobe Photoshop & Lightroom

Tuesday, January 30, 2018

10 Easy Instagram Promo Video Templates for Adobe After Effects

How To Create a Haas Delay In Ableton

How to Play the Piano Properly in a Rock Band

How to Create a Textured City Snapshot Illustration in Adobe Illustrator

Free Live Course: 15 Time Saving Shortcuts for Adobe XD

Bored at Work: How to Reclaim Your Time, Energy, & Attention

Get Started With Processing for Android

Histogram Equalization in Python

18+ Professional Business Project Proposal Templates for 2018

How to Create an Audio Oscillator With the Web Audio API

Bad Icon Design: 3 Pitfalls and How to Avoid Them

10 Amazing Photoshop Templates That Every Designer Should Own

Monday, January 29, 2018

How to Adjust Exposure: Video Image Correction in Adobe Premiere

15 Top Particle Effects Project Templates for Adobe After Effects (2018)

How to Apply Spot Fixes in Adobe Lightroom in 60 Seconds

Bootstrap 4 is Here! What’s New?

Overview of Wearable Development Platforms

Overview of Wearable Development Platforms

Technology is rapidly changing, and today's latest device becomes completely outdated in a flash. In such a dynamic and emerging tech environment, developers might get somewhat confused. We all want to find the best avenues to channel our learning and development efforts.

Many technologists believe that the golden age of smartphones is nearing its end. A whole new batch of hi-tech wearable devices are about to replace smartphones in the near future. What would these technologies and devices look like? Wearables can range in size from watches through to smart glasses and smart rings. Every day, they are becoming smaller in size and are boosting their performance too.

These devices have already started to redefine user interaction patterns, user behaviour, and sometimes even the user's lifestyle. In this article, you'll learn about the latest emerging wearable device platforms for which you could develop apps.

1. Smartwatches

Although smartwatches are the obvious next step, it took a while for them to challenge the dominant position of smartphones. That was mainly due to interaction problems associated with the small screen size and poor battery life. 

Most smartwatches started out as a "companion" to a smartphone. However, things are changing really fast. Several standalone smartwatches that don't need to pair with a smartphone are available now. The latest innovations have enhanced and refined the user interaction and user experience to a great extent.

If you want to develop for a smartwatch platform, you might consider one of the following.

1.1 Android Wear

Android Wear is one of the leading smartwatch platforms. Its latest version, Android Wear 2.0, has eliminated many problems of the previous versions and comes with some really cool features. The smartwatches powered by this platform can now function as standalone devices, meaning that they don't have to rely on a smartphone anymore. The UI has become more refined, more readable, and easier to navigate than ever before. It also features a full QWERTY keyboard so that the user can type on the device itself. The coolest thing is that it can directly access the Google Play store, without relying on a smartphone for the connection. 

So it's clear that Android Wear offers great opportunities for developers to explore. You could start developing either watch faces or other Android Wear apps. You are free to experiment with a broad range of supported sensors, including Bluetooth, WiFi, LTE, GPS, NFC, and the heart rate sensor. Android Wear 2.0 now even supports third-party input methods. So if you've been thinking of developing an innovative soft keyboard for the watch, this may be the time for it.

1.2 Apple Watch

Apple Watch's latest model, Series 3, has two variants. Only one has the optional LTE cellular connectivity, but both are equipped with onboard GPS. While one of them permits a standalone mode, both are optimized to be used together with a smartphone. You could come up with some weird and innovative app ideas to make use of the built-in GPS, LTE connectivity, altimeter and Siri, the voice assistant. 

Apple has also recently released watchOS 4, the latest version of its wearable OS. They have also fixed some bugs and issues, especially related to LTE connectivity. You don't have to worry much about linking it to the external world and can focus more on your app development business.

1.3 Samsung Gear S Series

While Tizen isn't as popular as Android or iOS among smartphone users, it's really a big name in the smartwatch sector. The Samsung Gear smartwatch, powered by Tizen OS, has the second largest market share in this sector. 

You should take into account the unique features of the watch when you're developing apps. These features include speech to text, GPS, in-app purchases, and a special UI element called Widget that provides easy access to frequently used tasks. The latest version is the Gear S3, and that too can be used as a standalone device. You just need to use Tizen Studio to make your app idea a reality.

2. Fitness & Activity Trackers

Some of the tech vendors have created wearables that cater to the specific needs of certain niches, rather than trying to build miniature smartphones. One such niche market consists of athletes, sportspeople, and outdoor adventure lovers. 

Wearables catering to this sector don't try to replace their users' smartphones. Instead, they're more likely to replace their regular wristwatches. These devices provide more accurate feedback on the users' sports activities. Most of them have stripped down versions of OS and hardware features, so that they can focus on their specialized job. That has enabled them to dramatically improve their battery life too.

2.1 Fitbit

Fitbit is an activity tracker that doubles as a watch. It pairs with a smartphone to provide comprehensive reports of the user's workout performance. Users can set daily goals, such as the number of calories to burn, and then view their progress towards them over a period of time. Developing apps for the Fitbit is a breeze if you are experienced in JavaScript, CSS, and SVG. Fitbit OS is a clever piece of software that makes this fitness tracker really exciting and easy to use.

You could use Fitbit Studio, the official IDE for the Fitbit OS, to develop apps and clock faces. If you want to distribute your apps, you could do that too, by uploading them to the App Gallery.

2.2 Garmin

Garmin has a series of wearables aimed at athletes, workout addicts, and outdoor adventure lovers. Almost all of their devices come ready with GPS, heart rate monitor, and dozens of useful sensors and features.

You can use Garmin's Connect IQ SDK and select from a number of APIs such as Health API, Connect API and various others to develop apps. The developer website is full of additional tools and resources such as GIS software, digital map datasets, and a lot more.

2.3 Samsung Gear Fit

While Gear S is a full-featured smartwatch, Gear Fit is more inclined towards the fitness tracker market. You could use the same tools that you used for the Gear S, but the only thing is that you need to be aware of this one's unique role as a fitness tracker.

3. Smart Glasses

Smart glasses offer a unique experience that's completely different from all the hand-worn wearables. They don't isolate the user as much from the real world as VR headsets do, but rather mix with reality. They normally do this by adding a layer of information on top of the user's view of the real world.

These smart glasses can be used in a variety of situations ranging from general consumer apps to highly technical and industrial tasks. One great example is for equipment repairs. The technician could see the actual equipment through the smart glasses, and an AR app would provide more assistance by identifying all the parts the technician touches and displaying information about them in an overlay.

3.1 Epson Moverio

Epson was a pioneer in this sector, and its latest Moverio models include Moverio BT-300, BT-350, and BT-2000 Pro versions. Although they don't support cellular data connectivity, you can use the built-in Wi-Fi or Bluetooth to connect them to any supported device.

Epson's smart glasses use Android OS and are packed with a number of sensors such as GPS, geomagnetic sensor, accelerometer, gyroscope, and illumination sensor. Now you too can become an AR app publisher, by registering on their developer website and using the Moverio SDK plus the optimized tools to create apps.

3.2 Daqri

Unlike Epson, which is more inclined towards consumers, Daqri focuses on enterprise clients. Its smart glasses and smart helmet are useful in a number of industrial and medical applications. The platform can provide real-time data visualization, job instructions, and remote expert assistance. You can download its SDK as an extension for Unity, and immediately start coding.

3.3 Sony SmartEyeglass

Sony SmartEyeglass is primarily aimed at developers who want to experiment with the latest AR apps. It has an embedded camera, microphone, accelerometer, gyroscope, compass, and brightness sensors. A layer of monochrome green text appears on its binocular see-through lenses, providing the user with information. 

These glasses need to be paired with a smartphone to function. Sony has also released an SDK, enabling developers to experiment with some cool app ideas.

3.4 Vuzix

Vuzix has a range of wearable products including smart glasses, smart sunglasses, and video headphones. They can cater to both consumers and professionals alike, and can cover a vast array of applications such as industrial, medical, retail, remote help desk, and a lot more. Be sure to register on the developer website and start developing after downloading the SDK.

4. VR Headsets

While VR headsets might make the wearer look ridiculous to others, they offer a truly immersive user experience that no other wearable can provide. Currently, the most promising applications are entertainment apps such as games, but there are many areas that could be explored. 

One such area is training simulations. Employers might make use of VR headsets and simulated virtual tasks to be accomplished by trainees. This helps reduce cost and get effective feedback on performance too. Immersive educational content is also sure to become a killer app.

Current VR headsets are packed with tons of sensors related to spatial, magnetic, optical and thermal data of the user's environment. They are capable of presenting the wearer with a real-world view, virtual-world view, or a combination of both. This makes them really powerful devices that can have a great impact on everyone.

Here are some of the most popular VR headset platforms.

4.1 HTC Vive

HTC's Vive VR headset comes with a complete set of accessories that help create realistic VR spaces called play areas. Users need to set up their headsets together with the accessories and define the play areas before using them. If you want to publish VR apps, just register as a developer on Vive's app store, Viveport, and start building new worlds using the Viveport SDK. The SDK supports several OS and game engine platforms, so you can choose the version that fits you best. You can publish your VR games on the popular SteamVR app store too.

4.2 Oculus Rift

Another leading platform in the VR space, Oculus offers a great VR experience and user interaction. Its SDK is also available in several packages, including the Platform SDK and utilities for Unity game engine. The popular game engine Unreal also offers built-in support for developing Oculus apps

4.3 Samsung Gear VR

Samsung Gear VR is not a standalone VR headset, but just a device holder for compatible smartphones that provide a VR experience. Samsung has produced it in collaboration with Oculus, and it supports Samsung's flagship handsets. The headset device acts as the controller, providing the optics as well as head tracking mechanisms, etc. It connects to the smartphone via USB and must be calibrated before use. Although setting up the development environment can be somewhat time-consuming, it's worth it to become a developer for one of the latest tech platforms available today.

4.4 Google Daydream View

Daydream View is also similar to Gear VR, but this one's clad in fabric and weighs much less than Samsung's device. Google has recently started collaborating with Lenovo on building a standalone VR headset, but that's yet to arrive. For the meantime, Google offers four SDKs for developers so that they can choose Android, Unity, Unreal, or iOS as their main development platform.

4.5 Sony PlayStation VR

Sony's VR headset also competes head to head with other popular platforms such as Oculus, but becoming a developer is relatively difficult. You need to be physically located in certain select countries, have a static IP address to access developer support, and submit your employer's tax ID number. This means that only corporate developers are allowed.

4.6 Windows Mixed Reality

While most of the other VR headsets rely on external sensors for motion tracking, Windows Mixed Reality headsets have all the sensors built in. So there's no need to set up spaces such as play areas (as in the case of HTC Vive), but this means the tracking capabilities are relatively limited. 

There are several vendors that manufacture Windows Mixed Reality headsets. Lenovo, HP, Samsung, Acer, and Dell are among them. There are tons of articles and other resources on the Microsoft HoloLens developer website to help you get up and running.

4.7 Google Cardboard

This the most low-tech item in an ultra hi-tech list: Google's attempt to bring the VR experience to the masses at a very low cost. The Google Cardboard device is actually made of cardboard, and holds a smartphone and plastic lenses to provide a VR experience. Google has also published a complete manufacturer kit so that developers can start building everything from scratch. The only thing that they need to buy is a smartphone and the lenses.

5. Smart Rings

Smart rings are perhaps the next evolution of smartwatches. As wearables become smaller and smaller, interacting with them poses a real challenge for developers. However, with the help of some unconventional interaction methods, such as gesture control, these can be solved. Below are two of the latest smart ring platforms.

5.1 Talon

Talon rings can connect to a range of devices from smartphones to tablets and smart TVs. Not only that, they can also be used as remote controls to switch on or off smart lights. A whole new world opens up when you think of the apps that can be created. You can control other devices or enhance the user experience of other apps. So just register as a Talon developer and request SDK access. You'll be creating amazing, futuristic apps in no time.

5.2 NFC Ring

The NFC Ring has a broad range of applications such as access control, data transfer, and payments. Really creative developers are free to come up with the coolest ideas and convert them into apps using the SDKs and other tools.

Conclusion

In this article we took a brief look at the latest and emerging wearable development platforms that are going to replace smartphones in the future. The technology is changing so fast that it's impossible to tell which one of these will actually dominate. So get out there and start experimenting!

While you're here, check out some of our other posts on smartwatch and wearable app development.

  • Android
    Google I/O 2017 Aftermath: What's New for Android Wear?
    Jessica Thornsby
  • Mobile Development
    WWDC 2017 Aftermath: The Most Important Announcements
    Bart Jacobs
  • iOS
    An Introduction to the UserNotifications Framework
    Davis Allie

We also have complete courses that will show you how to create a wearable app from start to finish for the popular Android Wear or Apple watchOS platforms.

  • Android
    Develop Apps for Android Wear
    Paul Trebilcox-Ruiz
  • watchOS
    Code a watchOS App With Swift
    Derek Jensen


How to Create a Surreal Broken Glass Effect in Adobe Photoshop

How to Cache Using Redis in Django Applications

How to Cache Using Redis in Django Applications

One of the ways to relieve strain on a server is by caching data. This is done by caching data after it has been processed and then serving it from the cache the next time it is requested. This tutorial will give a detailed discussion of Redis, explaining how to install Redis and cache data in Python applications.

Introduction to Redis and Caching

Caching refers to storing the server response in the client itself, so that a client need not make a server request for the same resource again and again. A server response should have information about how caching is to be done, so that a client caches the response for a time period or never caches the server response.

A cache, on the other hand, is a hardware or software component that is used to store data so future requests for the same data can be served faster.

In this age where users expect results within a second, it is wise to serve requests by reading data from the cache, which is ultimately faster than reading from a slower data store; thus, the system performance depends on how many requests can be served from the cache.

Redis is an open-source, in-memory data structure store, used as a database, cache, and message broker. It works by storing data in a cache and providing it the next time it is requested, instead of querying the database every time.

Install Redis

The first step is to get Redis up and running locally on your machine. The simplest way to install Redis is via the operating system’s package manager like so:

You can also follow the instructions from the official Redis site.

Download and extract Redis 4.0.6 tar as follows:

The binaries that are now compiled are available in the src directory. Run Redis with:

You can interact with Redis using the built-in client:

To check if the redis server is running, issue the following command on the terminal:

Django API Example

Let's create our Django project. Our project will be able to cache all the products in a store, making it easy and fast to retrieve data in subsequent queries.

To make use of Redis in our app, we need to do the following:

  1. Check if results for the current query exist in the cache.
  2. If results exist in the cache, retrieve them.
  3. If results don't exist, fetch them, store them in the cache, and then forward them to the requesting entity.

Requirements

  • Django
  • django-redis
  • Redis
  • loadtest

Create Your Project

Before we get started, create a directory and install a virtual environment. A virtual environment will let you install library versions required by your application.

Next, activate the virtual environment and install the project requirements.

Create a Django Project

Create a new app called store, which will handle product management in our store.

Add the store application and rest_framework to the list of installed apps in the settings.py file.

Creating the Models

In store/models.py, we start by creating the Product model for storing the product details as follows:

Migrations

Create an initial migration for our products model, and sync the database for the first time.

Create superuser

Create a superuser, log in to the admin panel, and populate your database with some sample data which we will use to do our tests.

Configuring Redis in Python Applications

In order to use Redis with a Django application, we need to set up Redis to store the application’s cache data. And the following to your settings.py file:

Next, we are going to create an endpoint that retrieves all the products from our database. We will first test the performance of the application in terms of how long it takes to retrieve data from the database without caching it. We will then implement another endpoint that retrieves data from a cache and compare the performance.

In store/views.py, add the following code which retrieves all the products present in the database.

Configuring URLs

Create a file store/urls.py and add the following code.

We also need to import URLs from the users application to the main django_cache/urls.py file.

Let's do a test and see if we are on track. We will be using loadtest. If you are not familiar with loadtest, it's a tool for testing performance.

Installing loadtest as root is simple:

As seen from the above, 55 requests are processed per second.

Let's create another endpoint for retrieving data after caching with Redis. Edit users/views.py to match the following:

The code above will check if the key product is present in the cache, and if found, the data represented will be returned to the browser. In the event that no data is present in the cache, we first retrieve the data from the database, store it in the cache, and then return the data queried to the browser.

Update store/urls.py as follows.

Let's carry out the tests.

The first time you hit the endpoint localhost:8000/store/cache, the application will query from the database and return data, but subsequent calls to the URL will bypass the database and query from the cache since the data is already available in the cache.

Conclusion

In this tutorial, we used Redis to give an application the illusion of speed. We leverage the use of RAM in Redis to store the results of queries and then return those results from the cache in subsequent queries rather than doing the round trip to the database.

There are other caching tools available, such as Memcached, which is similar to Redis. However, Redis is more popular than Memcached because it takes only a few minutes to set up and get working in applications. Redis has more sophisticated mechanisms as it has been described as a "data structure store", thus making it more powerful and flexible. Redis also has a larger advantage because you can store data in any form.

Hopefully, this tutorial has shown you how easy it is to add a caching layer to your application, hence improving performance. Caching must be something to consider when you need to reduce loading times and server costs.


How to Insert Images into Excel in 60 Seconds

Creating a VR Game in Unity

How to Draw a Rabbit Step by Step

Sunday, January 28, 2018

Faking Keyboard Parts On Guitar, Part 3

Faking Keyboard Parts On Guitar, Part 3

In Part 2 of this series, I covered a range of different analogue and iOS options suitable for creating keyboard sounds on guitar.

There’s a third way, however, that introduces the convoluted, technical world of MIDI.

In The Beginning…

MIDI stands for Musical Instrument Digital Interface. Introduced to the public in 1983, its basic function is to pass information such as note pitch, velocity, duration and so on from the controller—guitar, in this case—to the sound module such as synthesisers, samplers, and so on). 

Unlike conventional audio, event messages produce no sound of themselves serving as a set of instructions to trigger the sound module.

So far, nothing here to interest guitarists.

However, MIDI goes beyond simply being just a trigger for notes; indeed, its ability to manipulate whole hosts of variables via anything MIDI-compatible means you aren’t just limited to keyboard sounds. 

For a band or artist needing a broad palette of tones, it’s worth investigating. Here's some examples of a typical set-up.

Getting Started

You’ll need a guitar. This means either buying a MIDI-enabled guitar or fitting an existing one with a MIDI pickup. You’ll also need an appropriate sound module otherwise you won’t hear anything.

Unsurprisingly, this is the most difficult and expensive route to take so be warned.

MIDI-Enabled Guitar

Buying new presents few choices, but the Godin xtSA (£900) is probably the most versatile. Equipped with standard magnetic (electric) and piezo (acoustic) pickups (meaning that it functions just like a regular guitar), it’s also compatible with any MIDI device that uses 13-pin connectors.

Going secondhand, look for the Fender GK Ready Stratocaster, which has Roland’s GK-3 pickup and controls built into what’s otherwise a regular Strat.

MIDI Pickup

If you don’t want, or can’t afford, a dedicated MIDI guitar then a regular guitar can be modified by adding a MIDI pickup.

Incidentally, this isn’t just electric guitars—I’ve had MIDI pickups on acoustics as well. 

MIDI pickups are usually hexaphonic—six individual pickups in one, that treats/processes each string separately. Not only affording better clarity, it allows you to assign different events to individual strings. For example, each string could trigger a part of a drum kit.

The most famous example is Roland’s GK-3 (£150). Mounted behind a bridge pickup, it’s connected to a controller attached behind the bridge, allowing you to swap between the MIDI pickup and your regular pickups (you can plug your guitar’s usual cable into it), or have both on simultaneously. 

You also have a MIDI volume control, as well as up/down buttons for remotely scrolling through your sound module’s patches.

It’s not permanent (unlike MIDI-enabled instruments), but’ll involve drilling a few holes. It’s also not the prettiest addition to your guitar, and needs careful setting-up—if the pickup’s installed incorrectly you’ll get poor results.

Get Connected

Whatever you choose, you’ll need to run a MIDI cable between the guitar and your sound module of choice. It’s thicker than an audio cable, so be careful, and make sure it’s long enough for your needs. It can also be more expensive than a regular guitar lead, so shop around. 

Check the relevant connectors at both ends—instrument and sound module—are correct. Like so many devices, more than one connection option has passed into usage so ensure you’ve got the right one.

Going Wireless 

If long, bulky cabling sounds off-putting, there’s a potential solution. A relatively newcomer, Fishman's Triple Play (£300+ - prices vary) features a pickup and controller similar to the GK-3 albeit smaller, but uses wireless connectivity, thus dispensing with bulky MIDI cables, and giving it greater range with claims of up to 100ft.

The smaller physical footprint of the better-looking controller, plus the wireless connectivity, make it an attractive alternative. There are, however, some issues to bear in mind.

It’s at least twice as expensive as the GK-3. Its wireless operation means no cabling to power it, unlike the GK-3, so it uses an onboard lithium ion battery with a claimed life of 20 hours. That's more than enough for a gig.

However, the biggest drawback for the gigging guitarist is it only works with DAWs and Virtual Instruments, meaning you can’t use a hardware sound module; you’d need a laptop or an iPad with a USB adaptor. These are, of course, achievable but it’s even more equipment and cabling to consider, buy and transport.

Sound Modules

An essential part as no sound module means no sound. 

For the gigging guitarist, foot-operated pedals are more practical, and their architecture’s akin to multi-fx units, which many guitarists are already familiar. They offer a range of output connections, so you can easily plug them into an amp or PA.

Just as Roland makes the GK-3, they make a whole host of compatible sound modules, so look for what best suits your needs. 

Their current flagship is the GR-55, that covers all manner of instruments real and imagined, plus regular electric and acoustic sounds—in fact, it could replace your usual pedalboard, and even amp. 

It’s not cheap at £460, but you could save £80 if you buy the GR55GK, which includes the required GK-3 pickup.

As a cheaper option, look on eBay for the GR-20; as an older model, you could pick it up for a lot less, and it’s still an excellent piece of kit.

Conclusion

MIDI is both complicated and expensive, but with a bit of work, can open up a world of sonic possibilities. Remember, you’ll need:

  • A MIDI-enabled guitar
  • Failing that, a MIDI pickup, such as the Roland GK-3
  • A sound module, such as the GR-55
  • Check for compatible cable and connectors
  • Wireless connectivity is now an option
  • Be prepared to spend a lot of money
  • The secondhand market’s a cheaper way to get started

Thursday, January 25, 2018

Top 5 New After Effects Items for Creative Video Projects (January 2018)

How to Code a Bottom Navigation Bar for an Android App

How to Create a Romantic Wedding Photo Manipulation in Adobe Photoshop

Beginner's Guide to Angular 4: HTTP

How to Make Winning Pitch Decks (With PowerPoint Templates)

How to Create Flat Bride & Groom Characters in Adobe Illustrator

New Coffee Break Course: How to Use a Custom Campaign Monitor Template

Getting Started With the App Store

Create a Rainy Scene Animation Using Default After Effects Plugins

Wednesday, January 24, 2018

Video Lighting On-Location: How to Use Direct Sunlight

How to Decorate Photos for Instagram With Drawings: Photoshop in 60 Seconds

Get More Installs and Better Ratings for Your Apps Using Instabug

Rapid Web Deployment for Laravel With GitHub, Linode, and RunCloud.io

How to Make an Unbounce Landing Page Quickly

Beginners Guide to Angular 4: Routing

How to Create a Pastel Neon Club Flyer in Adobe InDesign

Getting Started With Cloud Firestore for Android

How to Build an Off-Canvas Menu With CSS and a Touch of JavaScript

Tuesday, January 23, 2018

How to Create a Glittering, Festive, 3D Text Effect in Adobe Photoshop

Learn Something New: Master These Trending Topics for 2018

How to Draw a Celebrating Sporty Character in Adobe Illustrator

18+ Best Responsive HTML5 Landing Page Templates (2018)

Beginner's Guide to Angular 4: Services

Git Version Control on the Command Line for iOS Devs

Checklist: Ways to Enhance Your Onboarding Experience

18 Best New Event Flyers for 2018

Friday, January 19, 2018

International Artist Feature: Croatia

Building Games With Python 3 and Pygame: Part 5

Building Games With Python 3 and Pygame: Part 5

Overview

This is part five of a five-part series of tutorials about making games with Python 3 and PyGame. In part four we detected collisions, responded to the ball hitting various game objects, and created a game menu with custom buttons. 

In this last part, we'll cover diverse topics such as the end game, managing lives and score, sound effects, music, and even a flexible special effects system. For dessert, we'll discuss potential improvements and future directions.

The End Game

Eventually, the game has to end. In this version of Breakout, the game ends in one of two ways: either the player loses all their lives or they hit all the bricks. There is no next level (although it would be easy to add).

Game Over!

The game_over field of the Game class is set to False in the __init__() method of the Game class. The main loop goes round and round until the game_over variable is set to True:

That all happens in the Breakout class in the following cases:

  • The player clicked the QUIT button from the menu.
  • The player loses their last life.
  • The player cleared all the bricks.

Display the End Game Message

Usually, when the game ends, we don't want the game window to just disappear into thin air. The exception is if you clicked the QUIT button in the menu. When the player loses their last life, Breakout displays the traditional 'GAME OVER!' message, and when the player wins, it displays 'YOU WIN!'

The show_message() function is used in both cases. It displays the text on top of the current screen (the game will be paused) and waits for a few seconds before returning. In the next iteration of the game loop, the check for the game_over field will determine it is True, and the program will exit. 

Here is the show_message() function:

Keeping the High Score Between Games

In this version, I don't keep the high score because there is just one level, and everybody's score will be the same if they clear all the bricks. In general, it can be done locally by storing the high score in a file and then displaying another message if the player broke the high score.

Adding Sound Effects and Music

Games are an audio-visual experience. Most games have sound effects that are short sound bytes that are played when the player kills a monster, finds some treasure, or explodes horribly. Some games have background music too, which contributes to the atmosphere. Breakout has only sound effects, but I'll show you how to play background music in your games.

Sound Effects

You need sound files (similar to image files) to play as sound effects. These files can be in .wav, .mp3, or .ogg formats. Breakout keeps its sound effects in the sound_effects folder:

Let's see how these sound effects are loaded and played at the right time. First, to play sound effects (or background music) you need to initialize the sound system of Pygame. That happens in the Game class: pygame.mixer.pre_init(44100, 16, 2, 4096)

Then, in the Breakout class, all the sound effects are loaded from the config into the pygame.mixer.Sound object and are stored in a dictionary:

Now, we can play the sound effects when something interesting happens. For example, when the ball hits a brick:

The sound effect plays asynchronously, which means the game doesn't freeze while the sound is playing. Multiple sound effects can be played simultaneously.

Record Your Own Sound Effects and Messages

Recording your sound effects is both easy and rewarding. Unlike visual asset design, it doesn't take much talent. Anybody can say "Kaboom!" or "Boing" or shout "You're dead. Better luck next time!"

I often ask my kids to record sound effects as well as voice messages that accompany text messages like 'YOU WIN!' or 'GAME OVER!' Your imagination is the only limitation.

Playing Background Music

Background music should play constantly. In theory, you can have a very loooooooong sound effect, but a more common approach is simply to play the background music in a loop. Music files can be .wav, .mp3, or .midi format. Here is how it's done:

You can have only one piece of background music playing at a time. But multiple sound effects can play over the background music. That's what mixing is all about.

Adding Advanced Features

Let's get fancy. Breaking bricks with a ball is cool, but it gets old pretty fast. How about a generic special effects system? We'll develop an extensible system of special effects that are associated with certain bricks and activate when the ball hits the brick. 

Here is the plan. Effects have a lifetime. The effect starts when the brick breaks and ends when the duration of the effect elapses. What happens if the ball hits another special effect brick? In theory, you could have compounding effects, but to simplify things for the initial implementation, the active effect will stop, and the new effect will take its place.

Special Effects System

A special effect can be defined in the most generic way as two functions. The first function activates the effect, and the second function resets it. We want to attach effects to bricks and make it clear to the player which bricks are special, so they can try to hit or avoid them at certain points. 

The following dict from the breakout.py module defines our special effects. Each effect has a name (e.g. long_paddle) and a value, which consists of the color its brick will have as well as the two functions. The functions are defined as lambda functions that take a Game instance, which includes everything a special effect in Breakout may want to change.

When the bricks are created, they have a change to be assigned one of the special effects. Here is the code:

The Brick class has an effect field that is usually None, but can get (30% chance) one of the special effects defined above. Note that this code is unaware of what effects are available. It simply gets the effect and the brick color and assigns them if needed. 

In this version of Breakout, I trigger effects only when a brick is hit, but you can imagine other scenarios that could trigger events. The previous effect is reset (if there was one), and then the new effect is launched. The reset function and the effect start time are stored for later.

If no new effect was triggered, we still need to reset the current event when it expires. That happens in the update() method. In each frame, the reset function of the current effect was assigned to the reset_effect field. If the time since the current effect started exceeded the effect duration then the reset_effect() function is called and the reset_effect field is set to None (meaning there is no active effect right now).

Enlarging the Paddle

The long paddle effect works by inflating the paddle by 50%. Its reset function just resizes it back to normal. The brick color is Orange:

Slowing the Ball

Another effect that helps with chasing the ball is the slow ball effect, which simply slows the ball speed by one unit. The brick color is Aquamarine.

More Points

If you want big numbers, you'll like the triple points effect that gives you three points for each brick you hit instead of the standard one point. The brick color is dark green.

Extra Lives

Finally, a very helpful effect is the extra lives effect. It just gives you an extra life. No reset is needed really. The brick color is gold.

Future Features

There are several natural directions to extend Breakout. If you're interested in trying your hand at adding more capabilities and features, here are some ideas.

Take It to the Next Level

To make Breakout a serious game, it needs levels. Playing just one screen is not enough. At the beginning of each level, you will reset the screen, but keep the score and lives as is. To make the game harder, you can slightly increase the ball speed on each level or add another layer of bricks.

Second Ball

Adding a second ball as a temporary effect is bound to create a lot of chaos. The tricky part here is to treat both balls as equal, regardless of which one was the original. When one ball is gone, the game continues with the single ball that was left. No life is lost.

Persistent High Score

When you have levels with increasing difficulty, the high score becomes a coveted prize. You can keep the high score in a file to persist between games. When a player breaks the high score, you can add a little pizazz or let them write their name (traditionally just three characters).

Bombs and Power-Ups

In the current implementation, all special effects are tied to bricks, but you can add effects (good and bad) that drop from the sky and the player has to collect them or avoid them.

Conclusion

Developing Breakout using Python 3 and Pygame was a super rewarding experience. It's a very powerful combination for 2D games (and 3D games too). If you like Python and want to make your own games, you can't go wrong with Pygame. 

I definitely plan to make more games with Python and Pygame.

Finally, remember we have plenty of Python content available for sale and for study in the Envato Market.



How to Create a Colorful Collage in Adobe Photoshop & Lightroom

How to Organize Your Outlook Email Inbox Efficiently

How to Code a Navigation Drawer for an Android App

Android Things: Adding Google Assistant

How to Create an Irish Door Illustration in Adobe Illustrator

Thursday, January 18, 2018

Hot Shots: Cool and Sleek, Tall Glass Office Buildings

How to Draw Furries, aka Anthropomorphic Characters

Design Patterns for Cocoa: MVC and MVVM

Building Games With Python 3 and Pygame: Part 4

Building Games With Python 3 and Pygame: Part 4

Overview

This is part four of a five-part series of tutorials about making games with Python 3 and Pygame. In part three, we dove into the heart of Breakout and learned how to handle events, met the main Breakout class, and saw how to move the different game objects.

In this part, we will see how to detect collisions and what happens when the ball hits various objects like the paddle, the bricks, the walls, the ceiling, and the floor. Finally, we will review the important topic of game UI and in particular how to create a menu with our own custom buttons.

Collision Detection

In games, things bump into each other. Breakout is no different. Mostly it's the ball that bumps into stuff. The handle_ball_collisions() method has a nested function called intersect(), which is used to test if the ball hit an object and where it hit the object. It returns 'left', 'right', 'top', 'bottom', or None if the ball didn't hit the object.

Hitting the Ball With the Paddle

When the ball hits the paddle, it bounces off. If it hits the top of the paddle, it will bounce back up but keep the same horizontal speed component. 

But if it hits the side of the paddle, it will bounce to the opposite side (left or right) and continue its motion downward until it hits the floor. The code uses the intersect function().

Hitting the Floor

When the paddle misses the ball on its way down (or if the ball hits the paddle on its side), the ball will keep falling and eventually hit the floor. At this point, the player loses a life, and the ball is recreated so the game can continue. The game is over when the player has run out of lives.

Hitting the Ceiling and Walls

When the ball hits a wall or the ceiling, it simply bounces back. 

Hitting Bricks

When a ball hits a brick, it's a major event in Breakout—the brick disappears, the player gets a point, the ball bounces back, and a few other things happen (sound effect and possibly a special effect too) that I'll discuss later. 

To determine if a brick was hit, the code checks to see if any of the bricks intersects with the ball:

Programming the Game Menu

Most games have some UI. Breakout has a simple menu that has two buttons that say 'PLAY' and 'QUIT'. The menu shows up at the beginning of the game and disappears when the player clicks 'PLAY'. Let's see how the buttons and menu are implemented and how they integrate with the game.

Making Buttons

Pygame doesn't have a built-in UI library. There are third-party extensions, but I decided to build my own buttons for the menu. A button is a game object that has three states: normal, hover, and pressed. The normal state is when the mouse isn't over the button, and the hover state is when the mouse is over the button but the left mouse button isn't pressed. The pressed state is when the mouse is over the button and the player has pressed the left mouse button. 

The button is implemented as a rectangle with background color and text displayed over it. The button also receives an on_click function (defaults to a noop lambda function) that gets called when the button is clicked.

The button handles its own mouse events and changes its internal state based on these events. When the button is in pressed state and receives a MOUSEBUTTONUP event, it means the player clicked the button, and the on_click() function is invoked.

The back_color property that is used to draw the background rectangle always returns the color that matches the current state of the button, so it's clear to the player the button is active:

Creating the Menu

The create_menu() function creates a menu with two buttons with the text 'PLAY' and 'QUIT'. It has two nested functions called on_play() and on_quit() that it provides to the corresponding button. Each button is added to the objects list (to be drawn) and also to the menu_buttons field.

When the PLAY button is clicked, on_play() is invoked, which removes the buttons from the objects list so they are not drawn anymore. Also, the boolean fields that trigger the start of the game—is_game_running and start_level—are set to True. 

When the QUIT button is clicked, is_game_running is set to False (effectively pausing the game) and game_over is set to True, triggering the end game sequence.

Showing and Hiding the Game Menu

Showing and hiding the menu is implicit. When the buttons are in the objects list, the menu is visible; when they are removed, it is hidden. As simple as that. 

It is possible to create a nested menu with its own surface that renders sub-components like buttons and more, and then just add/remove that menu component, but it's not needed for this simple menu.

Conclusion

In this part, we covered collision detection and what happens when the ball hits various objects like the paddle, the bricks, the walls, the ceiling, and the floor. Also, we created our own menu with custom buttons that we hide and show on command. 

In the last part of the series, we will look into the end game, keeping tabs on score and lives, sound effects, and music.

Then, we will develop a sophisticated system of special effects that will spice up the game. Finally, we will discuss the future direction and potential improvements.


How to Compose & Send New Emails With Microsoft Outlook

CSS Scroll Snap: What Is It? Do We Need It?

How to Draw a Wreath of Tropical Flowers in Adobe Illustrator

How to Do More With Photos in Apple Photos App: Part 4

Wednesday, January 17, 2018

5 Hot New Video Artists on Envato Market (January 2018)

How to Create a Wall of Lights Photo Effect: Photoshop in 60 Seconds

Free Live Course: 10 Essential Design Tips for Illustrator

Building Games With Python 3 and Pygame: Part 3

Building Games With Python 3 and Pygame: Part 3

Overview

This is part three of a five-part series of tutorials about making games with Python 3 and Pygame. In part two, we covered the TextObject class used to render text on the screen, created the main window, and learned how to draw objects like bricks, the ball, and the paddle. 

In this part, we will dive into the heart of Breakout and learn how to handle events, meet the main Breakout class, and see how to move the different game objects.

Handling Events

In Breakout, there are three types of events: key press events, mouse events, and timer events. The main loop in the Game class takes care of the key press and mouse events and delivers them to subscribers (by calling a handler function). 

While the Game class is very generic and has no Breakout specific knowledge, the subscription itself and how to handle each event are very specific.

The Breakout Class

The Breakout class is where most of the domain knowledge about the Breakout game is managed. We will meet the Breakout class several times during this series. Here are the lines that register the various event handlers. 

Note that all key events for both the left and right arrow keys will go to the same handler method of the paddle.

Handling Key Presses

The Game class will call the registered handlers for each key event and pass the key. Note that it doesn't the Paddle class. In Breakout, the only object that is interested in these events is the paddle. When a key is pressed or released, its handle() method is called. 

The Paddle doesn't need to know if it was a key down or key up event because it manages the current state through a pair of boolean variables: moving_left and moving_right. If moving_left is True then it means the left arrow key is pressed and the next event will be key up, which will release it. The same goes for the right arrow key. The logic is as simple as toggling these variables in response to any event. 

Handling Mouse Events

Breakout has a game menu you'll meet soon. The button on the menu handles various mouse events such as movement and clicks (mouse down and mouse up events). In response to these events, the button updates an internal state variable. Here is the mouse handling code:

Note that the handle_mouse_event() method that is registered to receive mouse events checks the type of the event and forwards it to the specific method that handles that event type.

Handling Timer Events

Timer events are not processed through the main loop. However, since the main loop is called every frame, it's easy to check if a certain timed event is due. You will see an example of this later when discussing timed special effects. 

Another situation is when we want to freeze the game—for example, when displaying a message that the player should be able to read without distraction. The show_message() method of the Breakout class uses this approach and calls time.sleep(). Here is the relevant code:

Gameplay

The gameplay part is where the rules of Breakout come to play (see what I did there?). Gameplay is about moving the different objects in response to the events and changing the game state based on their interactions.

Moving the Paddle

You saw earlier that the Paddle class responds to arrow keys by updating its moving_left and moving_right fields. The actual movement happens in the update() method. There is some computation going on here if the paddle is close to the left or right edge of the screen. We don't want the paddle to move beyond the edges of the screen (including a predefined offset). 

So if the movement would have taken it beyond the edge, the code adjusts the movement to stop exactly at the edge. Since the paddle is only moving horizontally, the vertical component of the movement is always zero. 

Moving the Ball

The ball just uses the functionality of the GameObject base class, which moves game objects based on their speed (with horizontal and vertical components). The speed of the ball is determined by many factors in the Breakout class that you'll see soon. Since moving is just adding the speed to the current position, the direction the ball is moving is fully determined by its speed along the horizontal and vertical axes.

Setting the Initial Ball Speed

The ball in Breakout appears out of nowhere at the beginning of the game every time the player loses a life. It just materializes out of the ether and starts dropping either straight down or at a slight angle. When the ball is created in the create_ball() method, it receives a speed with a random horizontal component between -2 and 2 and a vertical component, which is determined in the config.py module (currently set to 3). 

Conclusion

In this part, we covered event handling such as key presses, mouse movement, and mouse clicks. We also dove into some of the gameplay elements of Breakout such moving the paddle, moving the ball, and controlling the ball's speed. 

Remember also to see what we have available for sale and for study in the Envato Market if you're looking to study more Python-related material.

In part four, we will deal with the important topic of collision detection and see what happens when the ball hits various game objects like the paddle, bricks, and even the walls, ceiling, and the floor. 

Then we'll turn our attention to the game menu. We'll create custom buttons that we'll use as a menu we can show and hide as necessary.


7 Interactive Presentation Ideas to Engage Your Audience

Trend Watch: Floral, Tropical, and Botanical Design

Quick Tip: Get Free and Easy Mockups With “The Mockup Club”

Creating a Magnum Mecha Character in Maya: Part 1

How to Create an Easter Egg Flyer in Adobe InDesign

Tuesday, January 16, 2018

Creating Graphic Design and Illustration for Color Blind People

How to Use the Android ListView Component

Building Games With Python 3 and Pygame: Part 2

Quick Tip: How to Create a Monstera Leaf Pattern in Adobe Illustrator

18+ Modern Resume Templates With Clean (Elegant) Designs (2018)

Canny Edge Detector Using Python

20 Handy DuckDuckGo Cheat Sheets for Web Designers

Three Ways to Make Your Swift Code More Readable

New Web Design eBooks Available From A Book Apart

How to Create a Surreal Icy Fish Photo Manipulation With Adobe Photoshop

How to Create a Basic 3-Point Lighting Setup for Video

Thursday, January 11, 2018

How to Do More With Apple's Photos App: Part 2

Top 5 Video Artists on Envato Market This Month (January 2018)

15+ Best WordPress Event Themes: For Conferences and More

How to Use Shopify Themes to (Quickly) Make Online Stores

18+ Best Shopify Themes With Responsive Designs for 2018

How to Download Files in Python

How to Download Files in Python

Python provides several ways to download files from the internet. This can be done over HTTP using the urllib package or the requests library. This tutorial will discuss how to use these libraries to download files from URLs using Python.

REQUESTS

The requests library is one of the most popular libraries in Python. Requests allow you to send  HTTP/1.1 requests without the need to manually add query strings to your URLs, or form-encode your POST data.

With the requests library, you can perform a lot of functions including:

  • adding form data,
  • adding multipart files,
  • and accessing the response data of Python

MAKING REQUESTS

The first you need to do is to install the library and it's as simple as:

To test if the installation has been successful, you can do a very easy test in your  python interpreter by simply typing:

If the installation has been successful, there will be no errors.

HTTP requests include:

  • GET
  • POST
  • PUT
  • DELETE
  • OPTIONS
  • HEAD

Making a GET request

Making requests is very easy as illustrated below.

The above command will get the google web page and store the information in thereq variable. We can then go on to get other attributes as well.

For instance, to know if fetching the google web page was successful, we will query the status_code.

What if we want to find out the encoding type of the Google web page?

You might also want to know the contents of the response.

This is just a truncated content of the response.

Making a POST Request

In simple terms, a POST request used to create or update data. This is especially used in the submission of forms.

Let's assume you have a registration form that takes an email address and password as input data, when you click on the submit button for registration, the post request will be as shown below.

Making a PUT Request

A PUT request is similar to a POST request. Its used to update data.For instance, the API below shows how to do a PUT request.

Making a DELETE Request

A DELETE request, like the name suggests, is used to delete data. Below is an example of a DELETE request

urllib Package

urllib is a package that collects several modules for working with URLs namely:

urllib.request  offers a very simple interface, in the form of the urlopen function capable of fetching URLs using a variety of different protocols. It also offers a slightly more complex interface for handling basic authentication, cookies, proxies e.t. c.

How to Fetch URLs With urllib

The simplest way to use urllib.request is as follows:

If you wish to retrieve an internet resource and store it, you can do so via the urlretrieve() function.

Downloading Images With Python

In this example, we want to download the image available on this link using both the request llibrary and urllib module. 

Download PDF Files With Python

In this example, we will download a pdf about google trends from this link.

Download Zip Files With Python

In this example, we are going to download the contents of a GitHub repository found in this link and store the file locally.

Download Videos With Python

In this example, we want to download  the video lecture available on this page

Conclusion

This tutorial has covered the most commonly used methods to download files as well as the most common file formats. Even though you will write less code  when using  the urllib module, the requests module is preferred due to its simplicity, popularity and a wide array of features including:

  • Keep-Alive & Connection Pooling
  • International Domains and URLs
  • Sessions with Cookie Persistence
  • Browser-style SSL Verification
  • Automatic Content Decoding
  • Basic/Digest Authentication
  • Elegant Key/Value Cookies
  • Automatic Decompression
  • Unicode Response Bodies
  • HTTP(S) Proxy Support
  • Multipart File Uploads
  • Streaming Downloads
  • Connection Timeouts
  • Chunked Requests
  • .netrc Support