#!/usr/bin/env python #vplotex.py produces two files, temp.eps and temp_b.eps #v0.93 November 11, 2007 ############# import vplot #vplot.py must be in your PYTHONPATH ############# from math import * #need to use sin and cos below ########################################################## #this example makes a Japanese flag #the next line creates or "instantiates" an object vplot.eps_class a=vplot.eps_class() #output will be in temp.eps #next we invoke the methods of our object "a". The methods write out postscript commands. a.color('red') #changes colors to red a.circle(.5,.5,100,'F') #filled circle at user coordinate (.5,.5) with radius=100 pts a.color() #change color back to black (default) a.rect(0.,.15,1.,.85) #draws a rectangle a.close() #close the output file ########################################################## #the second example creates another object "b", and shows off the methods... b=vplot.eps_class(fname='temp_b.eps',bbx=600,bby=600) #override defaults b.scale(0.,2.,0.,2.) #set the range of user coordinates that spans between margins b.xaxis() #make an x axis b.yaxis(dy=.4) #make a y axis, change default ticks to 0.4 #try some rectangles: b.color('blue') b.rect(.65, 1.65, .75, 1.95,'F') # pass optional "fill" argument, 'F' b.color() #revert to default, black b.linewidth(5) #5 pts b.rect(.6, 1.6, .8, 2.0) #not filled, open b.linewidth() #revert do default, 1 #make some pretty circles: deg=pi/180. rad=.3 x=.4 y=.6 b.circle(x,y,.4) # note radius .4 is passed in user coordinates for theta in range(0,360,30): b.color(.5+.5*cos(theta*deg), 0., .5+.5*sin(theta*deg)) #vary red and blue b.circle(x+rad*cos(theta*deg),y+rad*sin(theta*deg),20,'F') #note 20 is integer, so pts #try some more drawing of (x,y) stored sequentially in lists [] b.color('blue') #pass string, therefore uses preset color b.poly([(1.2,1.2),(1.8,1.2),(1.6,1.6)],'F') #use option of passing as list of (x,y) tuples yellow=(1, 1, 0) #define our own color, in tuple or list b.color(yellow) #pass our tuple b.draw([1.5,1.0,1.7,1.6,1.9,1.0]) #note x,y does not need to be in tuples b.color(0.,1.,0.) #pass r,g,b for green as floats b.linewidth(2) b.dashdraw([[1.5,0.9],(1.7,1.5),1.9,0.9]) #dash version,note mixed way of passsing coords! b.linewidth() #try some arrows: b.color('red') b.arrow(1.9, .1, .1, 1.9, 10) #head size 10 passed as integer, so pts b.color(255, 0, 255) #pass rgb for magenta as integers b.arrow(400, 100, 300, 400, 0.05) #place arrow in postscipt coordinates, size in user coords b.color('green') b.fatarrow(1.7, .1, .1, 1.7 , 0.05) #width passed as real number, user coords b.color() # revert to default, black #try placing text: b.text(1.0, 1.6, 0., 16, 'this') #1.0 and 1.6 are the user x and y b.text(.8j, .8j, 90., .04j , 'that') #.8j and .04j are fractions of the Bounding Box #make some sectors: b.color('red') b.sector(1.2,1.7,30,100,10,45,'F')#center=1.2,1.7 radii=30pts,100pts angles=10deg,45deg b.color() b.sector(1.2,1.7,30,100,10,45) #put a black boundary around the sector #done b.close() #close the output file ################################