35 lines
		
	
	
		
			985 B
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			985 B
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
| #!/opt/homebrew/bin/python3.11
 | |
| 
 | |
| from raytracer import *
 | |
| 
 | |
| c = color(1, 1, 1)
 | |
| p = point(-10, 10, -10)
 | |
| 
 | |
| light = pointlight(p, c)
 | |
| 
 | |
| w = world(light)
 | |
| 
 | |
| middle = sphere() \
 | |
|     .set_material(material().diffuse(.7).specular(.3).color(color(.1, 1, .5))) \
 | |
|     .set_transform(matrix.translation(-.5, 1, .5))
 | |
| w.add_object(middle)
 | |
| 
 | |
| right = sphere() \
 | |
|     .set_material(material().diffuse(.7).specular(.3).color(color(.5, 1, .1))) \
 | |
|     .set_transform(matrix.translation(1.5, .5, -.5).multiply(matrix.scaling(.5, .5, .5)))
 | |
| w.add_object(right)
 | |
| 
 | |
| left = sphere() \
 | |
|     .set_material(material().diffuse(.7).specular(.3).color(color(1, .8, .1))) \
 | |
|     .set_transform(matrix.translation(-1.5, .33, -.75).multiply(matrix.scaling(.33, .33, .33)))
 | |
| w.add_object(left)
 | |
| 
 | |
| c = camera(640, 480, math.pi/3)
 | |
| frm = point(0, 1.5, -5)
 | |
| to = point(0, 1, 0)
 | |
| up = vector(0, 1, 0)
 | |
| camera_transform = camera_view_transform(frm, to, up);
 | |
| c.set_transform(camera_transform)
 | |
| canvas = c.render(w)
 | |
| canvas.write_to_file("test.ppm")
 |