mirror of
https://github.com/Noratrieb/redox.git
synced 2026-01-14 16:25:04 +01:00
added mass
This commit is contained in:
parent
1888dca4e8
commit
10ca04b98e
5 changed files with 19 additions and 66 deletions
8
.idea/.gitignore
generated
vendored
8
.idea/.gitignore
generated
vendored
|
|
@ -1,8 +0,0 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
47
README.md
47
README.md
|
|
@ -1,46 +1 @@
|
|||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `yarn start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.\
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `yarn test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `yarn build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `yarn eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
it's react because I'm soo lazy to use vanilla ts
|
||||
|
|
@ -7,11 +7,13 @@ const particles: Particle[] = [];
|
|||
|
||||
|
||||
export function particlesInit() {
|
||||
const chargeToMass = [0.1, 1, 10];
|
||||
for (let i = 0; i < 200; i++) {
|
||||
const charge = Math.random() < 0.3 ? 0 : Math.random() < 0.5 ? 1 : -1;
|
||||
particles.push(new Particle(new Vector(
|
||||
Math.random() * (CANVAS_WIDTH - 100) + 50,
|
||||
Math.random() * (CANVAS_HEIGHT - 100) + 50
|
||||
), Math.random() < 0.3 ? 0 : Math.random() < 0.6 ? -1 : 1));
|
||||
), charge, chargeToMass[charge - 1]));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,18 +12,18 @@ const RANDOM_ACCELERATION = 2;
|
|||
export default class Particle implements SimObject {
|
||||
private _position: Vector;
|
||||
private _velocity: Vector;
|
||||
// private _color: FillStyle;
|
||||
private _mass: number;
|
||||
private _charge: number;
|
||||
|
||||
constructor(position: Vector, /*color = "black", */charge = 0) {
|
||||
constructor(position: Vector, charge = 0, mass = 1) {
|
||||
this._position = position;
|
||||
this._velocity = new Vector();
|
||||
//this._color = color;
|
||||
this._charge = charge;
|
||||
this._mass = mass;
|
||||
}
|
||||
|
||||
public applyForce(force: Vector) {
|
||||
this._velocity = this._velocity.add(force);
|
||||
this._velocity = this._velocity.add(force.scaleInverse(this._mass));
|
||||
}
|
||||
|
||||
public draw(ctx: Ctx): void {
|
||||
|
|
|
|||
|
|
@ -11,15 +11,19 @@ export default class Vector {
|
|||
return new Vector(this.x + b.x, this.y + b.y);
|
||||
}
|
||||
|
||||
public sub(b: Vector) {
|
||||
public sub(b: Vector): Vector {
|
||||
return new Vector(this.x - b.x, this.y - b.y);
|
||||
}
|
||||
|
||||
public scale(number: number) {
|
||||
return new Vector(this.x * number, this.y * number);
|
||||
public scale(n: number): Vector {
|
||||
return new Vector(this.x * n, this.y * n);
|
||||
}
|
||||
|
||||
public magnitude() {
|
||||
public scaleInverse(n: number): Vector {
|
||||
return new Vector(this.x / n, this.y / n);
|
||||
}
|
||||
|
||||
public magnitude(): number {
|
||||
return Math.sqrt(this.x * this.x + this.y * this.y);
|
||||
}
|
||||
|
||||
|
|
@ -27,12 +31,12 @@ export default class Vector {
|
|||
return Math.sqrt((this.x - b.x) ** 2 + (this.y - b.y) ** 2)
|
||||
}
|
||||
|
||||
public negated() {
|
||||
public negated(): Vector {
|
||||
return new Vector(-this.x, -this.y);
|
||||
}
|
||||
|
||||
public normalized() {
|
||||
public normalized(): Vector {
|
||||
const factor = this.magnitude();
|
||||
return new Vector(this.x / factor, this.y / factor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue