Giter Club home page Giter Club logo

Comments (5)

theshock avatar theshock commented on July 17, 2024

There are three ways to do it:

  • Use getImageData and change pixels in it, adding new values to it using Alpha Compositing and such formula:

    resultColor = oldColor_(1-transparency) + newColor_transparency

  • Create new empty layer and render pixel data there

  • Prerender frames to hidden buffer and then just render buffer as image

Last way is most effective looking at speed - pixel manipulations are slow enough

from libcanvas.

stevozilik avatar stevozilik commented on July 17, 2024

Thanks will try that!

I tried creating new layer, but that did not work, was doing something wrong.... The problem with layers is also current libcanvas api doesnt provide a way of removing then, and I need a dynamic number of layers, one for each 'vehicle' (a vehicle is a set of simple shapers with animations) on the canvas, as the number of vehicles is data driven...

Ended up calling createBuffer on main libcanvas, which creates a new html canvas, then redering the flame inside the new buffer canvas (using getImageData, putImageData) and draw the buffer canvas into the 'main' libcanvas to get the transparency working. That works, but I doubt its good in terms of performance. What do u think?

from libcanvas.

theshock avatar theshock commented on July 17, 2024

I mean prepender several frames once and then just draw them first-second-third-first-second-...
You should try to avoid pixel manipulations.

from libcanvas.

stevozilik avatar stevozilik commented on July 17, 2024

I got u. The 'problem' is the algorithm is random and each frame is populated based on the previous frame, thus u never end up creating a loop that would smoothly transition between the last and first frame in the buffer...

Lets say I wont prerender, what is the best way to render the fllame each frame?

from libcanvas.

theshock avatar theshock commented on July 17, 2024

The better way is to change algorithm and run in without many calls of putImageData, but you can use first way, described in comment above - it is most correct.

from libcanvas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.