-
-
Save meyer9/35d746cbfaa662f26ee6327f4d48f24a to your computer and use it in GitHub Desktop.
Modifications to Scheme art to run faster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import struct | |
with open('test.ppm', 'wb') as ppm_file: | |
ppm_file.write("P6\n".encode('ascii')) | |
with open('test.txt', 'r') as out: | |
width = int(out.readline()) | |
height = int(out.readline()) | |
ppm_file.write((str(width) + ' ' + str(height) + '\n').encode('ascii')) | |
ppm_file.write('255\n'.encode('ascii')) | |
ppm = [] | |
for i in range(height): | |
ppm_line = [] | |
for j in range(width): | |
r = int(float(out.readline())) | |
g = int(float(out.readline())) | |
b = int(float(out.readline())) | |
ppm_line.append(struct.pack('BBB', r, g, b)) | |
ppm.append(b''.join(ppm_line[::-1])) | |
ppm_file.write(b''.join(ppm[::-1])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; ADD THESE FUNCTIONS TO THE TOP OF contest.scm | |
(define (screen_width) | |
600 | |
) | |
(define (screen_height) | |
600 | |
) | |
(define (rgb r g b) | |
(newColor r g b) | |
) | |
(define (pixel x y c) | |
(print (floor (* (color_r c) 255))) | |
(print (floor (* (color_g c) 255))) | |
(print (floor (* (color_b c) 255))) | |
) | |
;; REPLACE THE DRAW FUNCTION WITH THIS | |
(define (draw) | |
(print (screen_width)) | |
(print (screen_height)) | |
(drawfunc raytrace 0 (screen_width) (screen_height)) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
csc contest.scm && ./contest > test.txt && python outtoppm.py && convert test.ppm test.png && rm test.ppm test.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment