Skip to content

Instantly share code, notes, and snippets.

@kbastani kbastani/graph-art-1
Last active Aug 29, 2015

Embed
What would you like to do?
Run these Cypher scripts sequentially to generate graph art in Neo4j
MATCH (a), (b)
WHERE id(a) = 10484 AND id(b) = 10546
MATCH p=shortestPath((a)-[*]-(b))
RETURN p
// Create a matrix of size*size
// Change the size range below to change matrix dimensions
WITH range(0, 24) as size
FOREACH (y in tail(size) |
FOREACH (x in tail(size) |
MERGE (lastBlock:Pattern { x: x - 1, y: y, pattern: toString(x - 1) + "-" + toString(y) })
MERGE (thisBlock:Pattern { x: x, y: y, pattern: toString(x) + "-" + toString(y) })
MERGE (upBlock:Pattern { x: x, y: y - 1, pattern: toString(x) + "-" + toString(y - 1) })
MERGE (lastUpBlock:Pattern { x: x - 1, y: y - 1, pattern: toString(x - 1) + "-" + toString(y - 1) })
MERGE (dBlock:Pattern { x: x + 1, y: y + 1, pattern: toString(x + 1) + "-" + toString(y + 1) })
MERGE (lastBlock)-[:NEXT]->(thisBlock)
MERGE (lastBlock)-[:NEXT]->(lastUpBlock)
MERGE (thisBlock)-[:NEXT]->(upBlock)
MERGE (lastUpBlock)-[:NEXT]->(upBlock)
MERGE (dBlock)-[:NEXT]->(thisBlock))
)
RETURN *
// Create a branching tree off edges of a matrix
// Branching factor is adjustable
// Run multiple times to increase depth
WITH 3 as BRANCH_FACTOR
MATCH (n) WHERE NOT (n)<--()
WITH collect(n) as ns, BRANCH_FACTOR
FOREACH (x in ns | FOREACH (x2 in range(1, BRANCH_FACTOR) | MERGE (x)<-[:NEXT]-(pattern:Pattern { pattern: toString(x2) + "-" + toString(x.pattern) })))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.