def main(argv): view = commandline.get_view(argv) eye = commandline.get_eye(argv) light = commandline.get_light(argv) ambient = commandline.get_ambient(argv) sphere_list = commandline.get_sphere_list(argv[1]) cast.cast_all_rays(view[0], view[1], view[2], view[3], int(view[4]), int(view[5]), eye, sphere_list, ambient, light)
def main(): start_time = datetime.datetime.now() # create scene eye = data.Point(0.0, 0.0, -14.0) spheres = [data.Sphere(data.Point(.5, 1.5, -3.0), 0.5, data.Color(1, 0, 0), data.Finish(.4, .4, .5, .05)), data.Sphere(data.Point(1.0, 1.0, 0.0), 2.0, data.Color(0, 0, 1), data.Finish(.2, .4, .5, .05))] ambientColor = data.Color(1.0, 1.0, 1.0) pointLight = data.Light(data.Point(-100.0, 100.0, -100.0), data.Color(1.5, 1.5, 1.5)) # easy scaling of final image size scale = 1 width = 1024 / scale height = 768 / scale with open('image.ppm', 'w') as f: # ppm p3 headerwith f.write("P3\n") f.write(str(width) + " " + str(height) + '\n') f.write('255\n') cast.cast_all_rays(-10, 10, -7.5, 7.5, width, height, eye, spheres, ambientColor, pointLight, f) end_time = datetime.datetime.now() diff_time = end_time - start_time print >> sys.stderr, diff_time
def main(): args = sys.argv sphere_list = get_sphere_list(args[1]) eye_point = data.Point(0.0, 0.0, -14.0) view = [-10.0, 10.0, -7.5, 7.5, 1024, 768] ambient_light = data.Color(1.0, 1.0, 1.0) light = data.Light(data.Point(-100.0, 100.0, -100.0), data.Color(1.5, 1.5, 1.5)) if len(args) > 2: try: for i in range(2, len(args)): if args[i] == "-eye": l = args[i:i + 4] eye_point = commandline.get_eye_point(l, [0.0, 0.0, -14.0]) elif args[i] == "-view": l = args[i:i + 7] view = commandline.get_view(l, view) elif args[i] == "-light": l = args[i:i + 7] light = commandline.get_light( l, [-100.0, 100.0, -100.0, 1.5, 1.5, 1.5]) elif args[i] == "-ambient": l = args[i:i + 4] ambient_light = commandline.get_ambient_light( l, [1.0, 1.0, 1.0]) except: print "Something went horribly wrong" cast.cast_all_rays(view[0], view[1], view[2], view[3], view[4], view[5], eye_point, sphere_list, ambient_light, light)
def main(): args = sys.argv sphere_list = get_sphere_list(args[1]) eye_point = data.Point(0.0,0.0,-14.0) view = [-10.0, 10.0, -7.5,7.5, 1024, 768] ambient_light = data.Color(1.0,1.0,1.0) light = data.Light(data.Point(-100.0, 100.0,-100.0), data.Color(1.5,1.5,1.5)) if len(args) > 2: try: for i in range(2,len(args)): if args[i] == "-eye": l = args[i:i+4] eye_point = commandline.get_eye_point(l, [0.0,0.0,-14.0]) elif args[i] == "-view": l = args[i:i+7] view = commandline.get_view(l, view) elif args[i] == "-light": l = args[i:i+7] light = commandline.get_light(l, [-100.0,100.0,-100.0,1.5,1.5,1.5]) elif args[i] == "-ambient": l = args[i:i+4] ambient_light = commandline.get_ambient_light(l, [1.0,1.0,1.0]) except: print "Something went horribly wrong" cast.cast_all_rays(view[0],view[1],view[2],view[3], view[4], view[5], eye_point, sphere_list, ambient_light, light)
def create_file(): args = commandline.main(sys.argv) sphere_list = args[0] eye_point = args[1][0] view = args[1][1] light = args[1][2] ambient = args[1][3] cast.cast_all_rays(view[0], view[1], view[2], view[3], view[4], view[5], \ eye_point, sphere_list, ambient, light)
def main(argv): argument_errors = commandline.argment_errors(defaults, argv) if not argument_errors[0]: print "Argument Error, a valid .in file is needed as the first argument." exit(1) sphere_list = commandline.get_sphere_list(argv[1]) arg_dict = commandline.find_cast_args(defaults, argv) cast.cast_all_rays(defaults["min_x"], defaults["max_x"], defaults["min_y"], defaults["max_y"], defaults["width"], defaults["height"], defaults["eye_point"], sphere_list, defaults["ambient_color"], defaults["light"], defaults["outfile"])
def main(): """Outputs P3 header information, then runs raycasting on our sample data""" width = 512 height = 384 print('P3') print(width, height) print(255) ep = Point(0, 0, -14) lt = Light(Point(-100.0, 100.0, -100.0), Color(1.5, 1.5, 1.5)) sl = [ Sphere(Point(1, 1, 1), 2., Color(0, 0, 1), Finish(.2, .4, .5, .05)), Sphere(Point(.5, 1.5, -2), .5, Color(1, 0, 0), Finish(.4, .4, .5, .05)) ] cast_all_rays(-10, 10, -7.5, 7.5, width, height, ep, sl, Color(1, 1, 1), lt)
def main(): sphere_list = [] #try to open file or throw error try: input_file = open(argv[1], "r") except: print "Error: Filename not correctly specified" print "Usage: python ray_caster.py <filename> [-eye x y z] [-view min_x max_x min_y max_y width height" exit() #try to instantiate spheres from argv inputs or throw error line_count = 0 for line in input_file: line_count += 1 try: params = line.split() x = float(params[0]) y = float(params[1]) z = float(params[2]) rad = float(params[3]) r = float(params[4]) g = float(params[5]) b = float(params[6]) amb = float(params[7]) diff = float(params[8]) spec = float(params[9]) rough = float(params[10]) sphere = Sphere(Point(x, y, z), rad, Color(r, g, b), Finish(amb, diff, spec, rough)) sphere_list.append(sphere) except: print "malformed sphere on line {0} ... skipping".format(str(line_count)) #initialize casting variables relative to argv inputs eye_point = get_eye_point(argv) view = get_view(argv) light = get_light(argv) ambient = get_ambient(argv) #write to image.ppm output image file = open("image.ppm", "w") file.write("P3\n") file.write("{0} {1}\n".format(str(view.width), str(view.height))) file.write("{0}\n".format(str(255))) cast_all_rays(view, eye_point, sphere_list, ambient, light, file) file.close()
def dtest_cast_all_rays(): myeye= Point(0.0, 0.0, -14.0) red= Color(1.0, 0.0, 0.0) blue= Color(0.0, 0.0, 1.0) green= Color(0.0,1.0,0.0) white= Color(1.0, 1.0, 1.0) myambient1= Finish(0.2, 0.4, 0.5, 0.05) myambient2= Finish(0.4, 0.4, 0.5, 0.05) sphere1= Sphere(Point(1.0, 1.0, 0.0), 2.0, blue, myambient1) sphere2= Sphere(Point(0.5, 1.5, -3.0), 0.5, red, myambient2) myspherelist= [sphere1, sphere2] myambientlight= Color(1.0, 1.0, 1.0) light= Light(Point(-100.0, 100.0, -100.0), Color(1.5, 1.5, 1.5)) print "P3" print 1024, 768 print 255 cast.cast_all_rays(-10.0, 10.0, -7.5, 7.5, 1024, 768, myeye, myspherelist, myambientlight, light)
def main(): """ Main raycasting function Opens the output and input files Reads in and creates a list of spheres from input file Raycasts and writes image to output file """ try: in_file = open(argv[1], 'r') lines = in_file.readlines() except: print('Could not open input file') return try: out_file = open('image.ppm', 'w') except: print('Could not open output file') return sphere_list = [] for i in range(len(lines)): try: v = lines[i].split() p = Point(float(v[0]), float(v[1]), float(v[2])) r = float(v[3]) c = Color(float(v[4]), float(v[5]), float(v[6])) f = Finish(float(v[7]), float(v[8]), float(v[9]), float(v[10])) s = Sphere(p, r, c, f) sphere_list.append(s) except: print('Error on line' + str(i + 1) + ', skipping...') try: out_file.write('P3\n') out_file.write(str(width) + ' ' + str(height) + '\n') out_file.write('255\n') cast_all_rays(min_x, max_x, min_y, max_y, width, height, eye_point, sphere_list, color, light, out_file) except: print('Error writing to file')
def main(argv): args = commandline.process_args(argv) # tuple # 0: sphere list # 1: eye point # 2: view info (min_x, max_x, min_y, max_y, width, height) # 3: point light # 4: ambient color start = datetime.datetime.now() with open('image.ppm', 'w') as output_file: output_file.write('P3\n' + str(args[2][4]) + ' ' + str(args[2][5]) + '\n255\n') cast.cast_all_rays(args[2][0], args[2][1], args[2][2], args[2][3], args[2][4], args[2][5], args[1], args[0], args[4], args[3], output_file) end = datetime.datetime.now() delta = end - start print 'Time: ', str(delta)
def create_picture(): eyept = data.Point(0.0, 0.0, -14.0) sph1 = data.Sphere(data.Point(1.0, 1.0, 0.0), 2.0, data.Color(0.0, 0.0, \ 1.0), data.Finish(0.2, 0.4, 0.5, 0.05)) sph2 = data.Sphere(data.Point(0.5, 1.5, -3.0), 0.5, data.Color(1.0, 0.0, \ 0.0), data.Finish(0.4, 0.4, 0.5, 0.05)) S = [sph1, sph2] min_x = -10 max_x = 10 min_y = -7.5 max_y = 7.5 width = 1024 height = 768 ambient = 1.0 light = data.Light(data.Point(-100.0, 100.0, -100.0), data.Color(1.5, 1.5, \ 1.5)) cast.cast_all_rays(min_x, max_x, min_y, max_y, width, height, eyept, S, \ ambient, light)
eye_point = data.Point(0.0, 0.0, -14.0) light = data.Light(data.Point(-100.0, 100.0, -100.0), data.Color(1.5, 1.5, 1.5)) sphere_1 = data.Sphere(data.Point(1.0, 1.0, 0.0), 2.0, data.Color(0.0, 0.0, 1.0), data.Finish(0.2, 0.4, 0.5, 0.05)) sphere_2 = data.Sphere(data.Point(0.5, 1.5, -3.0), 0.5, data.Color(1.0, 0.0, 0.0), data.Finish(0.4, 0.4, 0.5, 0.05)) sphere_list = [sphere_1, sphere_2] ambient = data.Color(1.0, 1.0, 1.0) cast.cast_all_rays(min_x, max_x, min_y, max_y, width, height, eye_point, sphere_list, ambient, light) """ import data import cast min_x = -10 max_x = 10 min_y = -7.5 max_y = 7.5 width = 512 height = 384 eye_point = data.Point(0.0, 0.0, -14.0) sphere_1 = data.Sphere(data.Point(1.0, 1.0, 0.0), 2.0, data.Color(0.0, 0.0, 1.0)) sphere_2 = data.Sphere(data.Point(0.5, 1.5, -3.0), 0.5, data.Color(1.0, 0.0, 0.0))
import data import cast eyePoint = data.Point(0.0, 0.0, -14.0) ambient_light = data.Color(1.0, 1.0, 1.0) light = data.Light(data.Point(-100.0, 100.0, -100.0), data.Color(1.5, 1.5, 1.5)) a = data.Sphere(data.Point(1.0, 1.0, 0.0), 2.0, data.Color(0.0, 0.0, 1.0), data.Finish(.2, .4, .5, .05)) b = data.Sphere(data.Point(.5, 1.5, -3.0), .5, data.Color(1.0, 0.0, 0.0), data.Finish(.4, .4, .5, .05)) cast.cast_all_rays(-10.0, 10.0, -7.5, 7.5, 1024, 768, eyePoint, [a, b], ambient_light, light)
import data import cast eyePoint = data.Point(0.0, 0.0, -14.0) ambient_light = data.Color(1.0,1.0,1.0) light = data.Light(data.Point(-100.0, 100.0,-100.0), data.Color(1.5,1.5,1.5)) a = data.Sphere(data.Point(1.0,1.0,0.0), 2.0, data.Color(0.0,0.0,1.0), data.Finish(.2, .4, .5, .05)) b = data.Sphere(data.Point(.5,1.5,-3.0), .5, data.Color(1.0,0.0,0.0), data.Finish(.4, .4, .5, .05)) cast.cast_all_rays(-10.0,10.0,-7.5,7.5, 1024, 768, eyePoint, [a,b], ambient_light, light)
def main(argv: typing.List[str]): arguments = commandline.process_cmdArguments(argv) write_file = file_funcs.open_file('image.ppm', 'w') cast.cast_all_rays(-10, 10, -7.5, 7.5, 512, 384, data.Point(0, 0, -14), arguments[2], arguments[1], arguments[0], write_file) write_file.close()
import cast import data eye_point = data.Point(0.0, 0.0, -14.0) sphere_list = [ data.Sphere(data.Point(1.0, 1.0, 0.0), 2.0, data.Color(0, 0, 1.0), data.Finish(0.2, 0.4, 0.5, 0.05)), data.Sphere(data.Point(0.5, 1.5, -3.0), 0.5, data.Color(1.0, 0, 0), data.Finish(0.4, 0.4, 0.5, 0.05)) ] light = data.Light(data.Point(-100.0, 100.0, -100.0), data.Color(1.5, 1.5, 1.5)) cast.cast_all_rays(-10, 10, -7.5, 7.5, 1024, 768, eye_point, sphere_list, data.Color(1.0, 1.0, 1.0), light)
import cast import data import sys import commandline read = commandline.reader(1) #read first file (input) sphere_list = commandline.file_to_sphere_list(read) eye_point = commandline.check_eye() min_x,max_x,min_y,max_y,width,height = commandline.check_view() light = commandline.check_light() ambient = commandline.check_ambient() cast.cast_all_rays(min_x,max_x,min_y,max_y,width,height,eye_point,sphere_list,ambient,light)
sphere2 = data.Sphere(data.Point(0.5, 1.5, -3.0), 0.5, data.Color(1.0, 0, 0), data.Finish(0.4, 0.4, 0.5, 0.05)) sphere_list = [sphere1, sphere2] ambient_color = data.Color(1., 1., 1.) light = data.Light(data.Point(-100, 100, -100), data.Color(1.5, 1.5, 1.5)) min_x = -10 max_x = 10 min_y = -7.5 max_y = 7.5 width = 1024 * 8 height = 768 * 8 outfile = open("image.ppm", "w") # debug values min_x_d = 0.05859357 max_x_d = 0.44921857 min_y_d = 2.03125 max_y_d = 2.421875 width_d = 20 height_d = 20 if __name__ == "__main__": if mode == 'debug': cast.cast_all_rays(min_x_d, max_x_d, min_y_d, max_y_d, width_d, height_d, eye_point, sphere_list, ambient_color, light, outfile) else: cast.cast_all_rays(min_x, max_x, min_y, max_y, width, height, eye_point, sphere_list, ambient_color, light, outfile)
import data import math import utility import vector_math import collisions import cast eye_point = data.Point(0, 0, -14.0) color = data.Color(1.0, 1.0, 1.0) sphere1 = data.Sphere(data.Point(1.0, 1.0, 0.0), 2.0, data.Color(0, 0, 1.0), data.Finish(0.2, .4, .5, .05)) sphere2 = data.Sphere(data.Point(0.5, 1.5, -3.0), .5, data.Color(1.0, 0, 0), data.Finish(0.4, .4, .5, .05)) sphere_list = [sphere1, sphere2] color = data.Color(1.0, 1.0, 1.0) min_x = -10 max_x = 10 min_y = -7.5 max_y = 7.5 width = 1024 height = 768 light = data.Light(data.Point(-100.0, 100.0, -100.0), data.Color(1.5, 1.5, 1.5)) cast.cast_all_rays(min_x, max_x, min_y, max_y, width, height, eye_point, sphere_list, color, light)
import cast import data eye_point = data.Point(0.0,0.0,-14.0) sphere_list = [data.Sphere(data.Point(1.0,1.0,0.0), 2.0, data.Color(0,0,1.0), data.Finish(0.2,0.4,0.5,0.05)), data.Sphere(data.Point(0.5,1.5,-3.0), 0.5, data.Color(1.0,0,0), data.Finish(0.4,0.4,0.5,0.05))] light = data.Light(data.Point(-100.0,100.0,-100.0), data.Color(1.5,1.5,1.5)) cast.cast_all_rays(-10,10,-7.5,7.5,1024,768,eye_point,sphere_list, data.Color(1.0,1.0,1.0),light)
def read_file(file_name): count = 0 list_of_spheres = [] for line in file_name: count += 1 a = line.split() if len(a) != 11: print "malformed sphere on line ", count, " ...skipping" else: try: sphere_center = data.Point(float(a[0]), float(a[1]), float(a[2])) sphere_radius = float(a[3]) sphere_color = data.Color(float(a[4]), float(a[5]), float(a[6])) sphere_finish = data.Finish(float(a[7]), float(a[8]), float(a[9]), float(a[10])) sphere_complete = data.Sphere(sphere_center, sphere_radius, sphere_color, sphere_finish) list_of_spheres.append(sphere_complete) except: print "malformed sphere on line ", count, "...skipping" return list_of_spheres list_of_spheres = read_file(file_name) cast.cast_all_rays(arg_list[1], arg_list[2], arg_list[3], arg_list[4], int(arg_list[5]), int(arg_list[6]), arg_list[0], list_of_spheres, arg_list[8], arg_list[7])