GithubHelp home page GithubHelp logo

thecolorblocks / chladni Goto Github PK

View Code? Open in Web Editor NEW

This project forked from luciopaiva/chladni

0.0 0.0 0.0 48 KB

Chladni plate simulation made with vanilla Javascript.

Home Page: https://luciopaiva.com/chladni

JavaScript 78.66% HTML 21.34%

chladni's Introduction

Chladni plate

See live demo here.

When resonating, a vibrating plate is divided into regions that oscillate in opposite directions, bounded by lines where no vibration occurs. Particles standing on top of the plate tend to settle right on those lines. The resulting patterns are what is called Chladni figures, after Ernst Chladni. This simulation aims at replicating that same behavior on a digital canvas.

One of the key factors causing the patterns is the shape of the plate being vibrated. For this simulation, a square plate is assumed. The function that describes patterns in a square plate of side length L is given by:

cos(n * π * x / L) cos(m * π * y / L) - cos(m * π * x / L) cos(n * π * y / L)

Where x, y is the screen coordinate to compute and picking different m and n values produces different patterns (with the exception of m == n, where no pattern emerges).

Implementation details

My idea was to cycle through random Chladni patterns, as if the plate's vibration input frequency was changing periodically.

To make it easy for the CPU, I compute the whole Chladni pattern only once and then just simulate particles shaking and moving around until the next cycle.

Not only I had to compute the pattern, I also had to compute a gradient field so that particles could look up quickly where to go considering where they are right now. This turned to be even more expensive, due to each position having to check its 8 neighbors to know where to point its gradient to.

Computing a single Chladni pattern plus gradients is very expensive, taking around 100ms on a Intel® Core™ i5-4670 CPU @ 3.40GHz × 4 for about 500k points (canvas scale factor at 2, i.e., a quarter of a full HD screen). Since this would kill the frame rate, I used a web worker for the task. Every x seconds it selects a new pattern, computes it and posts a message to the main thread with the new buffer. The worker transfers its buffer, meaning there is no copy involved.

References

Paul Bourke's article on Chladni plates was extremely helpful.

chladni's People

Contributors

luciopaiva avatar

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.