Giter VIP home page Giter VIP logo

Comments (1)

davepagurek avatar davepagurek commented on June 30, 2024

Hi! Unfortunately this isn't an issue p5 is able to fix, as it is an issue with the data representation of all js canvases.

The first issue is that the color doesn't get reduced by 5/255 each frame. Instead, it's something closer to prevColor * 250/255 + 0 * 5/255. However, the colors are all stored as integers, so the new color is actually round(prevColor * 250/255). When the color gets dark enough, round(prevColor * 250/255) just equals prevColor and it stops changing.

So, some workarounds:

  • Use additive/subtractive backgrounds instead of the default mix blend mode. This will ensure the background always makes progress, and is probably how you expected the math to work. If you're just fading to black, you can subtract 1 each frame to make sure the color values always decrease:

    push()
    blendMode(DIFFERENCE)
    background(1)
    pop()

    Or for white, use ADD instead of DIFFERENCE.

  • Draw to something with higher precision color values. Unfortunately, js canvas does not give us any tools to change the precision of the main canvas. However, in WebGL, you can specify the precision for framebuffers, so you can do all your drawing to a createFramebuffer({ format: FLOAT }) to use high-precision floating point color. The annoying part about this is that you have to do all your drawing to the framebuffer and then draw the framebuffer to the main canvas at the end of each frame, because the content of the main canvas will still use integer colors.

from p5.js.

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.