{"id":19476961,"url":"https://github.com/leogaudin/fract-ol","last_synced_at":"2025-04-25T14:32:30.126Z","repository":{"id":175101318,"uuid":"653323780","full_name":"leogaudin/fract-ol","owner":"leogaudin","description":"42 • A guide for creating a small fractal exploration program. It is the time to discover or use the mathematical notion of complex numbers, to take a peek at the concept of optimization in computer graphics and practice event handling.","archived":false,"fork":false,"pushed_at":"2023-08-27T14:04:01.000Z","size":8960,"stargazers_count":19,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-03T23:04:34.535Z","etag":null,"topics":["42","c","complex-numbers","fract-ol","fractals","imaginary-numbers","mathematics"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leogaudin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-06-13T20:52:13.000Z","updated_at":"2025-04-03T10:09:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"4a8cfffc-71f9-46c1-b029-a9891fa3df85","html_url":"https://github.com/leogaudin/fract-ol","commit_stats":null,"previous_names":["leogaudin/fract-ol"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leogaudin%2Ffract-ol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leogaudin%2Ffract-ol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leogaudin%2Ffract-ol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leogaudin%2Ffract-ol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leogaudin","download_url":"https://codeload.github.com/leogaudin/fract-ol/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250834204,"owners_count":21494929,"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":["42","c","complex-numbers","fract-ol","fractals","imaginary-numbers","mathematics"],"created_at":"2024-11-10T19:42:53.103Z","updated_at":"2025-04-25T14:32:30.072Z","avatar_url":"https://github.com/leogaudin.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\t\u003ch1\u003e🌌 fract-ol\u003c/h1\u003e\n\t\u003cimg src=\"assets/banner.webp\"\u003e\n\t\u003cp\u003e\u003cb\u003eThe \u003ccode\u003efract-ol\u003c/code\u003e project from the 42 School is one of the three \"beginner\" graphical projects of the cursus. It teaches you about manipulating a low-level graphic library, advanced math, and more.\u003c/b\u003e\u003c/p\u003e\n\t\u003cp\u003e\u003cem\u003e⚠️ As mentioned in the rules of 42, do not copy and paste this code without thinking, the following README provides enough explanations and resources for you to go on your own journey with the awful MiniLibX ❤️\u003c/em\u003e\u003c/p\u003e\n\t\u003ca href=\"https://wakatime.com/badge/user/db0e5671-cec5-4e7b-9d41-19a881e67f7d/project/a74b4852-2740-4faa-8753-9239f87e3cdc\"\u003e\n\t\t\u003cimg src=\"https://wakatime.com/badge/user/db0e5671-cec5-4e7b-9d41-19a881e67f7d/project/a74b4852-2740-4faa-8753-9239f87e3cdc.svg\" alt=\"wakatime\"/\u003e\n\t\u003c/a\u003e\n\t\u003cbr /\u003e\n\t\u003cimg src=\"https://img.shields.io/badge/norminette-passing-success\"/\u003e\n\t\u003ca href=\"https://developer.apple.com/library/archive/documentation/Performance/Conceptual/ManagingMemory/Articles/FindingLeaks.html\"\u003e\n\t\t\u003cimg src=\"https://img.shields.io/badge/leaks-none-success\" /\u003e\n\t\u003c/a\u003e\n\t\u003cimg src=\"https://img.shields.io/badge/bonus-included-success\"/\u003e\n\t\u003cbr /\u003e\n\t\u003cimg src=\"https://img.shields.io/badge/-125%2F100-success?logo=42\u0026logoColor=fff\" /\u003e\n\u003c/div\u003e\n\n## 📖 Table of Contents\n\u003c!--ts--\u003e\n* [⚙️ Usage](#usage)\n\t* [🕹 Controls](#controls)\n* [🤔 How to do Fract-ol?](#how-to-do-fract-ol)\n\t* [🤓 The math behind fractals](#the-math-behind-fractals)\n\t* [👨🏻‍💻 From math to code](#from-math-to-code)\n* [🛠️ Main functions](#main-functions)\n\t* [`draw_fractal`](#draw_fractal)\n\t* [`calculate_mandelbrot`](#calculate_mandelbrot)\n* [🌌 Demonstrations](#demonstrations)\n\t* [🍑 Mandelbrot](#mandelbrot)\n\t* [👩🏼 Julia](#julia)\n\t* [🔥 Burning Ship](#burning-ship)\n* [🙇🏻 Resources and Credits](#resources-and-credits)\n\u003c!--te--\u003e\n\n## Usage\n\n* **Clone** the repository\n\n\t```bash\n\tgit clone https://github.com/leogaudin/fract-ol.git\n\t```\n\n* To **compile** the program, run the following command\n\n\t```bash\n\tmake\n\t```\n\n* To **execute** the program, use the following command\n\n\t```bash\n\t./fractol \u003cfractal\u003e\n\t```\n\n\u003e Available commands: `mandel`, `julia`, `ship`\n\n### Controls\n\nThe program supports the following controls:\n\u003ctable align=\"center\"\u003e\n  \u003ctr align=\"center\"\u003e\n    \u003ctd\u003e\u003cb\u003eScroll\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eZoom\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"center\"\u003e\n    \u003ctd\u003e\u003cb\u003e⬆️ ⬇️ ⬅️ ➡️\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eMove the view\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"center\"\u003e\n    \u003ctd\u003e\u003cb\u003eR\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eReset the fractal to its initial state\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"center\"\u003e\n    \u003ctd\u003e\u003cb\u003eC\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eShift the color range\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"center\"\u003e\n    \u003ctd\u003e\u003cb\u003eM\u003c/b\u003e and \u003cb\u003eP\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eDecrease or increase the max iterations\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr align=\"center\"\u003e\n    \u003ctd\u003e\u003cb\u003eJ\u003c/b\u003e\u003c/td\u003e\n    \u003ctd\u003eGenerate new constants for the Julia fractal\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\n\u003e 🚀 The lower the  iterations, the faster the program will run.\n\u003e\n\u003e 🐢 The deeper the zoom, the more iterations are needed to render the fractal, the slower the program.\n\n## How to do Fract-ol?\n\n### The math behind fractals\n\nFractals are formed by mathematical suites.\n\nFor example, the Julia and Mandelbrot sets are defined by the following suite:\n\n$$\nz_{n+1} = z_n^2 + c\n$$\n\nFractals are based on complex numbers (i.e. numbers with a real and imaginary part, like $z = a + bi$).\n\nThere is a great video by [DIMENSION CODE](https://www.youtube.com/@DIMENSIONCODE) explaining the concept of fractals and how to generate them here:\n\n|[![Comment Générer des Fractales ? ❄️](assets/maxresdefault.webp)](https://youtu.be/wUlVFYJIUNA)|\n|:-------:|\n| **Comment Générer des Fractales ? ❄️** |\n| *🇫🇷 French only*|\n\nThe video is ≈ 20 minutes long, but the part that we need to get started can be summarised as:\n\n* The $a$ (real) part of the complex number is represented on a x-axis.\n* The $b$ (imaginary) part of the complex number is represented on a y-axis.\n* This means that the coordinates $(3, 7)$ represent number $z = 3 + 7i$, and that every pixel of a window can be used to represent a complex number.\n* Every complex number put into the suite will either:\n\n\t* converge to a finite number\n\t* diverge to infinity.\n\n* The pixels of the window can be colored depending on whether the complex number they represent converges or diverges.\n\n* If we paint every pixel of the window in ![black](assets/000000.webp) if the complex number they represent converges or ![white](assets/ffffff.webp) if it diverges, we can see it already generates a fractal:\n\n\t|![Example](assets/orthonormal.webp)|\n\t|:-------:|\n\t| *Screenshot from the video* |\n\n### From math to code\n\n1. Setup the MiniLibX library.\n\t* You can find good resources on how to do this [here](https://qst0.github.io/ft_libgfx/man_mlx.html).\n2. Create a window, image and all the necessary things in the MiniLibX.\n3. Iterate through every pixel of the window.\n\t* *See [`draw_fractal`](#draw_fractal)*.\n4. For every pixel, calculate the complex number it represents and put it into the suite.\n\t* *See [`calculate_mandelbrot`](#calculate_mandelbrot) for example*.\n5. If the suite diverges, color the pixel in ![white](assets/ffffff.webp).\n6. If the suite converges, color the pixel in ![black](assets/000000.webp).\n\n\n## Main functions\n\n### `draw_fractal`\n\n```c\nint draw_fractal(t_fractal *fractal, char *query, double cx, double cy)\n```\nAs explained before, this function simply iterates through the pixels of the window and calls the appropriate function to draw the fractal.\n\n### `calculate_mandelbrot`\n\n```c\nvoid calculate_mandelbrot(t_fractal *fractal)\n```\n* The $z$ variables are set to 0, the beginning of the suite.\n\n* The $c$ constants are set to the coordinates of the pixel.\n\n* For performance reasons, we use the `(x * x)` calculation instead of the\n`pow(x, 2)` function.\n\n* The suite is iterated until:\n\n\t* **The absolute value of z is greater than the system's max values**: the suite will diverge to infinity.\n\n\t* **The number of iterations is too high**: the suite will stay stuck in an infinite loop.\n\n* If the the suite diverges, we color it and multiply the color by the number of iterations to make the mathematical depths more clear to the\neye.\n\n***🎉 Fun fact**: the British Standard subtitle color, ![#FCBE11](assets/fcbe11.webp) `#FCBE11` gives some pretty cool psychedelic renders when multiplied by the number of iterations*\n\n\u003e `calculate_julia` and `calculate_burning_ship` are very similar to `calculate_mandelbrot`, but with different equations.\n\n## Demonstrations\n\n### Mandelbrot\n\n|![Mandelbrot](assets/mandelbrot.webp)|\n|:-------:|\n| $z_{n+1} = z_n^2 + c$ |\n\n### Julia\n\n|![Julia](assets/julia.webp)|\n|:-------:|\n| $c_{real} = -0.745429$ and $c_{imaginary} = 0.05$ |\n\n### Burning Ship\n\n|![Burning Ship](assets/burning_ship.webp)|\n|:-------:|\n| $z_{n+1}=abs(z_n)^2+c$ |\n\n## Resources and Credits\n\n*The understanding of the concept of fractals and the implementation of the program was done with the help of the following resources.*\n\n* **Mathematical principles, equations, and translation to code**\n\n\t* **Comment Générer des Fractales ?**: https://www.youtube.com/watch?v=wUlVFYJIUNA\n\n* **Use of threads to improve performance** (not included here for the moment)\n\n\t* https://github.com/GlThibault/Fractol/\n\n* **Draw pixels on image**\n\n\t\u003e 💡 Don't use `mlx_pixel_put` like I did at first.\n\t\u003e\n\t\u003e It's slow and you can't re-render the canvas.\n\t\u003e\n\t\u003e Use `mlx_put_image_to_window` instead.\n\t* https://gontjarow.github.io/MiniLibX/mlx-tutorial-create-image.html\n\n* **Explore more**\n\t* **Other fractals and equations**: https://fractalfoundation.org/OFC/OFC-5-5.html\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleogaudin%2Ffract-ol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleogaudin%2Ffract-ol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleogaudin%2Ffract-ol/lists"}