GithubHelp home page GithubHelp logo

xlikesasukee / p5-physic-simulations Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 313 KB

In this Repository I am going to publish Physic Simulations I made in p5.js

JavaScript 87.10% HTML 11.28% CSS 1.62%
electric-field english german javascript math p5-js p5js physics physics-simulation simulation

p5-physic-simulations's Introduction

p5-Physic-Simulations

In this Repository I am going to publish Physic Simulations I made in p5.js.

This Repository will be my diary as I improve my skills in javascript with p5.js as well as my general understanding of physics.

The code is going to have a lot of comments that show my learn and though process. I hope you enjoy!

Electric Field Simulation

This project is the first physics simulation I made using p5.js. I showed the electric field created by Electrons and Protons by calculating the Force applied to small charges on the Canvas and displayed these vectors with arrows. I made use of the formula for electric force on an electric field.

grafik

(https://qph.cf2.quoracdn.net/main-qimg-4d7e7ca08e8bd4d8f034de7b2c96aa64)

To add direction I just had to multiply by the distance vector normalized and finally do the same for the force vector. I used Robert Eisele Complex.js library for complex numbers/my Vectors.

I learned a lot and had a lot of fun writing this little program. I hope you like it.

The controls to use the program are simple: "q" - to spawn Proton "w" - to spawn Electron "e" - to draw electric field "r" - to remove last cerated Particle

Mechanical Waves

In this Project I simulated moving mechanical waves using this function:

grafik https://www.youtube.com/watch?v=X8rfJZt8Lc4

The function takes x and t as an input, the time passed and the x-position of a point, and gives you the corresponding y-value. I added nice sliders so one can easily modify amplitude, swingDuration and waveLength for the wave themselves. If you want to add a wave just create a new Wave in sketch.setup(). I hope you enjoy!

p5-physic-simulations's People

Contributors

xlikesasukee avatar

Stargazers

 avatar

Watchers

 avatar

p5-physic-simulations's Issues

Electric Field: Change the color of the arrows depending on the force applied to them.

I would like the color of the Arrows to change depending on the value of F you get for them.
This could happen inside this function.

function drawElectricField() {
  for (let x = 0; x < 1200; x += 40) {
    for (let y = 0; y < 1200; y += 40) {
      let base = new Complex(x, y);
      let F = calculateElectricFieldVector(base).mul(1e15);

      //getColor(F) get corresponding color out of F value

      let absF = F.abs();
      F = F.mul(1/absF);
      drawArrow(base, new Complex(base.re + F.re, base.im + F.im),[35, 144, 145]);
    }
  }
}

The color variable is already a parameter of my drawArrow funciton.

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.