Canvas HTML5 animation with GSAP/d3.js - javascript

I want to create a HTML5 canvas animation likely the one on this site: https://flowstudio.co/.
I have started with GSAP, but it looks like creating something like this, is really a big task.
I have to create mostly every point/move singular and i have no idea if there is a faster/better way.
Currently i only have looked at GSAP without plugins.
Is there some special tool/(GSAP) plugin that can help to create this?
Or should i maybe use d3.js?
I also tried to find an tutorial for this, but it looks like there is nothing for this more advanced case.
Thanks for the help!

The example you provided is using THREE.js and I would suggest you to use it too since you want to operate in 3D space also.
When you want to animate a large ammount of points you will need to use a vertex shader. That's because vertex shader will allow you to calculate all of the points positions in one step (thanks to parallel computing on the GPU), whereas doing it the 'normal way' (on the CPU) is very bad on performance, since every single point has to be calculated one by one. (here you can see the difference)
The way you animate the points is a little different than you might think- you don't want to apply animation to every. single. point...
Instead you will need three things that you will pass to the shader:
-array containing starting points position,
-array containing final points position,
-blend parameter (just a float variable taking values from 0 to 1).
Then you use GSAP to animate only the blend parameter, and shader does the rest (for example when the blend parameter is 0.5 the point position is exactly halfway between starting position and final position that you provided to the shader)
The example you provided is also using some kind of Perlin Noise function which you will have to implement in the shader also.
Its a lot to bite at one time but here's some great tutorials from Yuri Artyukh which will help you achieve something similiar:
https://www.youtube.com/watch?v=XjZ9iu_Z9G8&t=5713s
https://www.youtube.com/watch?v=QGMygnzlifk
https://www.youtube.com/watch?v=RKjfryYz1qY
https://www.youtube.com/watch?v=WVTLnYL84hQ&t=4452s
Hope it helps and...good luck!

Related

Finding the orientation of an 2D Object in JavaScript

I'm sorry if this turns out to be a trivial answer I have not been able to figure out how to find the orientation of an irregular polygon (given as an array). By orientation I mean the angle between 0 and the long axis of the object.
Searching around I found a function in MatLab called regionprops() that is almost exactly what I need.
https://www.mathworks.com/help/images/ref/regionprops.html
Is there a JavaScript equivalent that I just cannot find, or would it be advisable to learn how to include MatLab in my project?
Seems you need to calculate image moments.
Information about image orientation can be derived by first using the
second order central moments to construct a covariance matrix.
Also consider principal components analysis

Color-tracking in a WebGL and JavaScript application

My problem seems to be a very simpel problem but I can't really find a good solution.
I'm working on an application that detects motions in an webcam stream. The plugin is written in JavaScript and WebGL. To this end it works fairly good.
I want to extand the application with color-tracking and ultimatley object recogniztion.
For now the color detection simply pass the a given color and the camera texture to a shader. The shader converts the texture and color to CIELAB space and checks the euclidean distance(on the A and B axes,Not the luminance component). If it is within the given distance the texture keeps the color, else the fragment is set to black. The result is barely "OK".
So my question is, is there a more robust and better way to find these colors?
I choosed the CIELAB space since it is somewhat invariant to shadows etc.
EDIT:
Seems that the biggest problem is that I use a Guassian Filter to reduce noise in the video image, this leads to a darker image. Even though LAB is, as stated "somewhat invariant to shadows etc" it makes the detection less efficient. So I'm guessing I need a different way to reduce noise in the image. And I have only tried a spatial median filter that uses the last 5 frames. But it is just not good enough. So an better solution for noise reduction would be MUCH appreciated.
Best regards
You need to normalize the Gaussian filter kernel values to prevent darkening/brightening of the image - you may take a look at this gaussian blur tutorial. You can also try Symmetric nearest neighbor or Kuwahara filters.
Regarding the color tracking, it seems to me you can also use HSV color space.

Pixi.js: How is this complex series of position/alpha/scale numbers generated?

Can anyone explain how this file was generated, what is was made with? It's a huge amount of y position, alpha and scale points, one for each frame, for animating sprites on the pixi canvas. Some elements have maybe 800 position points? I'm thinking each y point was not typed individually, but maybe it was :) Seems like it would have been tough to refine the animation if each number was typed rather than generated some other way.
http://flashvhtml.com/js/site/ScrollMap.js
For instance:
var rockets = {rockets:[{startFrame:0, endFrame:100, position:[1.15,5,3.14,2.25,10,3.14,3.3,15,3.14,4.3,20,3.14,5.3,25,3.14,6.25,30,3.13,7.15,35,3.13,8.05,40,3.13,8.9,45,3.13,9.75,50,3.13,10.55,53,3.13,11.35,54,3.13,12.15,53,3.13,12.9,50,3.13,13.65,45,3.13,14.4,38,3.13,15.1,29,3.13,15.8,18,3.13,16.5,5,3.13,17.2,-9.95,3.13,17.85,-26.9,3.13,18.5,-45.85,3.13,19.15,-66.8,3.13,19.8,-89.75,3.13,20.45,-114.7,3.13,21.05,-141.65,3.13,21.65,-170.6,3.13,22.25,-201.55,3.13,22.85,-234.5,3.13,23.45,-269.45,3.13,24.05,-306.4,3.13,24.6,-345.35,3.13,25.15,-386.3,3.13,25.7,-429.25,3.13,26.25,-474.2,3.13,26.8,-521.15,3.13,27.35,-570.1,3.13,27.9,-621.05,3.13,28.45,-674,3.13,29,-728.95,3.13,29.55,-785.9,3.13,30.05,-844.85,3.13,30.55,-905.8,3.13,31.05,-968.75,3.13,31.55,-1033.7,3.13,32.05,-1100.65,3.13,32.55,-1169.6,3.13,33.05,-1240.55,3.13,33.55,-1313.5,3.13,34.05,-1388.45,3.13,34.55,-1465.4,3.13,35.05,-1544.35,3.13,35.55,-1625.3,3.13,36.05,-1708.25,3.13,36.55,-1793.2,3.13,37.05,-1880.15,3.13,37.55,-1969.1,3.13,38.05,-2060.05,3.13,38.55,-2153,3.13,39.05,-2247.95,3.13,39.55,-2344.9,3.13,40.05,-2443.85,3.13,40.55,-2544.8,3.13,41,-2647.75,3.13,41.45,-2752.7,3.13,41.9,-2859.65,3.13,42.35,-2968.6,3.13,42.8,-3079.55,3.13,43.25,-3192.5,3.13,43.7,-3307.45,3.13,44.15,-3424.4,3.13,44.6,-3543.35,3.13,45.05,-3664.3,3.13,45.5,-3787.25,3.13,45.95,-3912.2,3.13,46.4,-4039.15,3.13,46.85,-4168.1,3.13,47.3,-4299.05,3.13,47.75,-4432,3.13,48.2,-4566.95,3.13,48.65,-4703.9,3.13,49.1,-4842.85,3.13,49.55,-4983.8,3.13,50,-5126.75,3.13,50.45,-5271.7,3.13,50.9,-5418.65,3.13,51.35,-5567.6,3.13,51.8,-5718.55,3.13,52.25,-5871.5,3.13,52.7,-6026.45,3.13,53.15,-6183.4,3.13,53.6,-6342.35,3.13,54.05,-6503.3,3.13,54.5,-6666.25,3.13,54.95,-6831.2,3.13,55.4,-6998.15,3.13,55.85,-7167.1,3.13,56.3,-7338.05,3.13,56.75,-7511,3.13,57.2,-7685.95,3.13]},
and also the position, scale and alpha here:
mc89:{view:'cloudFade', depth:3, startFrame:488, endFrame:540, position:[1,1,0.95,1.2,0.95,1.2,0.95,1.2,1,1,0.95,1.2,0.95,1.2,0.95,1.2,0.95,1.2,0.95,1.2,0.95,1.2,0.95,1.2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], scale:[20.718994140625,15.5989990234375,20.718368530273438,15.597808837890625,20.718368530273438,15.597808837890625,20.718368530273438,15.597808837890625,20.718994140625,15.5989990234375,20.718368530273438,15.597808837890625,20.718368530273438,15.597808837890625,20.718368530273438,15.597808837890625,20.718368530273438,15.597808837890625,20.718368530273438,15.597808837890625,20.718368530273438,15.597808837890625,20.718368530273438,15.597808837890625,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375,20.718994140625,15.5989990234375], alpha:[0,0.25,0.5,0.75,1,0.875,0.75,0.625,0.5,0.375,0.25,0.125,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},
It kind of looks like skrollr.js meets greensock on steroids. It's from the brilliant http://flashvhtml.com site. Anyhow, I'd like to know how it was put together.
Flash v HTML says that this file was produced using Adobe Edge Animate (it's in their "Findings" section). Back then, it was known for producing "brute-force" animation sheets. I'm not sure if they use a more programmatic approach nowadays, but GreenSock is a much lighter approach to making animations of this sort.
The third video in this page shows the animation process. It'll export the same style of file you linked to, chock-full of x, y, alpha, etc values.

How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)?

I'm combining 3D content with Three.js with HTML and SVG content. The Three.js CSSLoader does a pretty good job synchronizing placement of HTML and SVG content in the 3D world.
But the SVG/HTML coordinate systems are 'left-handed', whereas Three.js coordinate system is 'right-handed'. This basically means that their y-axes are reversed. In SVG/HTML, y/top goes up as you go down the screen, and Three.js uses the more standard mathematical convention of y going down as you go down the screen.
I have to continually convert from one to the other, which is pretty error prone. I know I am not the first to run into this (for example, look here). Has someone come up with a general solution? Here's what I tried:
Do everything in an Object3D with .scale.y = -1. As you may suspect, this turns out to be a disaster. It turns everything inside-out, and don't even try to put your camera in there.
Do everything in an Object3D with .rotate.x = Math.PI. This is more promising, but the z axis is no longer consistent with the HTML concept of z-index. Still, this is what I'm using now.
In HTML, don't use top, use bottom. In SVG, do everything inside a <g transform="scale(1, -1)"> inside a <g transform="translate(0, imageHeight)">. However, I feel this would be more confusing for developers, and the imageHeight has to be kept up to date at all times, which is yet another burden.
Has anyone come up with something better? Perhaps a library to help with this?
I would suggest you to use the SVG Global Transform Attribute, if you post an example of your code, i could edit the answer and post the example here, maybe a JSfiddle.
Basically you will need to add the transformation to your SVG, in your case to change the direction of y-axis, you can do a "scale(1,-1)".
See the W3 documentation with examples in the following link:
http://www.w3.org/TR/SVG/coords.html#SVGGlobalTransformAttribute
The first common use of this attribute:
Most ProjectedCRS have the north direction represented by positive
values of the second axis and conversely SVG has a y-down coordinate
system. That's why, in order to follow the usual way to represent a
map with the north at its top, it is recommended for that kind of
ProjectedCRS to use the ‘svg:transform’ global attribute with a
'scale(1, -1)' value as in the third example below.
They have some examples there too, I hope it solves your problem. :)

Javascript & Canvas: Endless random animation of slightly morphing circle?

I'm completely new to canvas and animating objects with it. I did a little bit of research (e.g. I found RaphaelJS) however I couldn't find any general answer or tutorial on how to create a "morphing" circle.
The image I posted here is what I would like to do:
I'd like to create one circle that is endlessly animated via a randomizer and is slightly morphing its contours.
I know this might be not a "real" question for this forum, however I just wonder if anyone could provide a few tipps or tricks on how to do something like that.
By "how to do something like that" I'm speaking actually about the technique on how to morph a circle. Do I have to "mathematically" create a circle with dozens of anchor-points along the edge that are influenced by a randomized function?
I would really appreciate some starting help with this.
Thank you in advance.
A circle can be reasonably well approximated by 4 cubic curves (one for each quarter and the control points on the tangents - google for the correct length of the control segments or calculate them yourself - see here. You could then randomly animate the control points within a small radius to get a wobbling effect.
Do I have to "mathematically" create a circle with dozens of anchor-points along the edge that are influenced by a randomized function?
Yes, you do, although it should not be necessary to create "dozens".
You may find the .bezierCurveTo() and .quadraticCurveTo() functions useful to provide smooth interpolated curves between control points.
When you can use a raster image then for every point you can displace it along the x-axis with a sin function. You can run the same function along the y-axis but instead to simply displace the pixel you can double it. This should give you a morphing circle but it also works with other shapes.

Categories

Resources