コード例 #1
0
	def __init__(self, cubicalComplex, fileName='temp.svg', squareSize=20, dotSize=2):
		self.cubicalComplex = cubicalComplex
		self.squareSize = squareSize
		self.dotSize = dotSize
		self.arrowwidth = 2 * dotSize
		self._isClosed = False
		assert(self.cubicalComplex.emb == 2)
		self.canvas = simpleSVG.svg_class(
			fname=fileName,
			bbx=self.squareSize * (1 + self.cubicalComplex.size[1]), 
			bby=self.squareSize *( 1 + self.cubicalComplex.size[0]))
		self.canvas.scale()
コード例 #2
0
ファイル: drawer.py プロジェクト: boopr/Trekke
def build_image_with_chords(modulo, factor, color='rgb(0,0,0)', reverse=False, text=True):
    circle = build_chords(modulo, factor)

    if reverse:
        draw = simpleSVG.svg_class(fname="{}.svg".format(OUTPUT_NAME), bbx=RESOLUTION, bby=RESOLUTION, whiteback=False)
        draw.rect(0, 0, RESOLUTION, RESOLUTION, fill='black')
    else:
        draw = simpleSVG.svg_class(fname="{}.svg".format(OUTPUT_NAME), bbx=RESOLUTION, bby=RESOLUTION)
    draw.scale()

    draw.circle(.5, .5, 300, stroke=color, stroke_width=1)

    if text:
        draw.text(10, RESOLUTION - 10, 0, 'Modulo : %d, Facteur : %.2f' % (modulo, factor), stroke=color)

    for chord in circle:
        draw.line(to_global_coords(chord['start']['x']), to_global_coords(chord['start']['y']),
                  to_global_coords(chord['end']['x']), to_global_coords(chord['end']['y']),
                  stroke=color, stroke_width=1)

    draw.close()
    return draw
コード例 #3
0
ファイル: simpleSVG.py プロジェクト: bfiedler/simpleSVG
def SVGtest():
	import simpleSVG 
	sys.stdout.write("A sample plot will be output as testSVG.svg\n")
	a=simpleSVG.svg_class(fname='testSVG.svg',bbx=600,bby=600) #override defaults for bbx and bby
	a.scale() #uses default scaling of coordinates (x=0. to x=1.0, y=0. to y=1.0) 
	a.group(fill='black')#otherwise fonts are hollow
	a.yaxis()
	a.xaxis(dx=.2,form='%9.2e')
	a.group()
	mypath=a.pathdata('M',[150,400],'l',(50,50),'l',-50,50,'l',-50,-50,'l',50,-50,'Z') #optional use of [] and ()
	mystyle=stylestring(stroke="olive",fill="#49bab6",stroke_width=10) #two ways to specify colors; note '_' replaces '-' in SVG parameters
	a.path(d=mypath,style=mystyle) # render the path
	color1='rgb(100,150,200)' #third way to define color 
	color2=rgbstring(.6,.7,200) #fourth way, real numbers will be multiplied by 255
	a.path('M',200,300,'l',50,50,'l',-50,50,'l',-50,-50,'l',50,-50,'Z',
		fill=color1,stroke=color2,stroke_width=5) # make path from positional arguements, make a style string from keyword arguments
	# if style= is passed, it will prepend  the style string made from keyword arguments:
	a.circle(.5,.3,20,style=mystyle,stroke='none')
	a.line(.5,.5,.4,.5)
	a.group(stroke_width=5) #apply this style to all items in the group
	a.line(.5,.5,.4,.6)
	a.line(300,simpleSVG.hires(300.23),.5,.6,stroke="lime") #demonstates using a hi-res coordinate
#	a.line(300,30023L,.5,.6,stroke="lime") # long integers (*100)  for hi-res coordinate are deprecated
	a.line(300,300,.5,.6,stroke="lime") #same central starting point, specified two ways in SVG coords
	a.path('M',300,300,'l',.1,.1,stroke="red",stroke_dasharray='3,2') #a line is easily made from path too
	a.fatarrow(.5,.5,.7,.5,10,fill='green',stroke='none') #arrow is like line, but with a headsize
	a.arrow(.5,.5,.7,.4,10,stroke_width=3,stroke='maroon',fill='black') #fill is for the head
	a.group()
	a.path('M',.7,.1,'l',.1,.1,.0,.1,-.1,.1,'Z',fill='gray',stroke='none') #path closed with 'Z ' makes polygon
	a.poly(.9,.1,1.,.2,1.,.3,.9,.4,fill='silver',stroke='none') #same poly as above, shifted.  Must use abs. coords.
	a.draw(.9,.1,1.,.2,1.,.3,.9,.4,stroke_width=3) #draw is similar to poly, but not closed
	a.arc(.8,.65,30,20,180,stroke='brown',stroke_width=10) #arc has radius 30, spans angle 20 to 180
	a.arc(.8,.65,60,20,245,stroke='purple',stroke_width=15) #arc had radius 60, spans angle 20 to 245
	a.radial(.8,.65,60,80,132.5,stroke='purple',stroke_width=15) #draw radial from radius of 60 to 80, at angle 132.5
	a.sector(.7,.85,30,100,10,45,fill='red',stroke='black') #sector has radii 30 and 100, spans angle 10 to 45
	a.rect(.7,.8,.35,.25,fill='none',stroke='aqua',stroke_width=3) #specify with width and height
	a.rect2(.72,.82,1.03,1.03,fill='none',stroke='yellow',stroke_width=5) #specify with two opposite vertices
	a.text(.2,.1,0,'hello',font_size="60pt",fill="lime")
	a.text(.5,.3,60,'again',font_size="48pt",text_anchor='middle') #rotate text by 60 degrees, place middle of text at x,y
	a.group(fill='black')
	a.windbarb(.05,.95,0,40,50,stroke_width=1) #x,y,speed,dir,size
	a.windbarb(.10,.90,7,30,50,stroke_width=1)
	a.windbarb(.15,.85,47,20,50,stroke_width=1)
	a.windbarb(.20,.80,107,10,80,stroke_width=1)
	a.group()
	a.group(clip_path=r'url(#marginmask)')
	a.text(.5,.85,60,'clipped',font_size="24pt",text_anchor='left') #demonstrates clipping
	a.group()
	a.text(.35,.80,60,' not clipped',font_size="24pt",text_anchor='left') 
	a.close()
	a.display()
コード例 #4
0
ファイル: drawer.py プロジェクト: freddie0621/Trekke
def build_image_with_chords(modulo,
                            factor,
                            color='rgb(0,0,0)',
                            reverse=False,
                            text=True):
    circle = build_chords(modulo, factor)

    if reverse:
        draw = simpleSVG.svg_class(fname="{}.svg".format(OUTPUT_NAME),
                                   bbx=RESOLUTION,
                                   bby=RESOLUTION,
                                   whiteback=False)
        draw.rect(0, 0, RESOLUTION, RESOLUTION, fill='black')
    else:
        draw = simpleSVG.svg_class(fname="{}.svg".format(OUTPUT_NAME),
                                   bbx=RESOLUTION,
                                   bby=RESOLUTION)
    draw.scale()

    draw.circle(.5, .5, 300, stroke=color, stroke_width=1)

    if text:
        draw.text(10,
                  RESOLUTION - 10,
                  0,
                  'Modulo : %d, Facteur : %.2f' % (modulo, factor),
                  stroke=color)

    for chord in circle:
        draw.line(to_global_coords(chord['start']['x']),
                  to_global_coords(chord['start']['y']),
                  to_global_coords(chord['end']['x']),
                  to_global_coords(chord['end']['y']),
                  stroke=color,
                  stroke_width=1)

    draw.close()
    return draw
コード例 #5
0
ファイル: CubicComplex.py プロジェクト: raulrm75/MC_thinning
def drawCubicComplex(cubicComplex, fileName='temp.svg', squareSize=10):
	R = 2
	n = len(cubicComplex.shape)
	assert(n == 2)
	
	CELLS = cells(cubicComplex, graded=True)
	canvas = simpleSVG.svg_class(fname=fileName, bbx=squareSize + squareSize*cubicComplex.shape[1]/2, bby=squareSize + squareSize*cubicComplex.shape[0]/2)
	canvas.scale()
	
	for d in CELLS:
		if d == 0:
			for cell in CELLS[0]:
				y = R + 2 + cell[0] / 2 * squareSize 
				x = R + 2 + cell[1] / 2 * squareSize
				canvas.circle(x, y, R,fill='red')
		if d == 1:
			for cell in CELLS[1]:
				generator = generators(cell)
				y = [R + 2 + g[0] / 2 * squareSize for g in generator]
				x = [R + 2 + g[1] / 2 * squareSize for g in generator]
				if x[0] == x[1]:
					y.sort()
					y[0] += R
					y[1] -= R
				if y[0] == y[1]:
					x.sort()
					x[0] += R
					x[1] -= R
					
				canvas.line(x[0], y[0], x[1], y[1], fill='green')

		if d == 2:
			for cell in CELLS[2]:
				generator = generators(cell)
				y = [R + 2 + g[0] / 2 * squareSize for g in generator]
				x = [R + 2 + g[1] / 2 * squareSize for g in generator]
				bx = sum(x)/4
				by = sum(y)/4
				px = bx - squareSize/2 + R
				py = by - squareSize/2 + R
				
				canvas.rect(px, py, squareSize - 2*R, squareSize - 2*R, fill='blue')
	
	canvas.close()
コード例 #6
0
def SVGtest():
	import simpleSVG 
	print("A sample plot will be output as testSVG.svg")
	a=simpleSVG.svg_class(fname='testSVG.svg',bbx=600,bby=600) #override defaults for bbx and bby
	a.group(fill='black')#otherwise fonts are hollow
	a.yaxis()
	a.xaxis(dx=.2,form='%9.2e')
	a.group()
	mypath=a.pathdata('M',[150,400],'l',(50,50),'l',-50,50,'l',-50,-50,'l',50,-50,'Z') #optional use of [] and ()
	mystyle=stylestring(stroke="olive",fill="#49bab6",stroke_width=10) #two ways to specify colors; note '_' replaces '-' in SVG parameters
	a.path(d=mypath,style=mystyle) # render the path
	color1='rgb(100,150,200)' #third way to define color 
	color2=rgbstring(.6,.7,200) #fourth way, real numbers will be multiplied by 255
	a.path('M',200,300,'l',50,50,'l',-50,50,'l',-50,-50,'l',50,-50,'Z',
		fill=color1,stroke=color2,stroke_width=5) # make path from positional arguements, make a style string from keyword arguments
	# if style= is passed, it will prepend  the style string made from keyword arguments:
	a.circle(.5,.3,20,style=mystyle,stroke='none')
	a.line(.5,.5,.4,.5)
	a.group(stroke_width=5) #apply this style to all items in the group
	a.line(.5,.5,.4,.6)
	a.line(300,30000,.5,.6,stroke="lime") #same central starting point, specified two ways in SVG coords
	a.path('M',300,300,'l',.1,.1,stroke="red",stroke_dasharray='3,2') #a line is easily made from path too
	a.fatarrow(.5,.5,.7,.5,10,fill='green',stroke='none') #arrow is like line, but with a headsize
	a.arrow(.5,.5,.7,.4,10,stroke_width=3,stroke='maroon',fill='black') #fill is for the head
	a.group()
	a.path('M',.7,.1,'l',.1,.1,.0,.1,-.1,.1,'Z',fill='gray',stroke='none') #path closed with 'Z ' makes polygon
	a.poly(.9,.1,1.,.2,1.,.3,.9,.4,fill='silver',stroke='none') #same poly as above, shifted.  Must use abs. coords.
	a.draw(.9,.1,1.,.2,1.,.3,.9,.4,stroke_width=3) #draw is similar to poly, but not closed
	a.sector(.7,.85,30,100,10,45,fill='red',stroke='black') #sector has radii 30 and 100, spans angle 10 to 45
	a.rect(.7,.8,.35,.25,fill='none',stroke='aqua',stroke_width=3) #specify with width and height
	a.rect2(.72,.82,1.03,1.03,fill='none',stroke='yellow',stroke_width=5) #specify with two opposite vertices
	a.text(.2,.1,0,'hello',font_size="60pt",fill="lime")
	a.text(.5,.3,60,'again',font_size="48pt",text_anchor='middle') #rotate text by 60 degrees, place middle of text at x,y
	a.group(fill='black')
	a.windbarb(.05,.95,0,40,50,stroke_width=1) #x,y,speed,dir,size
	a.windbarb(.10,.90,7,30,50,stroke_width=1)
	a.windbarb(.15,.85,47,20,50,stroke_width=1)
	a.windbarb(.20,.80,107,10,80,stroke_width=1)
	a.group()
	a.close()
コード例 #7
0
def GenerateRose(filename, calm, dirless, wfs, vel_bins):

    colors=[(0.,.5,0.),(0.,.7,.7),(.5,.6,.6),(.8,.6,.4),(1.,0.,0.),(1.,1.,0.),(0.,1.,0.),(0.,1.,1.)]
    clrs=[SVG.rgbstring(*t) for t in colors]

    wf = wfs.sum(axis=1)
    ## fixme - make calm just the first bins.
    sumb = wfs.sum() + calm + dirless

    n = wfs.shape[0] # number of direction bins
    mwf = wf.max() # max number in a direction bin


    rsize = 170 #pt size for maximum "petal" length
    sc = float(rsize)**2/mwf #scale factor, pts per number
    da = 360./n
    dah = .5*da
    a1 = 90+dah #convert meteorology angle to svg angle

    r0 = int(math.sqrt((calm+dirless)*sc/n)) #an integer, so unit is pts


    #now plot using simpleSVG:
    a = SVG.svg_class(fname=filename)

    a.scale(xmin=-1,xmax=1,ymin=-1,ymax=1)
    a.group(stroke_width=".25pt", fill="black", text_anchor='middle')

    lightVariable = calm+dirless * 100. / sumb
    # put the percent light and variable in the middle:
    a.text(256, 256, 0, "%.2f"%lightVariable, font_size='12pt')
    for i in range(1,7): #make the blue frequency circles
        rfreq=i*.02
        r=math.sqrt(rfreq*sumb*sc+r0**2)
        a.circle(0.,0.,int(r),fill='none',stroke='blue')

    # make the "sectors"
    for i in range(0,n):
        a2 = a1
        a1 = a2-da  #notice -da; meteorology is clockwise, svg is anticlockwise
        r2 = r0
        for n in range(len(wfs[i])):
            f=wfs[i][n]
            r1=r2 #last outer radius becomes current inner radius of sector
            r2=int(math.sqrt(r1**2+sc*f))
            a.sector(0.,0.,r1,r2,a1,a2,fill=clrs[n])

    for i in range(1,7): #make the labels for the frequency circles
        rfreq=i*.02
        lab="%5.1f" % (rfreq*100)
        r=math.sqrt(rfreq*sumb*sc+r0**2)
        a.text(0., int(a.jy(0.))+int(r)+11, 0, lab, font_size='12pt')

    

    a.text(.5j,.10j,0.,'blue circles are percent occurance',font_size='12pt',
               stroke='blue',fill='blue')

    a.text(.5j,.05j,0.,title,font_size='18pt')

    a.group(text_anchor="start")
    calmf=float(calm)/sumb
    calmfs="calm percent= %.1f"%(calmf*100) 

    a.text(.1j,.95j,0.,calmfs,font_size='12pt')
    dirlessf=float(dirless)/sumb
    dirlessfs="dirless percent= %.1f"%(dirlessf*100) 

    a.text(.1j,.98j,0.,dirlessfs,font_size='12pt')


    a.group()

    x=.5j
    y=.98j
    dx=.07j
    dy=-.07j
    a.group(text_anchor="middle")

    for n in range(len(vel_bins)):
            a.rect2(x+n*dx,y,x+(n+1)*dx,y+dy,fill=clrs[n])
            a.text(x+(n+1)*dx,y+dy-.01j,0.,str(vel_bins[n]),font_size="12pts")

    a.group()
    a.close()