-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (63 loc) · 1.96 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const fs = require("fs");
const path = require("path");
const { vec3 } = require("gl-matrix");
const mt = require("mersenne-twister");
const { render, canvas } = require("./camera");
const { hitSphere } = require("./sphere");
const { world } = require("./world");
const generator = new mt();
// world construction
const sphere1 = { hitSphere };
sphere1.material = {};
sphere1.material.type = "lambertian";
sphere1.center = vec3.fromValues(-1, 0, -1);
sphere1.radius = 0.2;
sphere1.attenuation = vec3.fromValues(0.5, 0.5, 0.5);
const sphere2 = { hitSphere };
sphere2.material = {};
sphere2.material.type = "metal";
sphere2.center = vec3.fromValues(0.5, 0, -1);
sphere2.radius = 0.2;
sphere2.attenuation = vec3.fromValues(0.8, 0.6, 0.2);
const groundSphere = { hitSphere };
groundSphere.material = { type: "metal" };
groundSphere.center = vec3.fromValues(0, -100.5, -1);
groundSphere.radius = 100;
groundSphere.attenuation = vec3.fromValues(0.8, 0.6, 0.2);
const sphere3 = { hitSphere };
sphere3.material = {};
sphere3.material.type = "metal";
sphere3.center = vec3.fromValues(-0.5, 0, -1);
sphere3.radius = 0.2;
sphere3.attenuation = vec3.fromValues(
generator.random(),
generator.random(),
generator.random()
);
const sphere4 = { hitSphere };
sphere4.material = {};
sphere4.material.type = "metal";
sphere4.center = vec3.fromValues(0, 0, -1);
sphere4.radius = 0.2;
sphere4.attenuation = vec3.fromValues(
generator.random(),
generator.random(),
generator.random()
);
const sphere5 = { hitSphere };
sphere5.material = {};
sphere5.material.type = "metal";
sphere5.center = vec3.fromValues(1, 0, -1);
sphere5.radius = 0.2;
sphere5.attenuation = vec3.fromValues(
generator.random(),
generator.random(),
generator.random()
);
// world.objects.push(sphere1, sphere2, sphere3, sphere4, sphere5, groundSphere);
render(world);
canvas
.createJPEGStream()
.pipe(fs.createWriteStream(path.join(__dirname, "/image.jpg")));
console.log("image created");
module.exports = { generator };