Code cleanup

This commit is contained in:
Dane Johnson 2024-10-11 17:57:45 -05:00
parent 9e8cf71d3b
commit da71b1bd85
2 changed files with 19 additions and 18 deletions

View File

@ -1 +0,0 @@
dane@deelite.633:1728402468

View File

@ -23,17 +23,20 @@
(define (idx->edges i w)
(filter-map
(lambda (x y)
(if (or (negative? (+ (idx->x i w) x))
(negative? (+ (idx->y i w) y))
(>= (+ (idx->x i w) x) w))
#f
(xy->idx
(+ (idx->x i w) x)
(+ (idx->y i w) y)
w)))
'(+0 -1 -1 +1)
'(-1 +0 -1 -1)))
(lambda (offset)
(let* ([x (idx->x i w)]
[y (idx->y i w)]
[ox (+ x (car offset))]
[oy (+ y (cdr offset))])
(and
(not (negative? ox))
(not (negative? oy))
(< ox w)
(xy->idx ox oy w))))
'(( 0 . -1)
(-1 . 0)
(-1 . -1)
(+1 . -1))))
(define (generate-web w h)
(define (make-node i)
@ -42,11 +45,10 @@
(+ (* 30 (idx->y i w)) 10))
(idx->edges i w)
white))
(reverse
(let loop ([i 0]
[lst '()])
(if (>= i (* w h))
lst
(loop (1+ i) (cons (make-node i) lst))))))
(let loop ([i 0]
[lst '()])
(if (>= i (* w h))
(reverse lst)
(loop (1+ i) (cons (make-node i) lst)))))
(write-graph-to-file (generate-web 5 5) (cadr (command-line)))