Getting Started With WebAssembly
An absolute beginner's guide to WebAssembly in which we write some C code, compile it to wasm, and then run it in the browser.
Continue reading on Tutorialzine.An absolute beginner's guide to WebAssembly in which we write some C code, compile it to wasm, and then run it in the browser.
Continue reading on Tutorialzine.Кotlin is a modern programming language that runs on the Java Virtual Machine. It has an elegant syntax and is interoperable with all existing Java libraries. In the 2017 Google I/O, the Android team announced that Kotlin will become an official programming language for the Android platform. This puts Kotlin in position to become one of the top programming languages of the future.
To help you get started with your Kotlin journey, we’ve curated a list of some of the best Kotlin learning resources available right now. We haven’t included any paid courses or books, everything on the list is 100% free.
The official website for the project is a very good place to start your Kotlin education. In the reference section you can find in-depth documentation that covers all the main concepts and features of the language. The tutorials section has a variety of practical step-by-step guides on setting up a working environment and working with the compiler.
There is also the Kotlin editor, a browser app that let’s you try out the language. It is loaded with many examples including the Koans course – by far the best way to get familiar with the syntax.
An excellent 11-part series by Juan Ignacio Saravia in which he puts Kotlin into action and builds a Reddit clone app. The tutorials cover a vast number of topics ranging from setting up the workspace to using APIs and even unit testing. The code is available on GitHub.
Antoni Leiva’s blog is dedicated to all things Kotlin. It is updated weekly(ish) with high-quality tutorials and articles in which more advanced Kotlin developers can learn about new libraries and find all kinds of practical techniques.
The official Google blog post that explains the reasons behind the exciting announcement and why Kotlin deserves a place in the Android ecosystem. The article then goes on to give a brief preview of some of the awesome syntax improvements that Kotlin brings.
Dariusz Baciński has created a useful GitHub repo containing common design patterns implemented in Kotlin. There are similar projects written in several languages including Java, Swift, JavaScript, and PHP, so if you are coming from one of these programming background you can use them as a reference point.
A quick cheatsheet with some of the most important features and syntax quirks that will help you write better Kotlin code. There are examples on working with classes, loops, and lists, as well as implementations of classic programming problems such as generating a Fibonacci sequence.
The official blog for Kotlin by its authors at JetBrains. Here you can find all Kotlin related news and updates, as well as all kinds of tutorials, tips, and other useful articles.
A helpful article from the Google Developers blog that explains how to setup Android Studio for Kotlin, how to convert .java files to .kt files, and how to incorporate the new language into an existing Android project. There are also some code comparisons on the same Android APIs used with both Kotlin and Java.
Great article that shows us how to write and run tests for Android apps using Kotlin. The author does a great job of explaining what different types of tests are available, when to use them, and how to make sure we are testing properly. Another good tutorial on this topic can be found here.
A talk from Google I/O 2017 dedicated to introducing Kotlin to people for the first time and giving them an idea of how it can improve their workflow. It covers many of the basics and showcases some cool Kotlin tips.
The second Kotlin talk from Google I/O 2017. This one covers more advanced topics like design patterns, best practices, and other common principles. It also sheds some light on what it is like to use Kotlin in production and the challenges of adopting a young language in the workplace.
Here is a free Kotlin course for complete beginners that includes all the basics from variables to conditionals to loops and functions. It then goes on to more advanced topics like object-orientation in Kotlin and functional programming like lambda expressions.
This talk from 2016 consists of a brief overview of the language’s features followed by a real world example where you’ll learn how Kotlin fits in with the existing tools in a typical Android workflow.
A very good 8-minute tutorial that quickly goes over the most important Kotlin features, such as the shortened variable declarations, lambdas, extension function, and more.
Introduction to Kotlin that explains how the new language will improve the Android ecosystem and shows us a number of cool ways we can use the smart Kotlin syntax to our advantage.
Useful cheatsheet containing short snippets of code that will help you quickly look up the Kotlin alternatives to common Java operators, functions, and declarations.
A plugin for IntelliJ IDEs that allows you to take the Koans course in a local offline environment.
Kotlin has been open-source for more than 5 years and there is a GitHub repo containing the entire history of the project. If you want to support the language there are multiple ways you can contribute, be it directly or by working on the docs.
Template Android project that makes it super easy to setup a stable Kotlin workspace and quickly bootstrap your apps.
An extensive list of Kotlin resources containing all sorts of useful links, books, libraries, frameworks, and videos. The list is very well organized, with a stylized version also available at kotlin.link.
Adding animations to web interfaces makes pages and apps feel more responsive and interactive. A side menu that smoothly slides out of view provides a much better user experience then a menu that just disappears when you close it.
So far creating web animations was done either via CSS transitions, CSS keyframes, or an external library such as Animate.css or Velocity. Thanks to a new native JavaScript API, we are now able to freely animate any HTML element without ever having to leave our .js file.
To showcase the awesomeness of the new API, let’s build a super simple example, once the old-fashioned CSS way, then with JavaScript Web Animations.
The editor below contains two HTML divs that when clicked on move to the right and then change their color. The square is animated via CSS @keyframes
, and the circle via the Web Animations API.
(Play with our code editor on Tutorialzine.com)
The @keyframes
animation should be familiar to most developers so let’s look at that first.
Our CSS animation is defined in a @keyframes
block that represents a timeline of all the transitions. Once we have our choreography defined, we can map it to a selector via the animation property and it’s options.
.animate { animation-name: move-and-change-color; animation-duration: 0.4s; animation-fill-mode: forwards; } @keyframes move-and-change-color { 0% { transform: translateX(0); } 80% { transform: translateX(100px); background-color: #2196F3; } 100% { transform: translateX(100px); background-color: #EF5350; } }
We want the animation to start on user interaction so we will also have to create an on-click event listener that adds a CSS class to the desired element:
var square = document.getElementById('square'); square.addEventListener('click', function() { square.className += " animate"; });
Although it works pretty well, the CSS approach seems rather non-intuitive as we define what happens in the stylesheets, but actually start it in the JavaScript. We also have very limited control over the animation once it has been invoked. Both these problems can be solved by switching to the Web Animation API.
We can describe our JavaScript animation using almost the exact same transitions we used in the CSS example:
var moveAndChangeColor = [ { transform: 'translateX(0)', background: '#2196F3' // blue }, { offset: 0.8, transform: 'translateX(100px)', background: '#2196F3' // blue }, { transform: 'translateX(100px)', background: '#EF5350' // red } ];
Each object in the array represents a state of the animation. The states are evenly distributed in time (3 states – 0%, 50%, 100%) unless we change the timing using the offset
option, as we’ve done with the middle state.
After we’ve defined our animation array, we can invoke it using the animate() method. It takes as a second argument an object with the same options as the CSS animation property, although with slightly different names (e.g. animation-fill-mode
is fill
, animation-iteration-count
is iteration
, etc).
var circle = document.getElementById('circle'); circle.addEventListener('click', function() { circle.animate(moveAndChangeColor, { duration: 400, fill: 'forwards' }); });
As you can see, the JavaScript approach is much more organized with the animation stored in a variable and the animate()
method used for invoking it whenever we need to.
The Web Animation API also makes it possible to easily control the playback of an animation in a number of ways. The animate()
method returns an Animation object which we can save in a variable and use to refer to that animation later on.
var animation = elem.animate(transitions, options);
The interface provides us with the following methods:
Below is a tiny demo with a loading indicator that loops infinitely. We’ve setup buttons for the different events so that you can try them out:
(Play with our code editor on Tutorialzine.com)
The Animation object returned from animate()
holds several useful properties that give us access to options like the current time, the playback rate, and others. Although some are read-only, most of the properties can be used as setters and getters.
You can view the JS code in the editor below to get a sense of how they work. For the full list of properties visit MDN.
(Play with our code editor on Tutorialzine.com)
In addition to that, the Web Animation API provides us with two useful event handlers for when the animation has finished or has been canceled:
spinnerAnimation.addEventListener('finish', function() { // Animation has completed or .finish() has been called. doSomething(); }); spinnerAnimation.addEventListener('cancel', function() { // Animation has been canceled. doSomething(); });
Most of the Web Animation features are freely available in Chrome and Firefox, with Edge and Safari implementations in the working (caniuse). There is also a well maintained open-source polyfill which can be used while waiting for full browser coverage.
When it comes to performance, there shouldn’t be any difference compared to regular CSS transitions, as browsers use the same engine for both. If you stick to animating only properties that don’t cause redraws, such as transform
and opacity
, animations should keep a steady 60fps rate.
The Web Animation API gives developers an awesome new way to create and control web animations using nothing but pure JavaScript. For animations that are invoked on user interaction or other dynamic events, this is great news since the whole animation can be done in the controller code, without having to jump to a CSS file for the actual transitions.
This article covered most of the features of the new API, but if you want to learn more here are a couple of excellent resources we highly recommend:
Today we’ve prepared for you five background images showcasing the power of modern CSS. They can be used as desktop wallpapers, eye-catching landing pages, and even as printed posters. In the article below we’ll also go over some of the key CSS techniques, so that you can customize them to your liking or make your own ones from scratch.
A Polyscape (poly = many, scape = scenery) is an image that contains multiple pictures mixed into one, creating very pleasing surrealistic visuals. Usually such design are made in Photoshop or other image editing software, but thanks to the ever growing arsenal of CSS properties, awesome polyscapes can now be created using nothing but simple web technologies!
You can view the designs in a demo app we created. The full source code plus all the polyscapes exported into HD images can be downloaded as a .zip archive from the Download button near the top of this page.
The demo uses some experimental CSS properties which might not work in all browsers. For the full experience, it’s best to open it in Chrome.
Making these polyscapes was very easy and we had a lot of fun in the process. For the backgrounds we used images from Unsplash. Everything else is done via various CSS shapes, transforms, and filters.
The designs use a variety of geometrical shapes made out of CSS. Here is how they are done:
height
and width
. To turn them sideways we use transform: rotate(45deg);
.border-radius: 50%;
to a square shape.clip-path
. We’ve recently wrote about this in detail in our article CSS Triangles Without Ugly Hacks. Check it out!Another interesting CSS shape we wanted to make is a square that is transparent inside but has an image as its border:
It turns out there is a CSS spec that does exactly that – it’s called border-image
and takes as parameters the path to an image, the border size, and how to place the image.
background: transparent; border: 25px solid transparent; border-image: url(clouds.jpg) 25 stretch;
Since we are adding images on top of an image background, in many cases we need to apply some filters to make the two views stand out. Most modern browsers freely support this feature under the filter
property.
It allows us to shift the hue from one color to another, boost the contrast, make everything black-and-white, and others. Here is a list of all the available CSS filters:
We can combine as many filters as we like until we get the desired result:
filter: hue-rotate(60deg) contrast(200%) blur(2px);
We hope you’ve enjoyed our little CSS experiment. The demo and all of the code is 100% free, and you have all rights to use, share, and change the designs (our license).