More stuff fuckit
This commit is contained in:
parent
8c65c0aabd
commit
4569ddfb1a
47
demo.scm
47
demo.scm
@ -1,5 +1,4 @@
|
||||
(use-modules (graphgif)
|
||||
(srfi srfi-1))
|
||||
(use-modules (graphgif))
|
||||
|
||||
(define red (create-color 1 0 0))
|
||||
|
||||
@ -14,43 +13,7 @@
|
||||
((10 . 40) (0 2 4))
|
||||
((40 . 40) (1 2 3))))
|
||||
|
||||
(define (idx->x i w)
|
||||
(modulo i w))
|
||||
|
||||
(define (idx->y i w)
|
||||
(quotient i w))
|
||||
|
||||
(define (xy->idx x y w)
|
||||
(+ (* y w) x))
|
||||
|
||||
(define (idx->edges i w)
|
||||
(filter-map
|
||||
(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))))
|
||||
;; Auto-connect these directions if legal indices
|
||||
'(( 0 . -1)
|
||||
(-1 . 0)
|
||||
(-1 . -1)
|
||||
(+1 . -1))))
|
||||
|
||||
(define (generate-web w h)
|
||||
(define (make-node i)
|
||||
(list
|
||||
(cons (+ (* 30 (idx->x i w)) 10)
|
||||
(+ (* 30 (idx->y i w)) 10))
|
||||
(idx->edges i w)))
|
||||
(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 10 10) "graph.gif")
|
||||
(let* ([graph1 (generate-web 10 10)]
|
||||
[graph2 (list-copy graph1)])
|
||||
(set-car! graph2 (append (car graph2) `(,red)))
|
||||
(write-graphs-to-file (list graph1 graph2) "graph.gif"))
|
||||
|
53
graphgif.scm
53
graphgif.scm
@ -1,7 +1,8 @@
|
||||
(define-module (graphgif))
|
||||
|
||||
(use-modules (cairo)
|
||||
(cgif))
|
||||
(cgif)
|
||||
(srfi srfi-1))
|
||||
|
||||
(re-export (cairo-pattern-create-rgb . create-color))
|
||||
|
||||
@ -58,11 +59,53 @@
|
||||
(cairo-destroy cr)
|
||||
surface))
|
||||
|
||||
(define-public (write-graph-to-file graph filename)
|
||||
(define my-surface (draw-abstract-graph graph))
|
||||
(make-gif `(,my-surface) filename)
|
||||
(cairo-surface-destroy my-surface))
|
||||
(define-public (write-graphs-to-file graphs filename)
|
||||
(let ([surfaces (map draw-abstract-graph graphs)])
|
||||
(make-gif surfaces filename)
|
||||
(for-each (lambda (s) (cairo-surface-destroy s)) surfaces)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Graph Generation ;;
|
||||
;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(define (idx->x i w)
|
||||
(modulo i w))
|
||||
|
||||
(define (idx->y i w)
|
||||
(quotient i w))
|
||||
|
||||
(define (xy->idx x y w)
|
||||
(+ (* y w) x))
|
||||
|
||||
(define (idx->edges i w)
|
||||
(filter-map
|
||||
(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))))
|
||||
;; Auto-connect these directions if legal indices
|
||||
'(( 0 . -1)
|
||||
(-1 . 0)
|
||||
(-1 . -1)
|
||||
(+1 . -1))))
|
||||
|
||||
(define-public (generate-web w h)
|
||||
(define (make-node i)
|
||||
(list
|
||||
(cons (+ (* 30 (idx->x i w)) 10)
|
||||
(+ (* 30 (idx->y i w)) 10))
|
||||
(idx->edges i w)))
|
||||
(let loop ([i 0]
|
||||
[lst '()])
|
||||
(if (>= i (* w h))
|
||||
(reverse lst)
|
||||
(loop (1+ i) (cons (make-node i) lst)))))
|
||||
|
||||
;; Local Variables:
|
||||
;; geiser-scheme-implementation: guile
|
||||
|
Loading…
Reference in New Issue
Block a user