0.0.1-2A • Published 2 years ago

physicssimulationts v0.0.1-2A

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

PhysicsSimulationTS

Hi! My name is OldSinner, and this repository presents my struggles with simulating the principles of physics in the field of programming. I used TypeScript for programming. I used it because of its ease of use in terms of drawing on the screen.

I created the whole thing by watching the series of guides "The Nature of Code" by The Coding Train, but not using Proccesing.

Install

npm i physicssimulationts

Random Walker

The Random Walker project is nothing more than an object moving in random places. I programmed it in three variants.

  • Walker - Moves randomly and independently.

  • WalkerWithPropability - Moves randomly, with the tendency given in the constructor.

  • SquareWalker - moves randomly turning clockwise every set number of frames.

MathUtils

It is a static class that gives you access to a number of mathematical functions that are used in physical calculations.

//The function returns an array of cubic Spline values ​​between the points of the xs and xy arrays, with a specified number of steps
MathUtils.cubicSpline([10,  20,  30],  [10,  20,  30],  1);
//The function returns a value between 0 and 1, according to the Gaauus distribution.
MathUtils.getGauusian();
// The function returns a random value between two values
MathUtils.getRandom(x,  y);
//The function returns the noise value for point X, using the sine wave
MathUtils.getSinusNoise(1,  10,  20,  30,  15);
//The function linearly interpolates the values ​​of ab at the point x
MathUtils.linearInterpolate(1,  x,  y,  y  -  x);

RenderUtils

RenderUtils is a static class that helps render the image in html canvas

  • Render(handler: Function, frames: number, canvas: HTMLCanvasElement) - The function executes a handler, the specified number of frames per second. Every cage cleans the canvas
  • RenderWithoutClear(handler: Function, frames: number) - The function executes a handler, the specified number of frames per second.
  • newGuid() - Generate Guid

RenderUtils

Soon...