This commit is contained in:
Miloslav Ciz 2024-09-22 01:02:44 +02:00
parent 8604bfc7c0
commit fb848d51f1
16 changed files with 1947 additions and 1855 deletions

View file

@ -69,6 +69,81 @@ There exist also [compression](compression.md) techniques based on fractals, see
There also exist such things as fractal antennas and fractal transistors.
## Example
Here is [C](c.md) code that draws one of the super simple fractals: Sierpinski triangle:
```
#include <stdio.h>
char sierpinski(int x, int y, int w, int h)
{
if (x >= w/2 && y < h/2)
return ' ';
if (w <= 1 || h <= 1)
return 'H';
return sierpinski(x % (w/2),y % (h/2),w/2,h/2);
}
int main(void)
{
#define W 32
#define H 32
for (int y = 0; y < W; ++y)
{
for (int x = 0; x < H; ++x)
{
char c = sierpinski(x,y,W,H);
putchar(c); putchar(c);
}
putchar('\n');
}
return 0;
}
```
which outputs:
```
HH
HHHH
HH HH
HHHHHHHH
HH HH
HHHH HHHH
HH HH HH HH
HHHHHHHHHHHHHHHH
HH HH
HHHH HHHH
HH HH HH HH
HHHHHHHH HHHHHHHH
HH HH HH HH
HHHH HHHH HHHH HHHH
HH HH HH HH HH HH HH HH
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
HH HH
HHHH HHHH
HH HH HH HH
HHHHHHHH HHHHHHHH
HH HH HH HH
HHHH HHHH HHHH HHHH
HH HH HH HH HH HH HH HH
HHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHH
HH HH HH HH
HHHH HHHH HHHH HHHH
HH HH HH HH HH HH HH HH
HHHHHHHH HHHHHHHH HHHHHHHH HHHHHHHH
HH HH HH HH HH HH HH HH
HHHH HHHH HHHH HHHH HHHH HHHH HHHH HHHH
HH HH HH HH HH HH HH HH HH HH HH HH HH HH HH HH
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
```
## See Also
- [Lissajous curve](lissajous_curve.md)