malik-tillman / Fluid-JS

A JavaScript library that allows for easy deployment of WebGL rendered fluid simulations.
129 stars 23 forks source link

Trigger animation on mouse hover #21

Closed Duhragon closed 1 year ago

Duhragon commented 1 year ago

Amazing work. I am planning to use it in a side project and was wondering if the animation could be triggered upon mouse movement instead of click and drag.

Duhragon commented 1 year ago

Figured it. In the fluid.min.js, changed from this : e.addEventListener("mousemove", function (e) { (a[0].moved = a[0].down), (a[0].dx = 5 * (e.offsetX - a[0].x)), (a[0].dy = 5 * (e.offsetY - a[0].y)), (a[0].x = e.offsetX), (a[0].y = e.offsetY); }), e.addEventListener("mousedown", function () { (a[0].down = !0), (a[0].color = L()); }), window.addEventListener("mouseup", function () { a[0].down = !1; }),

To this: e.addEventListener("mousemove", function (e) { (a[0].moved = a[0].down), (a[0].dx = 5 * (e.offsetX - a[0].x)), (a[0].dy = 5 * (e.offsetY - a[0].y)), (a[0].x = e.offsetX), (a[0].y = e.offsetY); (a[0].moved = !0), (a[0].color = L()); }), // e.addEventListener("mousedown", function () { // (a[0].down = !0), (a[0].color = L()); // }), // window.addEventListener("mouseup", function () { // a[0].down = !1; // }),