How are rich UI icon animations done? - user-interface

I have recently come across beautiful icon animations in Apple's Home app. This is example of opening/closing garage doors: https://giphy.com/gifs/0it1uTDtVR1Uw1FByx
I wonder how to make these animations. There are ways I can think of:
Manually creating shapes and animating them in code (this would be so hard to do)
Using some animation tool and exporting *.gif frames (but in this way we will lose vector graphics)
Using some animation tool and exporting *.svg frames (is this efficient?)
Using some animation tool that will generate code (for example JS/CSS) with all the shapes and animation (Does such tool/program exist?)
Does anyone have experience with creating this type of animations? It would be great if you could share this experience :)

Obviously no answer will be exhaustive. Pure "CSS3 art" is route that I've seen people use because it can define complex geometry and animations precisely. But here are some ways I've looked into using SVGs.
You can actually embed a script tag in an SVG that animates the elements. Something like this:
<svg>
<!-- svg objects -->
<script><![CDATA[!
//... Javascript to animate svg objects...
]]></script>
</svg>
You can also use a library like snapsvg.io where the construction of an animated svg is done purely with JavaScript. Here's the example they use for their quickstart page:
var s = Snap("#svg");
var bigCircle = s.circle(150, 150, 100);
bigCircle.attr({
fill: "#bada55",
stroke: "#000",
strokeWidth: 5
});
var smallCircle = s.circle(100, 150, 70);
var discs = s.group(smallCircle, s.circle(200, 150, 70));
discs.attr({
fill: "#fff"
});
bigCircle.attr({
mask: discs
});
smallCircle.animate({r: 50}, 1000);
Otherwise you can use a codeless animated-svg creator like this one.
Disclaimer: I haven't tested the codeless site past the demo plan and probably will never use it. My personal preference would probably be the first suggestion but a JavaScript library like snapsvg.io seems like a nice middle ground.

I would go with option 4. Using some animation tool that will generate code (for example JS/CSS) with all the shapes and animation
I think it can be done with a tool called lottie, which uses json file exported by AfterEffects plugin called bodymovin.
Lottie web docs

Related

simple vector graphics + animation DSL

I'm looking for a vector graphics format that supports simple animations. At first I thought SVG would be the best. But SVG animation doesn't have any support in libraries. Is there some other format that would be useable for this?
I would like to have a Rust library, but have no problems writing an FFI to a C or C++ library either.
Any tips are welcome.
SVG's have some cool animation capabilities, i.e. transform: matrix() attribute + CSS transitions. My personal webpage in my profile has an example SVG I animated using CSS.
Here is some material I have gathered, I'm not sure of any other libraries though. The Three.js link has tons of additional info. Hope this helps.
Greensock Library
-- Greensock Animation Platform (GSAP) is a suite of tools for scripted animation. GSAP animates anything JavaScript can touch; i.e. CSS , SVG, React, & canvas. Overall, GSAP can manipulate property values at high speeds, which is one of the core techniques involved in CSS based transitions.
Aframe.io
-- A-Frame is a web framework based on Three.js for building virtual reality (VR) experiences. In addition to animation it features many other components and customizations.
Boxy SVG
-- Manipulate SVGs in a browser editor, with tutorials and more.
Gif.js
Vectr and Pixlr
Three.js Libraries & Plugins
Three.js WebGL
Lastly, two really cool sites I have found using WebGL/Three.js/SVG animation:
Interactive Example 1
Interactive Example 2
To your question/request..
"..I would like to have a Rust library, but have no problems writing
an FFI to a C or C++ library either."
I would recommend, a couple of nice options using Rust, C or C++.
The approach I took/recommend was 2 steps: first using Resvg to interact with the SVG, and then used another lib to animate.
Option 1:
please check out popular Resvg is a great lib Link, and github 1300 stars
Option 2:
please check out UX-Animate, which also has Rust apps & samples
// Scaling example in rust
use ux::prelude::*;
use ux::{Surface, Window};
#[derive(Default, Application)]
struct Application {
window: Window,
}
impl Application {
fn new() -> Self {
let app: Self = Default::default();
app.window
.set_window_size(512, 512)
.set_title("UX Framework - Scaling")
.show()
.connect_destroy(move |_win| Application::quit());
app.window.set_background_color(Some(color::GRAY_9));
let surface = Surface::new();
surface.set_size(400.0, 400.0);
// we should also change surface content size to avoid distortion
surface.set_content_size(400.0, 400.0);
surface.set_position(56.0, 56.0);
app.window.set_child(&surface);
surface.connect_draw(move |_widget, ctx, width, height| {
ctx.clear_rect(0.0, 0.0, width as f64, height as f64);
ctx.set_fill_color(color::TEAL_9); // Fill color
ctx.begin_path();
ctx.rect(10.0, 10.0, 90.0, 90.0);
ctx.fill();
ctx.scale(0.6, 0.6);
ctx.set_fill_color(color::ORANGE_9); // Fill color
ctx.begin_path();
ctx.rect(30.0, 30.0, 90.0, 90.0);
ctx.fill();
ctx.scale(0.8, 0.8);
ctx.set_fill_color(color::INDIGO_9); // Fill color
ctx.begin_path();
ctx.rect(50.0, 50.0, 90.0, 90.0);
ctx.fill();
false
});
app
}
}
fn main() {
Application::run();
}

Using D3 axis functionality on a canvas

I'm trying to draw an axis on a canvas using D3 functionality (as exampled here https://www.tutorialsteacher.com/d3js/axes-in-d3). However every example I've seen is using an SVG while I wish to use canvas. On the other hand I didn't see any indication, in their documentation or elsewhere, that it can't be done in canvas.
Is it possible? If so, how?
In short: no, that's not possible.
D3 is pretty much render agnostic, meaning it can be used to create SVG, Canvas, other HTML elements etc. However, some modules are indeed quite specific, and that's the case of d3-axis.
If you have a look at d3-axis source code you'll see that it append SVG <path>, <line> and <text> elements for creating the axis. For instance:
path.enter().insert("path", ".tick")
Finally, here you have a discussion on this subject, where Bostock (D3 creator) abandons the idea of modifying the d3-axis module for creating axes on HTML canvas.

How to create SVG's with the stroke property?

I've been using a combination of Illustrator, Sketch, Inkscape, and Peter Collingridge's svg-editor to create and manipulate SVG's, but I've been running into a few issues. I am trying to create a basic logo using text, and when the logo appears on the page I would like to animate the outside border (with a drawing effect), and then fill the centers with a solid color.
In Illustrator and Sketch, I started with a basic text box and converted the layer to outlines, but my exported SVG's only contain a single path without the stroke and stroke-width fields. It just looks something like this: <path fill="#FFF" d="…"/>, with alot of markup in the d='' field.
I read up and learned Inkscape exports some of the cleanest SVG's, so imported a PNG of my initials, "traced a bitmap image" and the "ungrouped the layers" per this demo. This exported a multi-path svg, but each still lacked the stroke and stroke-width params. This is the closest I've come so far to animating it: codepen.io/pcooney10/pen/PPvGrx, and it also contains the actual SVG code.
I have a few questions, hopefully some people over here can help:
How can I create/export SVG's that contain stroke, stroke-width, stroke-dasharray, and stroke-dashoffset fields? These params seem to unlock a lot of animation functionality,and my paths only seem to have fill='' and d=''.
Generally, what's the best tool for creating SVG's? It seems Inkscape exports the cleanest SVG code, but it's not as easy to maneuver as Sketch and Illustrator. Peter Collingridge's svg-editor seems to be the best for slimming down the code, but it doesn't remove all of the styling that Sketch and Illustrator embed in the file.
You complain of your SVG as containing "d" operations. But this is a powerful notation which draws your letters! You can use this as a start for animation.
Idea: just use Inkscape.
Enter your text. Make it just the way you wish it to appear. Click Menu > Path > Object to Path. This converts it from font-based to vector-based.
Click Save As... and choose the plain SVG format.

How to create scaleable svg animations?

Consider creating an SVG animation: a rectangle move into the scene from left side of the svg image and move out from right side and this is a loop.
(And i don't what to use canvas libraries or any javascript code).
[1] Is it possible to create this simple animation with any application (just like flash but with svg export) (I know Adobe Illustrator let us export vectors but not sure about animating theme).
[2] Also as SVG is vector based i intend to make this svg animating fluid (setting the width of svg to 100% an content scale automatically) is it also possible?
(I know how to do such these things using canvas libraries like snap.svg kinetic ... with bunch of js code i'm looking for some GUI App which let a graphic designer having no idea what JS is do it like Adobe Flash for example).
Any solution?
I am not sure about GUI App but fluid animations are possible. Look at the following elements: animate, animateMotion, animateTransform, animateColor.
Here are some examples and documentation:
MDN: animate, animateMotion
W3C

Region selection in canvas

I'm setting up an experimental html5 website using canvas.
I am drawing 3 circles all next to each other and all I want to know is how to be able to select them.
I'd like them to become links, in a way. Not tags, since everything's gonna be created using javascript.
Something like kinetic JS : http://www.kineticjs.com/, but without the extra library.
I have found some scripts that are using ghost canvas and contexts, but the examples are for dragging and stuff. I only want to be able to select my shape and execute some code.
Thank you!
I am thinking you might want to look into the IsPointInPath() method. It will help you figure out whether or not the mouse clicked on your canvas object.
See Detect mouseover of certain points within an HTML canvas?
if you are talented in xml i suggest you to use canvas + SVG (http://www.w3schools.com/svg/)
And follow this simple example.
http://jsvectoreditor.googlecode.com/svn/trunk/index.html
regarding to SVG and Canvas , the differences are obvious, as you can load bitmaps in SVG, and you can draw lines using the canvas API. However, creating the image may be easier using one technology over the other, depending on whether your graphic is mainly line-based or more image-like.

Resources