{"id":23690791,"url":"https://github.com/dispatchcode/fractal","last_synced_at":"2025-09-02T20:31:31.472Z","repository":{"id":229352674,"uuid":"82615949","full_name":"DispatchCode/fraCtal","owner":"DispatchCode","description":"fraCtal generates fractals of any dimension that you want. It can generate fractals belonging at two sets: Mandelbrot and Julia.","archived":false,"fork":false,"pushed_at":"2025-06-27T15:25:43.000Z","size":122,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-27T16:32:15.716Z","etag":null,"topics":["c","fractals","mandelbrot-sets"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DispatchCode.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}},"created_at":"2017-02-21T00:09:26.000Z","updated_at":"2025-06-27T15:25:47.000Z","dependencies_parsed_at":"2024-03-23T19:22:28.419Z","dependency_job_id":"1c105333-352b-47d3-a6d1-82f5f3e37d83","html_url":"https://github.com/DispatchCode/fraCtal","commit_stats":null,"previous_names":["dispatchcode/fractal"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DispatchCode/fraCtal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DispatchCode%2FfraCtal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DispatchCode%2FfraCtal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DispatchCode%2FfraCtal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DispatchCode%2FfraCtal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DispatchCode","download_url":"https://codeload.github.com/DispatchCode/fraCtal/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DispatchCode%2FfraCtal/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273344602,"owners_count":25089012,"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","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","fractals","mandelbrot-sets"],"created_at":"2024-12-30T02:52:09.719Z","updated_at":"2025-09-02T20:31:31.189Z","avatar_url":"https://github.com/DispatchCode.png","language":"C","readme":"# fraCtal\n\n*fraCtal* generates fractals of any dimension that you want. It can generate fractals belonging at two sets: Mandelbrot and Julia.\n\n---\n## Supported features:\n✅ multithreading support \u003cbr\u003e\n✅ initial support to custom color palette \u003cbr\u003e\n✅ color can be personalized \u003cbr\u003e\n✅ image saved as a PNG file (using [lodepng](https://github.com/lvandeve/lodepng)) \u003cbr\u003e\n\n## Future plans:\n🎯 SDL2 support \u003cbr\u003e\n🎯 ImGUI support\n\nComparison between 1 vs 4 threads:\n\n 1-thread  |  4-thread  |   (x0, x1, y0, y1)      |\n-----------|------------|--------------------------|\n  166.30s   |  57.37s    | (0.37, 0.40, 0.21, 0.16) |\n198.322s    |  111.56s    | (0.37, 0.40, 0.21, 0.26) |\n 46.11s     |  21.60s     | (2.0, -2.0, 1.7, -1.7)   |\n\nYou can specify another number of threads in *main.c*.\n\n## The New Colors Algorithm\nThere are a lot a change in the color algorithm, and you can change some parameters to make it more or less interesting. \nA special thanks goes to [BrutPitt](https://github.com/BrutPitt) for the precious hints.\n\n```C\n// Blue and red from 0.00 to 255.0\ndouble blue_a = 0.0, blue_b = 255.0;\ndouble red_a  = 0.0, red_b  = 255.0;\n\n// Fractal must be red on x axis and blue on y axis\ndouble rstepx = (red_b - red_a) / coords-\u003ew;\ndouble bstepy = (blue_b - blue_a) / coords-\u003eh;\n```\n\nThe way the green channel get computed is the following:\n```C\nint val_in = 0, val_out = 0;\nint g = 0;\nif(k \u003e= 32) {\n    g = (int)(255.0 - ((((double)k + val_in)) / (coords-\u003emax_iterations + val_in) * (255.0-val_out)));\n}\n```\n\nBelow you can see how the fractal looks like:\n\n![mandelbrot_black](https://user-images.githubusercontent.com/4256708/164914316-288a4361-9051-49bb-82fb-6893b4b2bb2b.png)\n\nWith val_out = 0 and without attenuation (eg. you can comment the attenuation computation or set it to 1.0):\n\n![mandelbrot](https://user-images.githubusercontent.com/4256708/164915343-cb12b018-4fde-467d-a69c-753000c503a5.png)\n\nWith:\n\n```C\nint val_in = 32, val_out = 150;\nint g = 0;\nif(k \u003e= 32) {\n    g = (int)(255.0 - ((((double)k + val_in)) / (coords-\u003emax_iterations + val_in) * (255.0-val_out)));\n}\n```\nand without attenuation:\n\n![mandelbrot](https://user-images.githubusercontent.com/4256708/164915712-c72734dc-df8e-46a3-8827-ff9ef8bad535.png)\n\nWithout attenuation:\n\n```C\nint val_in = 32, val_out = 0;\nint g = 0;\nif(k \u003e= 0) {\n    g = (int)(255.0 - ((((double)k + val_in)) / (coords-\u003emax_iterations + val_in) * (255.0-val_out)));\n}\n```\n\n![mandelbrot](https://user-images.githubusercontent.com/4256708/164915832-daa5d8ab-3630-400c-a5c1-803e1bb5a455.png)\n\nWith:\n\n```C\ndouble blue_a = 255.0, blue_b = 255.0;\ndouble red_a  = 0.0, red_b  = 255.0;\n\nint val_in = 32, val_out = 32;\nint g = 0;\nif(k \u003e= 32) {\ng = (int)(255.0 - ((((double)k + val_in)) / (coords-\u003emax_iterations + val_in) * (255.0-val_out)));\n}\n\ndouble atten = ((double)k / coords-\u003emax_iterations);\natten = 1.0 - (atten*atten);\n\nr = (int)((double)r * atten);\nb = (int)((double)b * atten);\n```\nThe image will be:\n\n![mandelbrot](https://user-images.githubusercontent.com/4256708/164916149-8d533e4a-91c2-4849-ab8d-b0d9c8c14908.png)\n\n---\n\n## Color Palette\n\nLast but not least, now is possible load colors (R,G,B) from a text file with the following format:\n\n```\nsize (number of lines)\nr,g,b\nr,g,b\n.....\n```\n\nas an example, consider the image on Wikipedia: this are the colors:\n\n```\n16\n66,30,15\n25,7,26\n9,1,47\n4,4,73\n0,7,100\n12,44,138\n24,82,177\n57, 125,209\n134,181,229\n211,236,248\n241,233,191\n248,201,95\n255,170,0\n204,128,0\n153,87,0\n106,52,3\n```\n\nyou can find it the palette.txt file.\nAs a result we get:\n\n![mandelbrot_wiki](https://user-images.githubusercontent.com/4256708/77239653-700bfe00-6bdd-11ea-8027-9d8dc4a2b9fc.png)\n\n\nUncomment PALETTE in mandelbrot.h if you want use them.\n\n## Mathematical formula and explanation\n\nOn the web there are a lot of explanations about this formula so I don't want to be boring or maybe not totally precise.\n\n![](http://warp.povusers.org/Mandelbrot/eqn1.png)\n\n*Z* and *C* are two complex numbers. Complex numbers are composed by two parts: a real part, and a imaginary part. The formula tell to us that if the value of the function Zn for the value c is not infinite when n approaches infinity, then c belongs to the set. If C belongs to the set, then we choose the black color; otherwise the color will be white.\n\n## Besides mathematics: the code\n\nTo determine which will be the color (eg. black or not) we can't obviously iterate to infinity. Luckily maths tell that for definition if the absolute value of Z gets bigger of 2 it will never return closer to 2. So thanks to that we can iterate N times; N could be little but it depends from the number of pixels of the image.\n\nThis is my code:\n```C\ndouble y = info.y1 + (((double)j * (info.y0-info.y1)) / (double)info.h);\ndouble x = info.x1 + (((double)i * (info.x0-info.x1)) / (double)info.w);\n```\n\nHere *x* and *y* are the coords of the 2D plan (scaled). In this manner y and x are the imaginary part and the real part of the complex number *C* seen before (the point that we need to know if belong or not to the set).\n\nThe N number is chosen by user. We must just iterate till this value is reached or break the loop if the square root of the abs value is greater then 2; we can simplify this operation removing the sqrt and check for 4.\n\nHere the code:\n```C\nfor(i = 0; i \u003c info.depth; i++)\n{\n    z    = complex_sum(complex_mul(z, z), c);\n    *abs = complex_abs(z);\n\n    if(*abs \u003e 4.0) {\n        break;\n    }\n}\n```\n\nJust to summarize: if abs is greater than 4, the *C* point is not part of the set and it will be left white (but is common give another color based on the amount of iterations); if the value is below 4 then the common color is black because is part of the set.\n\n## The Area\n\nThe area is determined by x0, x1, y0 and y1. They represent the cartesian plane and they are the real part and imaginary part.\nThis four numbers are important because - how we will see - we can use them to zoomin or zoomout in the fractal.\n\n## The Colors\n\nIn the first part of this README I had talked about the Zn function and his result that tell to us if the value *C* belongs to the set or not. When *C* not belongs to the set we can set a color based on the numbers of the iterations. The intensity of the color differ based on the number of iterations.\n\nIf you want to change the primary color (eg, make the fractal red, green or blue or whatever) you must edit the code.\n\nHere some examples; all the images are generated using the same \"zoom\" (default zooming): x0=2.0, x1=-2.0, y0=2.0, y1=-2.0 and the same iterations, 2.000:\n\nFor example, to get this blue, you must use:\n\n```C\nint r =  iteration\u003e\u003e2;\nint g =  iteration\u003e\u003e1;\nint b =  iteration\u003c\u003c3;\n\nr = (r\u003e128) ? 128 : r;\ng = (g\u003e128) ? 128 : g;\nb = (b\u003e255) ? 255 : b;\n```\n\n![mandelbrot_blue](https://user-images.githubusercontent.com/4256708/77239813-0db3fd00-6bdf-11ea-97c1-982e35653d56.png)\n\n\nFor the green version, you must change the code in this way:\n\n```C\nint r =  iteration\u003e\u003e1;\nint g =  iteration\u003c\u003c3;\nint b =  iteration\u003e\u003e1;\n\nr = (r\u003e128) ? 128 : r;\ng = (g\u003e255) ? 255 : g;\nb = (b\u003e128) ? 128 : b;\n```\n\n![mandelbrot_green](https://user-images.githubusercontent.com/4256708/77239755-7babf480-6bde-11ea-9ab9-04f336782bac.png)\n\nFor the red/orange version:\n\n```C\nint r =  iteration\u003c\u003c2;\nint g =  iteration\u003e\u003e1;\nint b =  iteration\u003e\u003e2;\n\nr = (r\u003e255) ? 255 : r;\ng = (g\u003e128) ? 128 : g;\nb = (b\u003e128) ? 128 : b;\n```\n\n![mandelbrot_red1](https://user-images.githubusercontent.com/4256708/77239746-6767f780-6bde-11ea-8435-dae2557dad95.png)\n\nObviously this is not the only way to set a color.\n\nWe can also zoom in, how I said before. Let's take a look here, x0=0.37, x1=0.40, y0=0.21, y1=0.26 using the same red color:\n\n![mandel_red](https://user-images.githubusercontent.com/4256708/77239780-9c744a00-6bde-11ea-996b-3bfe71447003.png)\n\nHow you can see the color make the difference!\n\n# Gallery\n\n![fractal](https://user-images.githubusercontent.com/4256708/77239841-4fdd3e80-6bdf-11ea-8562-a1b9c01c8f3d.png)\n\n![mandelbroat_blue_zoom](https://user-images.githubusercontent.com/4256708/77240063-f7f40700-6be1-11ea-9f38-c13ff1490270.png)\n\n![mandelbrot_acquamarina](https://user-images.githubusercontent.com/4256708/77239849-64b9d200-6bdf-11ea-98d5-e276d224ca15.png)\n\n![mandelbrot_blue_green](https://user-images.githubusercontent.com/4256708/77239862-8024dd00-6bdf-11ea-8ad0-5e8889790ffb.png)\n\n![mandelbrot_light_blue](https://user-images.githubusercontent.com/4256708/77239869-96cb3400-6bdf-11ea-9210-5a842de806b7.png)\n\n![mandelbrot_orange](https://user-images.githubusercontent.com/4256708/77239872-a77baa00-6bdf-11ea-9c47-882b53eb7d77.png)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdispatchcode%2Ffractal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdispatchcode%2Ffractal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdispatchcode%2Ffractal/lists"}