Skip to content

Instantly share code, notes, and snippets.

@quangIO
Last active September 20, 2021 11:35
Show Gist options
  • Save quangIO/25e1ecb4b5d171d293a1e31a6020f0d1 to your computer and use it in GitHub Desktop.
Save quangIO/25e1ecb4b5d171d293a1e31a6020f0d1 to your computer and use it in GitHub Desktop.
#lang racket
;; brew install --cask racket
;; brew install graphviz
;; raco pkg install --auto git://github.com/quangio/racket-graphviz pict
;; racket diagram.rkt (this file)
(require graphviz)
(require pict/shadow)
(require pict)
(define (shadowed-box w h color)
(inset (shadow (filled-rounded-rectangle w h 5
#:color color
#:border-color "black")
15 -3 3) 10))
(define (shadowed-box2 w h color)
(filled-rounded-rectangle w h 5
#:color color
#:border-color "black"))
(define transaction-pict (shadowed-box 60 180 "Gainsboro"))
(define utxo-pict (shadowed-box 160 40 "LightSkyBlue"))
(define redeemer-pict (shadowed-box 150 40 "Aquamarine"))
(define error-pict (shadowed-box 150 40 "Salmon"))
(define d
(make-digraph
`(("Tx" #:label "Transaction" #:shape ,transaction-pict)
("utxo1" #:label "UTXO 1" #:shape ,utxo-pict)
("r1" #:label "Redeemer 1" #:shape ,redeemer-pict)
("r2" #:label "Redeemer 2" #:shape ,redeemer-pict)
("r3" #:label "Redeemer 3" #:shape ,redeemer-pict)
("r4" #:label "Redeemer 4" #:shape ,redeemer-pict)
("r5" #:label "Redeemer 5" #:shape ,redeemer-pict)
("utxo2" #:label "UTXO 2" #:shape ,utxo-pict)
("utxo3" #:label "UTXO 3" #:shape ,utxo-pict)
("utxo4" #:label "UTXO 4" #:shape ,utxo-pict)
("utxo5" #:label "UTXO 5" #:shape ,utxo-pict)
("utxo6" #:label "UTXO 1'" #:shape ,utxo-pict)
("utxo7" #:label "UTXO 3'" #:shape ,utxo-pict)
(edge ("utxo1" "r1") #:arrowhead "none" #:label "" #:weight "7")
(edge ("utxo2" "r2") #:arrowhead "none" #:label "" #:weight "7")
(edge ("utxo3" "r3") #:arrowhead "none" #:label "" #:weight "7")
(edge ("utxo4" "r4") #:arrowhead "none" #:label "" #:weight "7")
(edge ("utxo5" "r5") #:arrowhead "none" #:label "" #:weight "7")
(edge ("r1" "Tx") #:label "" #:fontsize "20" #:weight "7")
(edge ("r2" "Tx") #:label "" #:weight "7")
(edge ("r3" "Tx") #:label "" #:weight "7")
(edge ("r4" "Tx") #:label "" #:weight "7")
(edge ("r5" "Tx") #:label "" #:weight "7")
(edge ("Tx" "utxo6") #:label "" #:weight "7")
(edge ("Tx" "utxo7") #:label "" #:weight "7")
(same-rank "utxo1" "utxo2")) #:splines "true" #:rankdir "LR" #:nodesep "0.25"))
(define (save-pict the-pict name kind)
(define bm (pict->bitmap the-pict))
(send bm save-file name kind))
(save-pict
(scale (inset (digraph->pict d) 10) 4.0) "tmp.png" 'png)
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment