Skip to content

Instantly share code, notes, and snippets.

@jpjacobs
Last active August 29, 2015 14:22
Show Gist options
  • Save jpjacobs/ce6252c4a4a5ec5ecbc5 to your computer and use it in GitHub Desktop.
Save jpjacobs/ce6252c4a4a5ec5ecbc5 to your computer and use it in GitHub Desktop.
plotgraph
NB. Make square grid of side y
grid =: |:@:(,"2)@(,: |:)@(#"0 i.)
plotgraph =: 4 : 0 NB. todo: implement autoplacement of locations not given
pd 'reset'
pd 'type line;pensize 1;color blue'
edges =. ; (i.#x) ;/@,.&({&x)"0 &.> y
edges =. <"1 ~.@:(({~"1 /:@{.)"2) > edges NB. normalize: sort points on ascending x, eliminate double edges.
edges =. (#~ -.@({.&>-:{:&>)"1) edges NB. eliminate loops. Empties automagically disappear.
pd"1 edges
pd 'type dot;pensize 4;color red'
pd ;/|:x
pd'show'
#edges
)
(grid 10) plotgraph <"1 ? 100 3 $ 100 NB. graph with 100 vertices and 3 random neighbors per verrtex
(grid 10) plotgraph <@,"0] 1|.i.100 NB. now works correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment