Last active
December 15, 2015 16:09
-
-
Save dyoo/5286702 to your computer and use it in GitHub Desktop.
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
#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