예제 #1
0
def writePostscript(filename):
  "Writes the current canvas to a postscript file."    
  #psfile = file(filename, 'w')
  psfile = EPSFile(filename)
  psfile.write(_canvas.postscript(pageanchor='sw',
                   y='0.c', 
                   x='0.c'))
  psfile.close()
예제 #2
0
#! /usr/bin/env python

from random import uniform
from psfile import EPSFile

fd = EPSFile("ex1.eps", 600, 100)

# dark gray background
fd.append("0.1 setgray")
fd.append("0 0 %d %d rectfill" % (fd.width, fd.height))

# a grid of dark orange lines
fd.append("1 .596 .118 setrgbcolor")
fd.append("1 setlinewidth")
for i in range(1, 5):
    y = 100 * i / 5.0
    fd.append("5 %.1f moveto 595 %.1f lineto" % (y, y))
for i in range(1, 30):
    x = 100 * i / 5.0
    fd.append("%.1f 5 moveto %.1f 95 lineto" % (x, x))
fd.append("stroke")

# randomly colored, filled squares
for i in range(0, 30):
    x = i * 20 + 3
    for j in range(0, 5):
        y = j * 20 + 3
        col = uniform(0, 1)
        if 31 * uniform(0, 1) > i + 1:
            fd.append("0 %.3f 0 setrgbcolor" % col)
        else:
예제 #3
0
#! /usr/bin/env python

from __future__ import division

from random import uniform
from psfile import EPSFile

cols = 7
rows = 4
gap = 3

fd = EPSFile("ex4.eps", 350, 80)
fd.append("/Times-Roman findfont 8 scalefont setfont")
dx = (fd.width + gap) / cols
dy = (fd.height + gap) / rows
w = dx - gap
h = dy - gap
for j in range(0, rows):
    for i in range(0, cols):
        r = g = b = 0
        while r + g + b < 1:
            r, g, b = [uniform(0, 1), uniform(0, 1), uniform(0, 1)]
        fd.append("%.1f %.1f %.1f setrgbcolor" % (r, g, b))
        fd.append("%f %f %f %f rectfill" % (i * dx, j * dy, w, h))
        fd.append("0 setgray")
        fd.append("%f %f moveto" % (i * dx + 4, j * dy + 3))
        fd.append("(%.1f, %.1f, %.1f) show" % (r, g, b))
fd.close()
예제 #4
0
파일: ex5.py 프로젝트: clearclaw/psfile
#! /usr/bin/env python

from psfile import EPSFile

fd = EPSFile("ex5.eps", 350, 50)
# draw the yellow background
fd.append("1 1 0 setrgbcolor")
fd.append("0 0 %d %d rectfill"%(fd.width, fd.height))
# draw black circles filled with red
fd.append("0 setgray")
for x in range(25, 375, 50):
    fd.append("""%f 25 20 0 360 arc
                 gsave
                 1 0 0 setrgbcolor
                 fill
                 grestore
                 stroke"""%x)
fd.close()
예제 #5
0
from random import vonmisesvariate
from psfile import EPSFile

# a sample from a von Mises distribution
sample = [ vonmisesvariate(pi/4, 1.0) for i in range(0,200) ]

# generate a histogram of the data
nhist = 4 * int(sqrt(len(sample))/4 + 0.5);
count = [ 0 ] * nhist
for x in sample:
    y = x/(2*pi) % 1
    count[int(y*nhist+.5)%nhist] += 1

# turn into a plot
radius = 72
fd = EPSFile("ex7.eps", 4*radius, 4*radius)
fd.append("/Times-Roman findfont 10 scalefont setfont")
fd.append("%f %f translate"%(2*radius, 2*radius))
fd.append("%f setlinewidth"%((2*pi*radius) / nhist - 1))
for k in count:
    r = radius * (1 + .9*k/max(count))
    fd.append("0 0 moveto %f 0 lineto"%r)
    fd.append("%f -3 moveto (%d) show"%(r+3, k))
    fd.append("%f rotate"%(360/nhist))
fd.append("stroke")
fd.append("""1 setlinewidth
             0 0 %f 0 360 arc
             gsave 1 setgray fill grestore stroke"""%radius)
fd.append("/Symbol findfont 24 scalefont setfont")
fd.append("-35 -10 moveto (k = 1.0) show")
fd.close()
예제 #6
0
파일: ex2.py 프로젝트: timojuez/psfile
#! /usr/bin/env python

from psfile import EPSFile

fd = EPSFile("ex2.eps", 100, 100)
fd.append("""
  % outer square
  0 0 moveto
  100 0 lineto
  100 100 lineto
  0 100 lineto
  closepath

  % inner square, open to the left
  10 10 moveto
  90 10 lineto
  90 90 lineto
  10 90 lineto

  % draw the constructed path
  stroke
""")
fd.close()
예제 #7
0
#! /usr/bin/env python

from psfile import EPSFile

fd = EPSFile("ex5.eps", 350, 50)
# draw the yellow background
fd.append("1 1 0 setrgbcolor")
fd.append("0 0 %d %d rectfill" % (fd.width, fd.height))
# draw black circles filled with red
fd.append("0 setgray")
for x in range(25, 375, 50):
    fd.append("""%f 25 20 0 360 arc
                 gsave
                 1 0 0 setrgbcolor
                 fill
                 grestore
                 stroke""" % x)
fd.close()
예제 #8
0
파일: ex6.py 프로젝트: timojuez/psfile
#! /usr/bin/env python

from psfile import EPSFile

fonts = [
    "Times-Roman", "Times-Italic", "Times-Bold", "Times-BoldItalic",
    "Helvetica", "Helvetica-Oblique", "Helvetica-Bold",
    "Helvetica-BoldOblique", "Courier", "Courier-Oblique",
    "Courier-Bold", "Courier-BoldOblique", "Symbol"
]
str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

fd = EPSFile("ex6.eps", 420, len(fonts)*12)
for i, name in enumerate(reversed(fonts)):
    fd.append("/TimesRoman findfont 10 scalefont setfont")
    fd.append("0 %d moveto"%(12*i+3))
    fd.append("(%s:) show"%name)
    fd.append("/%s findfont 10 scalefont setfont"%name)
    fd.append("100 %d moveto"%(12*i+3))
    fd.append("(%s) show"%str)
fd.close()
예제 #9
0
def stampUV_Execute(fname, path, uvProj):
    if uvProj.Count > 0:
        path = XSIUtils.BuildPath(path, fname + ".eps")
        from psfile import EPSFile
        X = 1000
        Y = 1000
        fd = EPSFile(path, X, Y, margin=0)
        for uv in uvProj:
            if uv.Type == "uvspace":
                geo = uv.Parent3DObject.Activeprimitive.Geometry
                faces = geo.Facets
                aUV = uv.elements.Array
                aClusterIndices = uv.Parent.elements.Array
                for face in faces:
                    fId = face.Index
                    #fd.append("  % face "+str(fId))
                    fd.append(" 1 setlinejoin")
                    samples = face.Samples
                    for i, sample in enumerate(samples):
                        id = sample.Index
                        x = aUV[0][id] * X
                        y = aUV[1][id] * Y
                        if i == 0:
                            fd.append("  " + str(x) + " " + str(y) + " moveto")
                        else:
                            fd.append("  " + str(x) + " " + str(y) + " lineto")
                    fd.append("  closepath")
        fd.append("""
		  % draw the constructed path
		  stroke
		""")
        fd.close()
    return true
예제 #10
0
파일: ex3.py 프로젝트: mrbod/psfile
#! /usr/bin/env python

from __future__ import division

from math import pow
from psfile import EPSFile

min_lw = .5
max_lw = 9
steps = 18

fd = EPSFile("ex3.eps", 350, 38,
             margin_left=10+.5*min_lw, margin_right=10+.5*max_lw)
fd.append("/Times-Roman findfont 10 scalefont setfont")
for i in range(0, steps+1):
    lw = min_lw * pow(max_lw/min_lw, i/steps)
    x = fd.width*i/steps
    fd.append("%.1f setlinewidth"%lw)
    fd.append("%f 0 moveto 0 27 rlineto"%x)
    fd.append("stroke")
    fd.append("%f 30 moveto"%(x-6))
    fd.append("(%.1f) show"%lw)
fd.close()
예제 #11
0
def stampUV_Execute(fname,path,uvProj):
	if uvProj.Count > 0:
		path = XSIUtils.BuildPath( path, fname+".eps" )
		from psfile import EPSFile
		X= 1000
		Y= 1000
		fd = EPSFile(path, X, Y, margin=0)
		for uv in uvProj:
			if uv.Type == "uvspace":
				geo = uv.Parent3DObject.Activeprimitive.Geometry
				faces = geo.Facets
				aUV = uv.elements.Array
				aClusterIndices = uv.Parent.elements.Array
				for face in faces:
					fId = face.Index
					#fd.append("  % face "+str(fId))
					fd.append(" 1 setlinejoin")
					samples =  face.Samples
					for i,sample in enumerate(samples):
						id= sample.Index
						x = aUV[0][id]*X
						y = aUV[1][id]*Y
						if i == 0:
							fd.append("  "+str(x)+" "+str(y)+" moveto")	
						else:
							fd.append("  "+str(x)+" "+str(y)+" lineto")
					fd.append("  closepath")	
		fd.append("""
		  % draw the constructed path
		  stroke
		""")
		fd.close() 
	return true