Compare commits
No commits in common. "bc61ef7d8f1b4caa562734bb129728f2b2372c39" and "62fa4928230478b1a0955810b4d967080faee1d9" have entirely different histories.
bc61ef7d8f
...
62fa492823
52
demo.scm
52
demo.scm
@ -1,52 +0,0 @@
|
|||||||
(use-modules (graphgif)
|
|
||||||
(srfi srfi-1))
|
|
||||||
|
|
||||||
(define my-graph
|
|
||||||
`(((10 . 10) (1) ,white)
|
|
||||||
((30 . 20) () ,red)))
|
|
||||||
|
|
||||||
(define more-complex-graph
|
|
||||||
`(((10 . 10) () ,white)
|
|
||||||
((40 . 10) (0) ,white)
|
|
||||||
((25 . 25) (0 1) ,white)
|
|
||||||
((10 . 40) (0 2 4) ,white)
|
|
||||||
((40 . 40) (1 2 3) ,white)))
|
|
||||||
|
|
||||||
(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 (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)))
|
|
||||||
|
|
||||||
(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)
|
|
||||||
white))
|
|
||||||
(reverse
|
|
||||||
(let loop ([i 0]
|
|
||||||
[lst '()])
|
|
||||||
(if (>= i (* w h))
|
|
||||||
lst
|
|
||||||
(loop (1+ i) (cons (make-node i) lst))))))
|
|
||||||
|
|
||||||
(write-graph-to-file (generate-web 5 5) (cadr (command-line)))
|
|
35
graphgif.scm
35
graphgif.scm
@ -1,17 +1,28 @@
|
|||||||
(define-module (graphgif))
|
#!/usr/bin/guile -s
|
||||||
|
!#
|
||||||
(use-modules (cairo))
|
(use-modules (cairo))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;
|
||||||
;; Basic Drawing ;;
|
;; Basic Drawing ;;
|
||||||
;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
(define-public pi 3.14159)
|
(define pi 3.14159)
|
||||||
(define-public tau (* 2 pi))
|
(define tau (* 2 pi))
|
||||||
|
|
||||||
(define-public black (cairo-pattern-create-rgb 0 0 0))
|
(define black (cairo-pattern-create-rgb 0 0 0))
|
||||||
(define-public white (cairo-pattern-create-rgb 1 1 1))
|
(define white (cairo-pattern-create-rgb 1 1 1))
|
||||||
(define-public red (cairo-pattern-create-rgb 1 0 0))
|
(define red (cairo-pattern-create-rgb 1 0 0))
|
||||||
|
|
||||||
|
(define my-graph
|
||||||
|
`(((10 . 10) (1) ,white)
|
||||||
|
((30 . 20) () ,red)))
|
||||||
|
|
||||||
|
(define more-complex-graph
|
||||||
|
`(((10 . 10) () ,white)
|
||||||
|
((40 . 10) (0) ,white)
|
||||||
|
((25 . 25) (0 1) ,white)
|
||||||
|
((10 . 40) (0 2 4) ,white)
|
||||||
|
((40 . 40) (1 2 3) ,white)))
|
||||||
|
|
||||||
(define (edge-painter cr graph)
|
(define (edge-painter cr graph)
|
||||||
(lambda (node)
|
(lambda (node)
|
||||||
@ -40,7 +51,7 @@
|
|||||||
(cairo-set-source cr black)
|
(cairo-set-source cr black)
|
||||||
(cairo-stroke cr))))
|
(cairo-stroke cr))))
|
||||||
|
|
||||||
(define-public (draw-abstract-graph graph)
|
(define (draw-abstract-graph graph)
|
||||||
(let* ([surface (cairo-image-surface-create 'argb32 400 400)]
|
(let* ([surface (cairo-image-surface-create 'argb32 400 400)]
|
||||||
[cr (cairo-create surface)])
|
[cr (cairo-create surface)])
|
||||||
(define paint-edges (edge-painter cr graph))
|
(define paint-edges (edge-painter cr graph))
|
||||||
@ -54,11 +65,9 @@
|
|||||||
(cairo-destroy cr)
|
(cairo-destroy cr)
|
||||||
surface))
|
surface))
|
||||||
|
|
||||||
(define-public (write-graph-to-file graph filename)
|
(define my-surface (draw-abstract-graph more-complex-graph))
|
||||||
(define my-surface (draw-abstract-graph graph))
|
(cairo-surface-write-to-png my-surface (cadr (command-line)))
|
||||||
(cairo-surface-write-to-png my-surface filename)
|
(cairo-surface-destroy my-surface)
|
||||||
(cairo-surface-destroy my-surface))
|
|
||||||
|
|
||||||
|
|
||||||
;; Local Variables:
|
;; Local Variables:
|
||||||
;; geiser-scheme-implementation: guile
|
;; geiser-scheme-implementation: guile
|
||||||
|
Loading…
Reference in New Issue
Block a user