commit 7e9c50b764e850da9277812b42ebea67bba2cd27 Author: Jean-Michel Gorius Date: Thu Nov 10 21:17:15 2022 +0100 Initial commit diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..9b3aa8b --- /dev/null +++ b/.clang-format @@ -0,0 +1 @@ +BasedOnStyle: LLVM diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d0f11d4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +build/ + +*.ppm + +.clangd/ +.cache/ +.vs/ +.vscode/ + +compile_flags.txt diff --git a/README.md b/README.md new file mode 100644 index 0000000..6c1673f --- /dev/null +++ b/README.md @@ -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. diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..8848b68 --- /dev/null +++ b/build.sh @@ -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} diff --git a/main.c b/main.c new file mode 100644 index 0000000..0ff2659 --- /dev/null +++ b/main.c @@ -0,0 +1,24 @@ +#include + +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; +}