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
|
#!/usr/bin/env ruby
Maths = Math
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
require 'interval'
require 'vec3'
require 'ray'
require 'hittable'
require 'camera'
require 'material'
#mat_ground = Lambertian.new(Colour.new(0.8, 0.8, 0.0))
#mat_centre = Lambertian.new(Colour.new(0.1, 0.2, 0.5))
#mat_left = Dielectric.new(1.5)
#mat_bubble = Dielectric.new(1 / 1.5)
#mat_right = Metal.new(Colour.new(0.8, 0.6, 0.2), 1.0)
#
#world = Hittables.new
#world << Sphere.new(Point.new( 0, -100.5, -1), 100, mat_ground)
#world << Sphere.new(Point.new( 0, 0, -1.2), 0.5, mat_centre)
#world << Sphere.new(Point.new(-1, 0, -1), 0.5, mat_left)
#world << Sphere.new(Point.new(-1, 0, -1), 0.4, mat_bubble)
#world << Sphere.new(Point.new( 1, 0, -1), 0.5, mat_right)
#
#camera = Camera.new(400, 16.0 / 9,
# vfov: 20,
# lookfrom: Point.new(-2,2,1),
# defocus_angle: 10, focus_dist: 3.4)
#camera.render(world)
world = Hittables.new
mat_ground = Lambertian.new(Colour.new(0.5, 0.5, 0.5))
world << Sphere.new(Point.new(0.0, -1000.0, 0.0), 1000.0, mat_ground)
(-4...4).each do |a|
(-4...4).each do |b|
centre = Point.new(a + 0.9 * rand, 0.2, b + 0.9 * rand)
if (centre - Point.new(4, 0.2, 0)).mag > 0.9
s_mat = case rand
when 0...0.8
albedo = Colour.random * Colour.random
Lambertian.new(albedo)
when 0.8...0.95
albedo = Colour.random(min: 0.5, max: 1)
fuzz = rand(0...0.5)
Metal.new(albedo, fuzz)
else
Dielectric.new(1.5)
end
world << Sphere.new(centre, 0.2, s_mat)
end
end
end
mat1 = Dielectric.new(1.5)
world << Sphere.new(Point.new(0.0, 1.0, 0.0), 1.0, mat1)
mat2 = Lambertian.new(Colour.new(0.4, 0.2, 0.1))
world << Sphere.new(Point.new(-4.0, 1.0, 0.0), 1.0, mat2)
mat3 = Metal.new(Colour.new(0.7, 0.6, 0.5), 0.0)
world << Sphere.new(Point.new(4.0, 1.0, 0.0), 1.0, mat3)
camera = Camera.new(400, 16.0 / 9,
aliasing: 4, depth: 4,
vfov: 20.0,
lookfrom: Point.new(13.0, 2.0, 3.0),
lookat: Point.new,
defocus_angle: 0.6, focus_dist: 10.0)
camera.render(world)
|