Initial commit

This commit is contained in:
Jean-Michel Gorius 2022-11-10 21:17:15 +01:00
commit 7e9c50b764
5 changed files with 51 additions and 0 deletions

1
.clang-format Normal file
View File

@ -0,0 +1 @@
BasedOnStyle: LLVM

10
.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
build/
*.ppm
.clangd/
.cache/
.vs/
.vscode/
compile_flags.txt

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# Ray tracing in one week-end
C implementation of the [*Ray tracing in one week-end*](https://raytracing.github.io/) series by Peter Shirley.

13
build.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
CC=${CC:-"gcc"}
CFLAGS=${CFLAGS:-"-Wall -Wextra -std=c18 -g"}
LDFLAGS=${LDFLAGS:-""}
MAIN_FILE=${MAIN_FILE:-"main.c"}
# Write out compile_flags.txt for clangd
echo "${CFLAGS}" | tr ' ' '\n' > compile_flags.txt
mkdir -p build
${CC} ${CFLAGS} ${MAIN_FILE} -o build/raytracer ${LDFLAGS}

24
main.c Normal file
View File

@ -0,0 +1,24 @@
#include <stdio.h>
int main(void) {
const int image_width = 256;
const int image_height = 256;
printf("P3\n%u %u\n255\n", image_width, image_height);
for(int j = image_height - 1; j >= 0; --j) {
for(int i = 0; i < image_width; ++i) {
double r = (double)(i) / (image_width - 1);
double g = (double)(j) / (image_height - 1);
double b = 0.25;
int ir = (int)(255.999 * r);
int ig = (int)(255.999 * g);
int ib = (int)(255.999 * b);
printf("%d %d %d\n", ir, ig, ib);
}
}
return 0;
}