aboutsummaryrefslogtreecommitdiffstats
path: root/examples/drawing2d
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-02-21 18:08:55 -0800
committerbnewbold <bnewbold@robocracy.org>2016-02-21 18:08:55 -0800
commitb24f282bca4af63982937c10835063d3e6e9eb74 (patch)
treefd8c58601beb3964ccecf4709f7b28944fc1c36b /examples/drawing2d
parent84572be10cdfc852530787a5dc78ddef3e0f23cd (diff)
downloadPyX.jl-b24f282bca4af63982937c10835063d3e6e9eb74.tar.gz
PyX.jl-b24f282bca4af63982937c10835063d3e6e9eb74.zip
add many, many more example conversions. still not complete
Diffstat (limited to 'examples/drawing2d')
-rw-r--r--examples/drawing2d/clipping.jl33
-rw-r--r--examples/drawing2d/ellipse.jl36
-rw-r--r--examples/drawing2d/insert.jl32
-rw-r--r--examples/drawing2d/parallel.jl23
-rw-r--r--examples/drawing2d/smoothed.jl23
5 files changed, 147 insertions, 0 deletions
diff --git a/examples/drawing2d/clipping.jl b/examples/drawing2d/clipping.jl
new file mode 100644
index 0000000..e21f4bb
--- /dev/null
+++ b/examples/drawing2d/clipping.jl
@@ -0,0 +1,33 @@
+# Original Python:
+# from pyx import *
+
+# clippath = path.circle(0, 0, 1)
+# drawpath = path.line(-2, -2, 1.2, 2)
+
+# cl = canvas.canvas([canvas.clip(clippath)])
+# cl.stroke(drawpath, [color.rgb.red, style.linewidth(1.0)])
+
+# c = canvas.canvas()
+# c.stroke(drawpath, [style.linewidth(1.0)])
+# c.insert(cl)
+# c.stroke(clippath)
+
+# c.writeEPSfile("clipping")
+# c.writePDFfile("clipping")
+# c.writeSVGfile("clipping")
+
+using PyX
+
+clippath = path.circle(0, 0, 1)
+drawpath = path.line(-2, -2, 1.2, 2)
+
+cl = canvas.canvas([canvas.clip(clippath)])
+stroke(cl, drawpath, [color_rgb.red, style.linewidth(1.0)])
+
+c = canvas.canvas()
+stroke(c, drawpath, [style.linewidth(1.0)])
+pyx_insert(c, cl)
+stroke(c, clippath)
+
+writeEPSfile(c, "clipping")
+writePDFfile(c, "clipping")
diff --git a/examples/drawing2d/ellipse.jl b/examples/drawing2d/ellipse.jl
new file mode 100644
index 0000000..931ba89
--- /dev/null
+++ b/examples/drawing2d/ellipse.jl
@@ -0,0 +1,36 @@
+# Original Python:
+# from pyx import *
+
+# c = canvas.canvas()
+# circ = path.circle(0, 0, 1)
+
+# # variant 1: use trafo as a deformer
+# c.stroke(circ, [style.linewidth.THIck,
+# trafo.scale(sx=2, sy=0.9), trafo.rotate(45), trafo.translate(1, 0)])
+
+# # variant 2: transform a subcanvas
+# sc = canvas.canvas()
+# sc.stroke(circ, [style.linewidth.THIck])
+# c.insert(sc, [trafo.scale(sx=2, sy=0.9), trafo.rotate(45), trafo.translate(5, 0)])
+
+# c.writeEPSfile("ellipse")
+# c.writePDFfile("ellipse")
+# c.writeSVGfile("ellipse")
+
+
+using PyX
+
+c = canvas.canvas()
+circ = path.circle(0, 0, 1)
+
+# variant 1: use trafo as a deformer
+stroke(c, circ, [style_linewidth.THIck,
+ trafo.scale(sx=2, sy=0.9), trafo.rotate(45), trafo.translate(1, 0)])
+
+# variant 2: transform a subcanvas
+sc = canvas.canvas()
+stroke(sc, circ, [style_linewidth.THIck])
+pyx_insert(c, sc, [trafo.scale(sx=2, sy=0.9), trafo.rotate(45), trafo.translate(5, 0)])
+
+writeEPSfile(c, "ellipse")
+writePDFfile(c, "ellipse")
diff --git a/examples/drawing2d/insert.jl b/examples/drawing2d/insert.jl
new file mode 100644
index 0000000..41bb0b9
--- /dev/null
+++ b/examples/drawing2d/insert.jl
@@ -0,0 +1,32 @@
+# Original Python:
+# from math import sin, cos, radians
+# from pyx import *
+
+# angle = 10
+# factor = 1.0 / (cos(radians(angle)) + sin(radians(angle)))
+
+# cc = canvas.canvas()
+# cc.stroke(path.rect(-2, -2, 4, 4))
+
+# c = canvas.canvas()
+# for i in range(10):
+# c.insert(cc, [trafo.rotate(i*angle), trafo.scale(factor**i)])
+# c.writeEPSfile("insert")
+# c.writePDFfile("insert")
+# c.writeSVGfile("insert")
+
+using PyX
+
+angle = 10
+factor = 1.0 / (cos(deg2rad(angle)) + sin(deg2rad(angle)))
+
+cc = canvas.canvas()
+stroke(cc, path.rect(-2, -2, 4, 4))
+
+c = canvas.canvas()
+for i in 0:9
+ pyx_insert(c, cc, [trafo.rotate(i*angle), trafo.scale(factor^i)])
+end
+
+writeEPSfile(c, "insert")
+writePDFfile(c, "insert")
diff --git a/examples/drawing2d/parallel.jl b/examples/drawing2d/parallel.jl
new file mode 100644
index 0000000..73b284a
--- /dev/null
+++ b/examples/drawing2d/parallel.jl
@@ -0,0 +1,23 @@
+# Original Python:
+# from pyx import *
+
+# c = canvas.canvas()
+# p = path.line(0, 0, 2, 2)
+# p.append(path.curveto(2, 0, 3, 0, 4, 0))
+# c.stroke(p)
+# c.stroke(p, [deformer.parallel(0.2), color.rgb.blue])
+# c.stroke(p, [deformer.parallel(-0.2), color.rgb.red])
+# c.writeEPSfile("parallel")
+# c.writePDFfile("parallel")
+# c.writeSVGfile("parallel")
+
+using PyX
+
+c = canvas.canvas()
+p = path.line(0, 0, 2, 2)
+pyx_append(p, path.curveto(2, 0, 3, 0, 4, 0))
+stroke(c, p)
+stroke(c, p, [deformer.parallel(0.2), color_rgb.blue])
+stroke(c, p, [deformer.parallel(-0.2), color_rgb.red])
+writeEPSfile(c, "parallel")
+writePDFfile(c, "parallel")
diff --git a/examples/drawing2d/smoothed.jl b/examples/drawing2d/smoothed.jl
new file mode 100644
index 0000000..8bce718
--- /dev/null
+++ b/examples/drawing2d/smoothed.jl
@@ -0,0 +1,23 @@
+# Original Python:
+# from pyx import *
+
+# c = canvas.canvas()
+# p = path.line(0, 0, 2, 2)
+# p.append(path.curveto(2, 0, 3, 0, 4, 0))
+# c.stroke(p)
+# c.stroke(p, [deformer.smoothed(1.0), color.rgb.blue])
+# c.stroke(p, [deformer.smoothed(2.0), color.rgb.red])
+# c.writeEPSfile("smoothed")
+# c.writePDFfile("smoothed")
+# c.writeSVGfile("smoothed")
+
+using PyX
+
+c = canvas.canvas()
+p = path.line(0, 0, 2, 2)
+pyx_append(p, path.curveto(2, 0, 3, 0, 4, 0))
+stroke(c, p)
+stroke(c, p, [deformer.smoothed(1.0), color_rgb.blue])
+stroke(c, p, [deformer.smoothed(2.0), color_rgb.red])
+writeEPSfile(c, "smoothed")
+writePDFfile(c, "smoothed")