https://github.com/zemse/projectile.js
Kinematics motion with HTML elements.
https://github.com/zemse/projectile.js
Last synced: 12 months ago
JSON representation
Kinematics motion with HTML elements.
- Host: GitHub
- URL: https://github.com/zemse/projectile.js
- Owner: zemse
- Created: 2019-03-03T19:38:28.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-03T20:34:17.000Z (over 7 years ago)
- Last Synced: 2025-04-03T13:28:49.441Z (about 1 year ago)
- Language: JavaScript
- Homepage: https://zemse.github.io/projectile.js/
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# projectile.js
Kinematics motion with HTML elements.
## How to
1. Include the projectile.js file with the script src.
```
```
2. In scripts, create an object with Projectile class.
```
const ball = new Projectile(document.getElementById('element'));
```
3. You can change location of the element by using the setXY method of the object.
```
ball.setXY(100, 100);
```
4. You can access to the current location of the element by using the getXY method of the object.
```
console.log(ball.getX()); //prints a Number e.g. 100
console.log(ball.getY()); //prints a Number e.g. 100
console.log(ball.getXY()); //prints an Object e.g. {x: 100, y: 100}
```
5. You can do a projectile of the element using the throwXY method of the object.
```
ball.throw(100,-100); //x is towards right and y is towards bottom thats why -100.
ball.throw(100,-200,0); //specificy g value in third argument, default value is 100.
```
## Demo
In the demo, please open console and you can use ball.setXY, ball.getXY and ball.throwXY methods. You can find the demo [here](https://zemse.github.io/projectile.js/).