当前位置: 首页>>代码示例>>Python>>正文


Python SVGdraw.polygon方法代码示例

本文整理汇总了Python中SVGdraw.polygon方法的典型用法代码示例。如果您正苦于以下问题:Python SVGdraw.polygon方法的具体用法?Python SVGdraw.polygon怎么用?Python SVGdraw.polygon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SVGdraw的用法示例。


在下文中一共展示了SVGdraw.polygon方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: toSVG

# 需要导入模块: import SVGdraw [as 别名]
# 或者: from SVGdraw import polygon [as 别名]
	def toSVG(self):
		#modification du maximum en X : depend du nombre d'element
		global XMAX
		XMAX = len(self.infos)*(BAR_THICKNESS+SPACE)
		# creation du document
		doc=SVGdraw.drawing()
		svg=SVGdraw.svg(None, '100%','100%')
		
		# creation des patterns pour les axes et la grille
		axeX = SVGdraw.pattern(id="axeX",width="20",height="10",patternUnits="userSpaceOnUse")
		axeX.addElement(SVGdraw.path("M 0 0, L 0 10","none","black","0.25"))
		axeX.addElement(SVGdraw.path("M 10 10, V 5","none","lightgray","0.25"))
		axeY = SVGdraw.pattern(id="axeY",width="10",height="20",patternUnits="userSpaceOnUse")
		axeY.addElement(SVGdraw.path("M 0 0, L 10 0","none","black","0.25"))
		axeY.addElement(SVGdraw.path("M 5 10, L 10 10","none","lightgray","0.25"))
		grid = SVGdraw.pattern(id="grid",width="10",height="10",patternUnits="userSpaceOnUse")
		grid.addElement(SVGdraw.path("M 0 0, L 10 0, L 10 10,L 0 10, L 0 0","none","lightgray","0.25"))

		defs=SVGdraw.defs()
		defs.addElement(axeX)
		defs.addElement(axeY)
		defs.addElement(grid)
		svg.addElement(defs)
		
		group=SVGdraw.group(transform="translate(130,130) scale(1,-1)")
		
		# dessin de la grille de fond
		group.addElement(SVGdraw.rect(0,0,XMAX,YMAX,"url(#grid)","lightgray","0.25"))
	
		# dessin des axes
		group.addElement(SVGdraw.rect(0,-10,XMAX,10,"url(#axeX)"))
		group.addElement(SVGdraw.rect(-10,0,10,YMAX,"url(#axeY)"))
		group.addElement(SVGdraw.line(0,0,XMAX,0,"black",1))
		group.addElement(SVGdraw.line(0,0,0,YMAX,"black",1))
		# dessin des fleches des axes
		group.addElement(SVGdraw.polygon([[-3,YMAX],[3,YMAX],[0,YMAX+10]], "black","white"))
		group.addElement(SVGdraw.polygon([[XMAX,-3],[XMAX,3],[XMAX+10,0]], "black","white"))
		
		textgroup=SVGdraw.group(transform="scale(1,-1)")
		# graduations
		for y in range(0,YMAX+STEP,STEP):
			textgroup.addElement(SVGdraw.text(-STEP,y, str(y), 8, text_anchor="middle", transform="translate(0,%d)"%(-y*2)))
		textgroup.addElement(SVGdraw.text(0,YMAX+SPACE, r"%", 8, transform="translate(0,%d)"%(-(YMAX+SPACE)*2)))
		
		# ajout de la legende principale
		legendText = "Repertoire %s - taille %.02f ko"%(self.rootName,float(self.totalSize/1024.0))
		textgroup.addElement(SVGdraw.text(XMAX,YMAX+3*SPACE, legendText,12, "verdana", 
			text_anchor="end", fill="darkblue",transform="translate(0,%d)"%(-(YMAX+3*SPACE)*2)))
		
		group.addElement(textgroup)
		
		# tri des elements selon la taille occupee
		self.infos.sort(self.tupleCmp)
		
		xincr=0
		#self.infos
		for (name,size) in self.infos:
			# calcul du pourcentage de place occupe
			pourcent = (100.0*float(size))/float(self.totalSize)
			height=int(pourcent*YMAX/100);
			# insertion du texte de l'emplacement sur le disque et de la taille occupee en Ko
			legendText = "%s (%### ###.02f ko)"%(name,float(size/1024.0))
			legend = SVGdraw.text(xincr+BAR_THICKNESS/2, -10,legendText,8,"verdana",text_anchor="begin",fill="blue")
			legend.attributes["transform"]="scale(1,-1) translate(0,20) rotate(45,%d,-10)"%(xincr+BAR_THICKNESS/2)
			group.addElement(legend)
			
			#insertion de la barre representant le pourcentage
			group.addElement(SVGdraw.rect(xincr,0,BAR_THICKNESS, height,"green","black",opacity=0.5))
			
			#insertion de la taille en pourcentage a gauche de la barre
			pourcentText=SVGdraw.text(xincr+BAR_THICKNESS/2, height+SPACE,"%02.01f%% "%pourcent,6,
				"arial", text_anchor="middle", fill="black")
			pourcentText.attributes["transform"]="scale(1,-1) translate(0,-%d)"%((height+SPACE)*2)
			group.addElement(pourcentText)
			# augmentation du l'abscisse en X
			xincr = xincr+BAR_THICKNESS+SPACE
			
		svg.addElement(group)
		doc.setSVG(svg)
		doc.toXml(self.svgURL)
开发者ID:BackupTheBerlios,项目名称:openphysic-svn,代码行数:82,代码来源:stats.py

示例2: svgout

# 需要导入模块: import SVGdraw [as 别名]
# 或者: from SVGdraw import polygon [as 别名]

#.........这里部分代码省略.........
                    else:
                        pathstring+=" M %f %f L %f %f"% \
                            (tuple(transform(path[j].x,path[j].y)+
                                   transform(path[j+1].x,path[j+1].y)))
                pathelt=SVGdraw.path(pathstring,stroke_width=stroke_width,
                                     stroke=col,fill="none")
                if self.slopebetween(here,nxt)>0:
                    plus.addElement(pathelt)
                else:
                    minus.addElement(pathelt)
        for i in self.pivots:
            cr=transform(i.x, i.y)
            c=SVGdraw.circle(cx=cr[0], cy=cr[1], r=circle_radius,
                             fill='black')
            circgroup.addElement(c)
        if not circradius:
            # Mark the wraparound point.
            circgroup.addElement(SVGdraw.path("M 0 -1 l 0 %d M %d -1 l 0 %d"% \
                                                  (self.ymax+2,self.xmodulus,
                                                   self.ymax+2),
                                              stroke='black',
                                              stroke_width=0.03))
        # Somehow I want to *note* when a knot is single-strand or
        # multistrand.
        circgroup.addElement(SVGdraw.text(x=0.2,y=0,
                                          text=str(len(strands)),
                                          fill='#000408',
                                          font_size=1,
                                          font_family='sans-serif',
                                          transform='scale(1,-1)'))

        if crossings:
            # Try multistrand crossings?  (not working right)
            # Need *ALL* the crossing points though.
            oncircuit=[]
            for circuit in strands:
                oncircuit.extend(self.oncircuit(circuit))
            masked=set()
            over=0
            masks=[minusmask,plusmask]
            # How about this?  For each horizontal line _that has intersections on it_,
            # all crossings go in one direction, and that direction alternates.
            #
            # How do we find those lines?
            points=[]
            for circuit in strands:
                for i in range(0,len(circuit)):
                    here=circuit[i]
                    nxt=circuit[(i+1)%len(circuit)]
                    points+=self.pointsbetween(here,nxt)
            heights=[]
            howmanyhits=dict()
            for p in points:
                howmanyhits[p]=howmanyhits.get(p,0)+1
            howmanyhits=[(p,howmanyhits[p]) for p in howmanyhits.keys()]
            howmanyhits=filter((lambda x: x[1]>1), howmanyhits)
            heights=[x[0].y for x in howmanyhits]
            heights.sort()
            # No "sort unique" so just keep track of the last one we saw and skip it.
            # DOESN'T WORK EITHER BUT BETTER THAN BEFORE XXXXXX
            # (testing with python ./knots.py -l 18 17 6 32 6 37)  Works with more
            # symmetrical designs.
            last=None
            for h in heights:
                if h==last:
                    continue
                last=h
                mask=masks[over]
                over=1-over
                for x in range(0,self.xmodulus,2):
                    p=Point((x if not h%2 else x+1),h,self)
                    if p in self.pivots:
                        continue # Skip pivot-points.
                    tp1=transform(p.x-0.5, p.y-0.5)
                    tp2=transform(p.x-0.5, p.y+0.5)
                    tp3=transform(p.x+0.5, p.y+0.5)
                    tp4=transform(p.x+0.5, p.y-0.5)
                    tp=transform(p.x, p.y)
                    if circradius:
                        r=SVGdraw.circle(fill="black",
                                         cx=tp[0], cy=tp[1], r=0.6)
                    else:
                        angle=45 
                        r=SVGdraw.polygon(fill="black",
                                          points=[tp1,tp2,tp3,tp4],
                                          transform="rotate(%f,%f,%f)"% \
                                              (angle, tp[0], tp[1]))
                    mask.addElement(r)
                    # maingroup.addElement(r)
                    # If it's on the edge, duplicate it on the other side
                    # for ease of viewing.
                    if p.x==0 and not circradius:
                        mask.addElement(SVGdraw.rect(x=self.xmodulus-0.5,
                                                     y=p.y-0.5,
                                                     width=1, height=1,
                                                     fill="#111",
                                                     transform=
                                                     "rotate(45,%d,%d)"%
                                                     (self.xmodulus,p.y)))
        return svg
开发者ID:clsn,项目名称:THexplorer,代码行数:104,代码来源:knots.py


注:本文中的SVGdraw.polygon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。