Skip to content

Instantly share code, notes, and snippets.

@tonetheman
Created October 27, 2019 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonetheman/6a6728d41463f2e37ab0fd297b25617a to your computer and use it in GitHub Desktop.
Save tonetheman/6a6728d41463f2e37ab0fd297b25617a to your computer and use it in GitHub Desktop.
first program in raytracing in a weekend in racket
#lang racket
(define nx 200)
(define ny 100)
(display (string-append "P3\n"
(number->string nx) " "
(number->string ny) "\n255\n"))
(for ([j (in-range (- ny 1) 0 -1)])
(for ([i (in-range 0 (- nx 1))])
(let ([r (/ i nx)]
[g (/ j ny)]
[b 0.2])
(let ([ir (exact-round (* 255.99 r))]
[ig (exact-round (* 255.99 g))]
[ib (exact-round (* 255.99 b))])
(display (string-append (number->string ir)
" " (number->string ig)
" " (number->string ib) "\n"))
) ;; end of inner let
) ;; end of let first let
) ;; end of inner for
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment