{"id":20384338,"url":"https://github.com/gyakobo/cross-hairs","last_synced_at":"2026-05-02T11:40:56.291Z","repository":{"id":132953407,"uuid":"427907439","full_name":"Gyakobo/Cross-Hairs","owner":"Gyakobo","description":"This project tries to simulate fluid dynamics, and fluid viscosity.","archived":false,"fork":false,"pushed_at":"2024-06-20T13:32:38.000Z","size":804,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-15T08:07:00.399Z","etag":null,"topics":["c","c-plus-plus","devpost-hackathon","fluid-dynamics","fluid-simulation","hackathon-project","illumination-estimation","multithreading","njit","opencv"],"latest_commit_sha":null,"homepage":"https://devpost.com/software/cross-hairs","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Gyakobo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-14T11:16:40.000Z","updated_at":"2024-12-03T18:10:28.000Z","dependencies_parsed_at":"2024-04-28T05:30:13.263Z","dependency_job_id":"e29c75cc-5561-443f-8ecf-a1d5fd14d20b","html_url":"https://github.com/Gyakobo/Cross-Hairs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyakobo%2FCross-Hairs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyakobo%2FCross-Hairs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyakobo%2FCross-Hairs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyakobo%2FCross-Hairs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gyakobo","download_url":"https://codeload.github.com/Gyakobo/Cross-Hairs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241935269,"owners_count":20044827,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","c-plus-plus","devpost-hackathon","fluid-dynamics","fluid-simulation","hackathon-project","illumination-estimation","multithreading","njit","opencv"],"created_at":"2024-11-15T02:27:23.450Z","updated_at":"2026-05-02T11:40:51.269Z","avatar_url":"https://github.com/Gyakobo.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cross-Hairs\n\n![image](https://img.shields.io/badge/Devpost-003E54?style=for-the-badge\u0026logo=Devpost\u0026logoColor=white)\n![image](https://img.shields.io/badge/C-00599C?style=for-the-badge\u0026logo=c\u0026logoColor=white)\n![image](https://img.shields.io/badge/C%2B%2B-00599C?style=for-the-badge\u0026logo=c%2B%2B\u0026logoColor=white)\n![image](https://img.shields.io/badge/Python-FFD43B?style=for-the-badge\u0026logo=python\u0026logoColor=blue)\n![image](https://img.shields.io/badge/OpenCV-27338e?style=for-the-badge\u0026logo=OpenCV\u0026logoColor=white)\n![image](https://img.shields.io/badge/CMake-064F8C?style=for-the-badge\u0026logo=cmake\u0026logoColor=white)\n![image](https://img.shields.io/badge/windows%20terminal-4D4D4D?style=for-the-badge\u0026logo=windows%20terminal\u0026logoColor=white)\n\nAuthor: [Andrew Gyakobo](https://github.com/Gyakobo)\n\n\u003e[!NOTE]\n\u003eThis is a project which I presented and subsequently won 1st place in the [2021 Hackathon @ NJIT](https://devpost.com/software/cross-hairs).  \n\n\u003e[!WARNING]\n\u003eThis project is very raw and indelicate, and honestly could be furnished slightly more. Most prominently I want to point out that I should have definitely utilized `malloc` and allocated and managed memory way more efficiently. Apart from that there's a ton of memory leaks and code errors. Moreover, I ought to have used a struct or a class for each particle in this engine.  \n\n## Introduction\n\nTo start off, I always had a passion for mathematics, physics and programming. The world always seemed quantifiable and boring to me, thus I always reverted to coding. I specifically loved exploiting game and physics engines. Making up glamorous formulas predicting the gravitational trajectory of an object always fascinated me. Having heard of the Hackathon, I was sort of pushed into making my own physics from scratch.\n\nThis project tries to simulate fluid dynamics, and fluid viscosity. In particular I drew inspiration from the game [Noita](https://store.steampowered.com/app/881100/Noita/) (cool game btw) to develop this project. More details can be found on this [video](https://youtu.be/mcoHVF-JWog?si=MOAMeUlSdaGBlRED)\n\n\nhttps://github.com/user-attachments/assets/bca51814-f474-4b7e-af04-2bf966234822\n\n\n## Methodolgy\n\nThe game is divided into small grids which pertain to a specific.\n\n* The dynamics of this game are painfully simple. Each `particale` in the grid follows a specific behaviour and interacts with other particles which also conform to the same move set.\n\nIn particular each particle moves in the following manner:\n\n1. If there simply isn't anything underneath a select particle then the said particle just moves down:\n\n\u003ctable\u003e\n\n\u003ctr\u003e\u003ctd\u003e\n\n|   | █ |   |\n|---|---|---|\n| █ | □ | █ |\n\n\u003c/td\u003e\u003ctd\u003e\n\n\u0026nbsp;\n→\n\u0026nbsp;\n\n\u003c/td\u003e\u003ctd\u003e\n\n|   | \u0026nbsp; |   |\n|---|---|---|\n| █ | █ | █ |\n\n\u003c/td\u003e\u003c/tr\u003e\n\n\u003c/table\u003e\n\n2. If there's however another object underneath the existing one then the particle moves to the left of the object:\n\n\u003ctable\u003e\n\n\u003ctr\u003e\u003ctd\u003e\n\n|   | █ |   |\n|---|---|---|\n| □ | █ |   |\n\n\u003c/td\u003e\u003ctd\u003e\n\n\u0026nbsp;\n→\n\u0026nbsp;\n\n\u003c/td\u003e\u003ctd\u003e\n\n|   | \u0026nbsp; |   |\n|---|---|---|\n| █ | █ |   |\n\n\u003c/td\u003e\u003c/tr\u003e\n\n\u003c/table\u003e\n\n3. And subsequently the element would seek to occupy the next available space on the right: \n\n\u003ctable\u003e\n\n\u003ctr\u003e\u003ctd\u003e\n\n|   | █ |   |\n|---|---|---|\n| █ | █ | □ |\n\n\u003c/td\u003e\u003ctd\u003e\n\n\u0026nbsp;\n→\n\u0026nbsp;\n\n\u003c/td\u003e\u003ctd\u003e\n\n|   | \u0026nbsp; |   |\n|---|---|---|\n| █ | █ | █ |\n\n\u003c/td\u003e\u003c/tr\u003e\n\n\u003c/table\u003e\n\n4. Lastly, if all the avaiable space below are occupied then the particle in question would remain at the same place. There is however another methodolgy that I glossed over. There exists an additional step on making the viscosity aspect of this game even more prominent adding another relation: each particle that has nowhere to go would simply 'slide' down left and cocomitantly right if there's already a particle on the left:\n\n\u003ctable\u003e\n\n\u003ctr\u003e\u003ctd\u003e\n\n| □ | █ |   |\n|---|---|---|\n| █ | █ | █ |\n\n\u003c/td\u003e\u003ctd\u003e\n\n\u0026nbsp;\n→\n\u0026nbsp;\n\n\u003c/td\u003e\u003ctd\u003e\n\n| █ |   |   |\n|---|---|---|\n| █ | █ | █ |\n\n\u003c/td\u003e\u003c/tr\u003e\n\n\u003c/table\u003e\n\n\n\u003ctable\u003e\n\n\u003ctr\u003e\u003ctd\u003e\n\n| █ | █ | □ |\n|---|---|---|\n| █ | █ | █ |\n\n\u003c/td\u003e\u003ctd\u003e\n\n\u0026nbsp;\n→\n\u0026nbsp;\n\n\u003c/td\u003e\u003ctd\u003e\n\n| █ |   | █ |\n|---|---|---|\n| █ | █ | █ |\n\n\u003c/td\u003e\u003c/tr\u003e\n\n\u003c/table\u003e\n\n## What I'd have done differently\n\n1. Most definitely I should have just instantiated a struct `struct Particle` and created them with `malloc` and freed memory with `free` respectively. The contents of this data structure would be as follows: the coordinate `int x, y` and the color `char color`. \n\n\u003e[!NOTE]\n\u003eFrom a memory management perspective, you ought to have the smallest element first in the `struct` in order to minimize memory usage. This way a select `struct` object would be of size `9 bytes`.\n\n```c\nstruct Particle {\n    char color; /* 1 byte */\n    int x, y; /* 4 bytes per variable */\n}\n```\n\n2. The particle grid could also be operated with the use of threads. Let say we have an adustable 640 x 480 grid. For now it's very easy to work with this grid, however, as soon as you add more elements or increase the grid size, there becomes an overhead and latency increases. This is where you should use multi-threading.\n\n### The OpenMP - open Multi-processing library \n\nJust as a side note the **OpenMP** library comprises of the following parts. Also feel free to download, edit, commit and leave feedback to the project.\n\nFor more details about parallelism in C please refer to my previous [multi-threading project](https://github.com/Gyakobo/multi-threading) where I utilized and explained the `\u003comp.h\u003e` C library. \n\n#### Compiler Directives\n\n```c\n#pragma omp parallel\n#pragma omp critical\n#pragma omp barrier\n#pragma omp master\n```\n\n#### Functions\n\n```c\n#include \u003comp.h\u003e\nint omp_get_thread_num()\nint omp_get_num_threads()\n```\n\n#### Compiling and Linking\n\n```bash\ngcc -fopenmp # C compiler\ng++ -fopenmp # C++ compiler\n```\n\n#### Environmental variables\n\n```bash\nexport OMP_NUM_THREADS=8\nexport OMP_NESTED=TRUE\n```\n\n## How to execute \n\nTo execute this project please first give exec permissions to [build.sh](https://github.com/Gyakobo/Cross-Hairs/blob/main/Cross-Hairs/build.sh) and of course run it:\n\n```shell\n$ sudo chmod +x build.sh\n$ sudo ./build.sh\n```\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgyakobo%2Fcross-hairs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgyakobo%2Fcross-hairs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgyakobo%2Fcross-hairs/lists"}