Add basic PPM generation
This commit is contained in:
commit
b8047f4d4e
|
@ -0,0 +1,16 @@
|
|||
.dub
|
||||
docs.json
|
||||
__dummy.html
|
||||
docs/
|
||||
/oneweekend-d
|
||||
oneweekend-d.so
|
||||
oneweekend-d.dylib
|
||||
oneweekend-d.dll
|
||||
oneweekend-d.a
|
||||
oneweekend-d.lib
|
||||
oneweekend-d-test-*
|
||||
*.exe
|
||||
*.o
|
||||
*.obj
|
||||
*.lst
|
||||
owe
|
|
@ -0,0 +1,16 @@
|
|||
# vim:noexpandtab
|
||||
|
||||
.PHONY: build clean run
|
||||
|
||||
dmd_opts = -de -w -unittest
|
||||
prog = owe
|
||||
main = source/$(prog).d
|
||||
|
||||
run:
|
||||
rdmd $(dmd_opts) $(main)
|
||||
|
||||
build:
|
||||
dmd $(dmd_opts) $(main)
|
||||
|
||||
clean:
|
||||
rm $(prog) $(prog).o
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"authors": [
|
||||
"Michael Kohl"
|
||||
],
|
||||
"copyright": "Copyright © 2021, Michael Kohl",
|
||||
"description": "Ray Tracing in One Weekend",
|
||||
"license": "MIT",
|
||||
"name": "oneweekend-d"
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,34 @@
|
|||
import std.conv : to;
|
||||
import std.format : format;
|
||||
import std.range : iota;
|
||||
import std.stdio;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
||||
// Image
|
||||
const int imageWidth = 256;
|
||||
|
||||
const imageHeight = 256;
|
||||
|
||||
// Render
|
||||
|
||||
write(format("P3\n%s %s\n255\n", imageWidth, imageHeight));
|
||||
for (int j = imageHeight - 1; j >= 0; --j)
|
||||
{
|
||||
stderr.write(format("\rScanlines remaining: %d", j));
|
||||
for (int i = 0; i < imageWidth; ++i)
|
||||
{
|
||||
auto r = to!double(i) / (imageWidth - 1);
|
||||
auto g = to!double(j) / (imageHeight - 1);
|
||||
auto b = 0.25;
|
||||
|
||||
const int ir = to!int(255.999 * r);
|
||||
const int ig = to!int(255.999 * g);
|
||||
const int ib = to!int(255.999 * b);
|
||||
|
||||
write(format("%d %d %d\n", ir, ig, ib));
|
||||
}
|
||||
}
|
||||
stderr.writeln("\nDone.");
|
||||
}
|
Loading…
Reference in New Issue