-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue-9: #9
- Loading branch information
Showing
11 changed files
with
357 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from colour import Color | ||
from chalk import Diagram, triangle | ||
|
||
papaya = Color("#ff9700") | ||
|
||
def sierpinski(n: int, size: int) -> Diagram: | ||
if n <= 1: | ||
return triangle(size) | ||
else: | ||
smaller = sierpinski(n - 1, size / 2) | ||
return smaller.above(smaller.beside(smaller).center_xy()) | ||
|
||
d = sierpinski(5, 4).fill_color(papaya) | ||
d.render() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import os # markdown-exec: hide | ||
if "CI" in os.environ: # markdown-exec: hide | ||
print("D2 is not installed in CI, skipping this gallery example.") # markdown-exec: hide | ||
raise SystemExit(0) # markdown-exec: hide | ||
import subprocess | ||
|
||
diagram = """ | ||
direction: right | ||
Before and after becoming friends: { | ||
2007: Office chatter in 2007 { | ||
shape: sequence_diagram | ||
alice: Alice | ||
bob: Bobby | ||
awkward small talk: { | ||
alice -> bob: uhm, hi | ||
bob -> alice: oh, hello | ||
icebreaker attempt: { | ||
alice -> bob: what did you have for lunch? | ||
} | ||
unfortunate outcome: { | ||
bob -> alice: that's personal | ||
} | ||
} | ||
} | ||
2012: Office chatter in 2012 { | ||
shape: sequence_diagram | ||
alice: Alice | ||
bob: Bobby | ||
alice -> bob: Want to play with ChatGPT? | ||
bob -> alice: Yes! | ||
bob -> alice.play: Write a play... | ||
alice.play -> bob.play: about 2 friends... | ||
bob.play -> alice.play: who find love... | ||
alice.play -> bob.play: in a sequence diagram | ||
} | ||
2007 -> 2012: Five\nyears\nlater | ||
} | ||
""" | ||
|
||
# We simply run `d2` in a subprocess, passing it our diagram as input and capturing its output to print it. | ||
svg = subprocess.check_output(["d2", "-", "-"], input=diagram, stderr=subprocess.DEVNULL, text=True) | ||
print(svg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.