Skip to content

Commit 29ea8be

Browse files
committed
figure for pi by random numbers
1 parent 388341d commit 29ea8be

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

images/random_pi.pdf

16 KB
Binary file not shown.

images/src/random_pi.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from pyx import canvas, color, path, text, unit
2+
3+
text.set(text.LatexRunner)
4+
text.preamble(r'\usepackage{arev}\usepackage[T1]{fontenc}\usepackage{nicefrac}')
5+
unit.set(xscale=1.2, wscale=1.2)
6+
7+
c = canvas.canvas()
8+
side = 4
9+
lightcolor = color.hsb(0.65, 0.2, 1)
10+
darkcolor = color.hsb(0.65, 1, 1)
11+
c.fill(path.path(path.moveto(0, 0),
12+
path.lineto(side, 0),
13+
path.arc(0, 0, side, 0, 90),
14+
path.closepath()), [lightcolor])
15+
c.stroke(path.path(path.arc(0, 0, side, 0, 90)), [darkcolor])
16+
c.stroke(path.rect(0, 0, side, side))
17+
ticklen = 0.15
18+
for tick in (0, 1):
19+
dist = tick*side
20+
c.stroke(path.line(dist, 0, dist, -ticklen))
21+
c.text(dist, -1.5*ticklen, str(tick), [text.halign.center, text.valign.top])
22+
c.stroke(path.line(0, dist, -ticklen, dist))
23+
c.text(-1.5*ticklen, dist, str(tick), [text.halign.right, text.valign.middle])
24+
c.text(0.4*side, 0.4*side, r'\huge$\frac{\pi}{4}$',
25+
[text.halign.center, text.valign.middle, darkcolor])
26+
c.writePDFfile()

0 commit comments

Comments
 (0)