# billiards **Repository Path**: bababi/billiards ## Basic Information - **Project Name**: billiards - **Description**: 镜像自github, 值得学习的桌球游戏源码 GPL协议 - **Primary Language**: TypeScript - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-05-07 - **Last Updated**: 2024-08-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # billiards [![codecov](https://codecov.io/gh/tailuge/billiards/branch/master/graph/badge.svg?token=BH11KRAEL0)](https://codecov.io/gh/tailuge/billiards) [![CodeFactor](https://www.codefactor.io/repository/github/tailuge/billiards/badge)](https://www.codefactor.io/repository/github/tailuge/billiards) [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=tailuge_billiards&metric=code_smells)](https://sonarcloud.io/summary/new_code?id=tailuge_billiards) [![Tests](https://github.com/tailuge/billiards/actions/workflows/main.yml/badge.svg)](https://github.com/tailuge/billiards/actions/workflows/main.yml) [![Open in Gitpod](https://img.shields.io/badge/Gitpod-Open%20in%20Gitpod-%230092CF.svg)](https://gitpod.io/#https://github.com/tailuge/billiards) ![GitHub](https://img.shields.io/github/license/tailuge/billiards.svg) [![Demo and Screenshot](https://raw.githubusercontent.com/tailuge/billiards/master/dist/images/t3.png)](https://tailuge.github.io/billiards/dist) This is an open-source project bringing unsophisticated billiards physics written in typescript to a browser near you. Play pool, snooker, or 3-cushion online for free! ## Features * Backspin and sidespin well modeled. * Presentation using WebGL in any modern browser on mobile, linux, mac or windows. * Record and playback breaks. * Two player online mode with node websocket server. * Nine ball, Snooker and three cushion billiards rules. * Deploys to github pages, vercel.com and render.com with github actions. ## Online Demo Demos run in all major desktop and mobile browsers and uses WebGL * [Nine ball ⬀](https://tailuge.github.io/billiards/dist) make a break and share replay link with friends * [Three cushion billiards ⬀](https://tailuge.github.io/billiards/dist?ruletype=threecushion) the ultimate test of physics and player (average on both counts) * [Snooker ⬀](https://tailuge.github.io/billiards/dist?ruletype=snooker) we await the first 147 submission to the leaderboard. * 4-ball [Straight pool ⬀](https://tailuge.github.io/billiards/dist?ruletype=fourteenone). * Inspect physics and tweak constants using [diagrams](https://tailuge.github.io/billiards/dist/diagrams/diagrams.html). * Try to get on the leaderboard of highest [breaks](https://scoreboard-tailuge.vercel.app/leaderboard.html) hosted on vercel.com * Try [two player](https://tailuge.github.io/billiards/dist/lobby/lobby.html) online hosted on render.com ## Reference material * Papers on ball mechanics [Han 2005](https://billiards.colostate.edu/physics_articles/Han_paper.pdf) with important corrections by [Kiefl](https://ekiefl.github.io/2020/04/24/pooltool-theory/#3-han-2005"). * [cushions](https://billiards.colostate.edu/physics_articles/Mathavan_IMechE_2010.pdf), [max spin](https://billiards.colostate.edu/technical_proofs/new/TP_B-17.pdf), simulation and constants [1](https://savoirs.usherbrooke.ca/bitstream/handle/11143/6598/MR91690.pdf?sequence=1) [2](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.89.4627&rep=rep1&type=pdf) [3](https://www.researchgate.net/publication/228634093_Bounce_of_a_spinning_ball_near_normal_incidence) [4](https://billiards.colostate.edu/technical_proofs/new/TP_B-6.pdf) [5](https://billiards.colostate.edu/faq/physics/physical-properties/) * 3D graphics uses [three.js](https://threejs.org/docs/index.html#api/math/Vector3) * Inline [LaTeX](https://www.codecogs.com/eqnedit.php?latex=\dot{a}) editor for equations in README.md ### Key equations Based on [Han 2005](https://billiards.colostate.edu/physics_articles/Han_paper.pdf) paper #### surface velocity ![equation](http://latex.codecogs.com/png.latex?\vec{v{_{a}}}%20=%20\vec{v}+%20(\vec{up}%20\times%20R\vec{\omega})) #### sliding motion ![equation](http://latex.codecogs.com/png.latex?\dot{v}%20=%20-\mu%20g%20\frac{\vec{v_{a}}}{\left%20|%20\vec{v_{a}}%20\right%20|}) ![equation](http://latex.codecogs.com/png.latex?\dot{w}%20=%20-\frac{5}{2}\frac{\mu%20g}{R}%20\frac{\vec{v_{a}}}{\left%20|%20\vec{v_{a}}%20\right%20|}) ![equation](http://latex.codecogs.com/png.latex?\dot{\omega}_{z}%20=%20-\frac{5}{2}\frac{M_{z}}{mR^2}sgn(\omega_{z})) #### rolling motion ![equation](http://latex.codecogs.com/png.latex?\dot{v}%20=%20-\frac{5}{7}\frac{M_{xy}}{mR}\frac{\vec{up}\times\vec{\omega}}{\left%20|%20\vec{w}%20\right%20|}) ![equation](http://latex.codecogs.com/png.latex?\dot{w}%20=%20-\frac{5}{7}\frac{M_{xy}}{mR^2}\frac{\vec{\omega}}{\left%20|%20\vec{w}%20\right%20|}) where ![equation](https://latex.codecogs.com/svg.image?M_{xy}=\frac{7}{5\sqrt{2}}R\mu&space;m&space;g) ,![equation](https://latex.codecogs.com/svg.image?M_{z}=\frac{2}{3}\mu&space;m&space;g\rho) #### cushion bounce ## Useful commands ### Install ```shell nvm use v18.17.1 yarn install yarn dev yarn gltfpack ``` This generates artefacts in /dist for prod deployment (e.g. on github static pages) ### Run ```shell yarn serve ``` Then open in your browser to play ### Test ```shell yarn test yarn coverage ``` ### Maintain ```shell yarn deps yarn upgrade -L yarn prettify ``` ### Two player ```shell yarn websocket ``` the client uses query parameter ``?websocketserver=wss://some-host`` to locate a websocket server, open to see options ## Controls Use mouse, touch screen or keyboard: Aim Control Fine aim Topspin and backspin Shift Side spin Space Hit - hold for more power ## Progress snapshots July 2018 ![2018](https://raw.githubusercontent.com/tailuge/billiards/master/dist/images/t1.png) July 2019 ![2019](https://raw.githubusercontent.com/tailuge/billiards/master/dist/images/t2.png) March 2021 ![2021](https://raw.githubusercontent.com/tailuge/billiards/master/dist/images/t3.png) August 2023 (mobile) top | aim :--:|:--: ![2023](https://raw.githubusercontent.com/tailuge/billiards/master/dist/images/mobile1.jpg) | ![2023](https://raw.githubusercontent.com/tailuge/billiards/master/dist/images/mobile2.jpg) Star History [![Star History Chart](https://api.star-history.com/svg?repos=tailuge/billiards&type=Date)](https://star-history.com/#tailuge/billiards&Date) ## Licence This project is open source and licensed under the GNU General Public License - see the [LICENSE](LICENSE) file for details. Contributions welcome.