Initial commit.
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
main
|
||||||
|
raylib
|
||||||
2
Makefile
Normal file
2
Makefile
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
main: main.c
|
||||||
|
gcc main.c -o main -I./raylib/include -L./raylib/lib -lraylib -lm
|
||||||
6
README.md
Normal file
6
README.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# Mandelbrot using Raylib
|
||||||
|
|
||||||
|
Download [raylib](https://github.com/raysan5/raylib/releases) and extract it into `raylib`.
|
||||||
|
|
||||||
|
Then run `make` and `./main`.
|
||||||
|
|
||||||
57
main.c
Normal file
57
main.c
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#include <assert.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define WIDTH 800
|
||||||
|
#define HEIGHT 600
|
||||||
|
#define MAX_ITER 50
|
||||||
|
|
||||||
|
int mandelbrot(double x, double y) {
|
||||||
|
int k;
|
||||||
|
double u = 0.0;
|
||||||
|
double v = 0.0;
|
||||||
|
double u2 = 0.0;
|
||||||
|
double v2 = 0.0;
|
||||||
|
|
||||||
|
for (k = 1; k < MAX_ITER && (u2 + v2 < 4.0); k++) {
|
||||||
|
v = 2 * u * v + y;
|
||||||
|
u = u2 - v2 + x;
|
||||||
|
u2 = u * u;
|
||||||
|
v2 = v * v;
|
||||||
|
}
|
||||||
|
|
||||||
|
return k;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
InitWindow(WIDTH, HEIGHT, "Hello, raylib!");
|
||||||
|
|
||||||
|
double re_start = -2.0;
|
||||||
|
double re_end = 1.0;
|
||||||
|
double im_start = -1.0;
|
||||||
|
double im_end = 1.0;
|
||||||
|
|
||||||
|
while (!WindowShouldClose()) {
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
for (int x = 0; x < WIDTH; ++x) {
|
||||||
|
for (int y = 0; y < HEIGHT; ++y) {
|
||||||
|
double zreal = re_start + (x / (float) WIDTH) * (re_end - re_start);
|
||||||
|
double zimag = im_start + (y / (float) HEIGHT) * (im_end - im_start);
|
||||||
|
int m = mandelbrot(zreal, zimag);
|
||||||
|
assert(m >= 0 && m <= MAX_ITER);
|
||||||
|
|
||||||
|
unsigned char c = 255 - ((m * 255) / MAX_ITER);
|
||||||
|
Color color = { c, c, c, 255 };
|
||||||
|
DrawPixel(x, y, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EndDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseWindow();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user