Skip to content

Instantly share code, notes, and snippets.

@dyoo
Last active December 15, 2015 16:09
Show Gist options
  • Save dyoo/5286702 to your computer and use it in GitHub Desktop.
Save dyoo/5286702 to your computer and use it in GitHub Desktop.
#lang racket
(require racket/draw)
(define bm (make-bitmap 640 480))
(define dc (send bm make-dc))
(define pixs (make-hash))
(define black (make-object color% 0 0 0))
(define (plot row col)
(hash-set! pixs (list col row) 1)
(send dc set-pixel col row black))
(define (pick row col)
(hash-ref pixs (list col row) 0))
(define (is_on_next_gen row col)
(not (equal? (pick (- row 1) (- col 1))
(pick (- row 1) (+ col 1)))))
(define (compute_row (gen 1) (start 319) (end 321))
(when (is_on_next_gen gen start) (plot gen start))
(cond [(= start end)
(compute_row (+ 1 gen) (- 319 gen) (+ 321 gen))]
[(= gen 128)
(void)]
[else
(compute_row gen (+ 1 start) end)]))
(time (plot 0 320))
(time (compute_row))
(time bm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment