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


Python Polygon.scale方法代码示例

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


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

示例1: ellipse

# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import scale [as 别名]
def ellipse(pos=(0,0), width=1.0, height=None, np=32, rotate=0.0, thickness=None,
            scale=1.0, xscale=1.0, yscale=1.0):
        if height == None: height = 0.5*width
        if thickness == 0 or thickness == None:
            cp = []
            seg = 2.0*pi/np
            angle = 0
            radius=0.5
            lf = width/2.0
            hf = height/2.0
            for i in range(np):
                x = cos(angle)*lf + pos[0]
                y = sin(angle)*hf + pos[1]
                cp.append((x,y))
                angle += seg
            cp.append(cp[0])
            if rotate != 0.0: cp = rotatecp(cp, pos, rotate)
            if scale != 1.0: xscale = yscale = scale
            pp = Polygon(cp)
            if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
            return pp
        else:
            pp = ering(pos=pos, width=width, height=height, np=np, rotate=rotate,
                  thickness=thickness)
            return pp
开发者ID:Emma920,项目名称:visual,代码行数:27,代码来源:shapes.py

示例2: pointlist

# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import scale [as 别名]
def pointlist(pos=[], rotate=0.0, roundness=0.0, invert=False,
              scale=1.0, xscale=1.0, yscale=1.0, path=False):
    # pos may be either a list of points or a Polygon object
    try:
        points = pos.contour(0)
        if len(pos) > 1:
            raise AttributeError("pointlist can deal with only a single contour.")
    except:
        points = pos[:]
    closed = (points[-1] == points[0])
    if not closed:
        points.append(points[0])
    pp = Polygon(points)
    if len(pp) and rotate != 0.0: pp.rotate(rotate)
    if scale != 1.0: xscale = yscale = scale
    if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
    if roundness > 0:
        cp = roundc(pp.contour(0), roundness=roundness, invert=invert)
        pp = Polygon(cp)
    if path:
        if closed:
            return list(pp)
        else:
            return list(pp)[:-1]
    else:
        return pp
开发者ID:Emma920,项目名称:visual,代码行数:28,代码来源:shapes.py

示例3: ngon

# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import scale [as 别名]
def ngon(pos=(0,0), np=3, length=None, radius=1.0, rotate=0.0, thickness=0,
         roundness=0.0, invert=False, scale=1.0, xscale=1.0, yscale=1.0):
        cp = [] 
        if np < 3:
                raise AttributeError("number of sides can not be less than 3")
                return None

        angle = 2*pi/np
        if length != None: radius = (length/2.0)/(sin(angle/2))    
        else: length = radius*(sin(angle/2))*2
        if thickness == 0:
            seg = 2.0*pi/np
            angle = rotate
            for i in range(np):
                x = radius*cos(angle) + pos[0]
                y = radius*sin(angle) + pos[1]
                cp.append((x,y))
                angle += seg
            cp.append(cp[0])
            if scale != 1.0: xscale = yscale = scale
            pp = Polygon(cp)
            if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
            if roundness > 0:
                    cp = roundc(pp.contour(0), roundness=roundness, invert=invert)
                    return Polygon(cp)
            else: return pp
        else:
            pp = nframe(pos=pos, length=length, thickness=thickness, roundness=roundness,
                        invert=invert, rotate=rotate, np=np)
            return pp
开发者ID:Emma920,项目名称:visual,代码行数:32,代码来源:shapes.py

示例4: line

# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import scale [as 别名]
def line(pos=(0,0), np=2, rotate=0.0, scale=1.0, xscale=1.0, yscale=1.0,
           thickness=None, start=(0,0), end=(0,1), path=False):
        v = vis.vector((end[0]-start[0]), (end[1]-start[1]))
        if thickness is None:
            thickness = 0.01*vis.mag(v)
        dv = thickness*vis.norm(vis.vector(0,0,1).cross(v))
        dx = dv.x
        dy = dv.y
        cp = [] # outer line
        cpi = [] # inner line
        vline = (vis.vector(end)-vis.vector(start)).norm()
        mline = vis.mag(vis.vector(end)-vis.vector(start))
        for i in range(np):
            x = start[0] + (vline*i)[0]/float(np-1)*mline
            y = start[1] + (vline*i)[1]/float(np-1)*mline
            cp.append( (x+pos[0],y+pos[1]) )
            cpi.append( (x+pos[0]+dx,y+pos[1]+dy) )
        if not path:
                cpi.reverse()
                for p in cpi:
                    cp.append(p)
                cp.append(cp[0])
        if rotate != 0.0: cp = rotatecp(cp, pos, rotate)
        if scale != 1.0: xscale = yscale = scale
        pp = Polygon(cp)
        if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
        if not path:
                return pp
        else:
                return [cp]
开发者ID:Emma920,项目名称:visual,代码行数:32,代码来源:shapes.py

示例5: arc

# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import scale [as 别名]
def arc(pos=(0,0), radius=0.5, np=32, rotate=0.0, scale=1.0, xscale=1.0, yscale=1.0,
           thickness=None, angle1=0.0, angle2=pi, path=False):
        if thickness is None:
            thickness = 0.01*radius
        cp = []  # outer arc
        cpi = [] # inner arc
        seg = 2.0*pi/np
        nseg = int(abs((angle2-angle1))/seg)+1
        seg = (angle2-angle1)/nseg
        for i in range(nseg+1):
            x = cos(angle1+i*seg)
            y = sin(angle1+i*seg)
            cp.append( (radius*x+pos[0],radius*y+pos[1]) )
            cpi.append( ((radius-thickness)*x+pos[0],(radius-thickness)*y+pos[1]) )
        if not path:
                cpi.reverse()
                for p in cpi:
                    cp.append(p)
                cp.append(cp[0])
        if rotate != 0.0: cp = rotatecp(cp, pos, rotate)
        if scale != 1.0: xscale = yscale = scale
        pp = Polygon(cp)
        if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
        if not path:
                return pp
        else:
                return [cp]
开发者ID:Emma920,项目名称:visual,代码行数:29,代码来源:shapes.py

示例6: rectangle

# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import scale [as 别名]
def rectangle(pos=(0,0), width=1.0, height=None, rotate=0.0, thickness=0, 
              roundness=0.0, invert=False, scale=1.0, xscale=1.0, yscale=1.0):
        if height is None: height = width
        
        if thickness == 0:
            p0 = (pos[0]+width/2.0, pos[1]-height/2.0)
            p1 = (pos[0]+width/2.0, pos[1]+height/2.0)
            p2 = (pos[0]-width/2.0, pos[1]+height/2.0)
            p3 = (pos[0]-width/2.0, pos[1]-height/2.0)
            p4 = (pos[0]+width/2.0, pos[1]-height/2.0)

            cp = [p0, p1, p2, p3, p4]
            if rotate != 0.0: cp = rotatecp(cp, pos, rotate)
            if scale != 1.0: xscale = yscale = scale
            pp = Polygon(cp)
            if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
            if roundness > 0:
                cp = roundc(pp.contour(0), roundness=roundness, invert=invert)
                return Polygon(cp)
            else: return pp
        else:
            pp = rframe(pos=pos, width=width, height=height, thickness=thickness,
                       rotate=rotate, roundness=roundness, invert=invert,
                       scale=scale, xscale=xscale, yscale=yscale)
            return pp
开发者ID:Emma920,项目名称:visual,代码行数:27,代码来源:shapes.py

示例7: rackGear

# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import scale [as 别名]
def rackGear(pos=(0,0), n=30, radius=5., phi=20., addendum=0.4, dedendum=0.5,
         fradius=0.1, rotate=0, scale=1.0, length=10*pi, res=1, bevel=0.05, depth=(0.4+0.6+0.1)):
        tooth = RackOutline(n, res, phi, radius, addendum, dedendum,
                        fradius, bevel)

        toothl = tooth[0][1] - tooth[-1][1]

        ntooth = int(length/toothl)
        flength = ntooth * toothl

        gear = []
        for i in range(0, ntooth):
            ntooth = []
            for (x, y) in tooth:
                nx = x + pos[0]
                ny = -i*toothl + y + pos[1]
                ntooth.append((nx,ny))
            gear.extend(ntooth)
        gear.append((gear[-1][0]-depth,gear[-1][1]))
        gear.append((gear[0][0]-depth,gear[0][1]))
        gear.append(gear[0])
        pp =  Polygon(gear)
        pp.shift(-pp.center()[0],-pp.center()[1])
        if rotate != 0.0: pp.rotate(rotate)
        if scale != 1.0 : pp.scale(scale,scale)
        return pp
开发者ID:Emma920,项目名称:visual,代码行数:28,代码来源:shapes.py

示例8: gear

# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import scale [as 别名]
def gear(pos=(0,0), n=20, radius=5, phi=20, addendum=0.4, dedendum=0.5,
         fradius=0.1, rotate=0, scale=1.0, internal=False, res=1, bevel=0):
        tooth = ToothOutline(n, res, phi, radius, addendum, dedendum,
                        fradius, bevel=0.0)
        if internal:
                itooth = []
                for p in tooth:
                        px = p[0]
                        py = p[1]
                        driro = sqrt(px*px +py*py) - radius
                        ir = radius - driro
                        ro = radius + driro
                        ix = (ir/ro)*px
                        iy = (ir/ro)*py
                        itooth.append((ix,iy))

                tooth = itooth
        gear = []
        for i in range(0, n):
            rotan = -i*2*pi/n
            rtooth = []
            for (x, y) in tooth:
                rx = x*cos(rotan) - y*sin(rotan) + pos[0]
                ry = x*sin(rotan) + y*cos(rotan) + pos[1]
                rtooth.append((rx,ry))
            gear.extend(rtooth)
        #gear.append(gear[0])
        pp =  Polygon(gear)
        if rotate != 0.0: pp.rotate(rotate)
        if scale != 1.0 : pp.scale(scale,scale)
        return pp
开发者ID:Emma920,项目名称:visual,代码行数:33,代码来源:shapes.py

示例9: circle

# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import scale [as 别名]
def circle(pos=(0,0), radius=0.5, np=32, scale=1.0, xscale=1.0, yscale=1.0,
           thickness=0):
        if thickness == 0:
            cp = []
            seg = 2.0*pi/np
            for i in range(np):
                angle = i*seg
                x = radius*cos(angle) + pos[0]
                y = radius*sin(angle) + pos[1]
                cp.append((x,y))
            cp.append(cp[0])
            if scale != 1.0: xscale = yscale = scale
            pp = Polygon(cp)
            if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
            return pp
        else:
            if thickness == Default: thickness = radius*0.2
            pp = ring(pos=pos, radius=radius, np=np, scale=scale,
                      iradius=(radius-thickness), xscale=xscale, yscale=yscale)
            return pp
开发者ID:Emma920,项目名称:visual,代码行数:22,代码来源:shapes.py

示例10: star

# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import scale [as 别名]
def star(pos=(0,0), radius=1.0, n=5, iradius=None, rotate=0.0, thickness=0.0,
         roundness=0.0, invert=False, scale=1.0, xscale=1.0, yscale=1.0):
    if iradius == None: iradius = radius*0.5
    if thickness == 0.0:
        pstar = Star(radius=radius, center=pos, beams=n, iradius=iradius)
        cp = pstar[0]
        cp.append(cp[0])
        cp.reverse() # Polygon Star goes around clockwise, so reverse to go CCW
        cp = rotatecp(cp, pos, rotate)
        if scale != 1.0: xscale = yscale = scale
        pp = Polygon(cp)
        if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
        if roundness > 0:
            cp = roundc(pp.contour(0), roundness=roundness, invert=invert)
            return Polygon(cp)
        else: return pp
    else:
        pp = sframe(pos=pos, radius=radius, iradius=iradius, rotate=rotate,
                    thickness=thickness, roundness=roundness, invert=invert,
                    scale=scale, xscale=xscale, yscale=yscale, n=n)
        return pp
开发者ID:Emma920,项目名称:visual,代码行数:23,代码来源:shapes.py

示例11: cross

# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import scale [as 别名]
def cross(pos=(0,0), width=1.0, thickness=0.2, rotate=0.0,
              roundness=0.0, invert=False, scale=1.0, xscale=1.0, yscale=1.0):

        fsqr = rectangle(pos=pos, width=width)
        sqr1 = rectangle(pos=(pos[0]-(width+thickness)/4.0,
                                     pos[1]+(width+thickness)/4.0), width=(width-thickness)/2.0)
        sqr2 = rectangle(pos=(pos[0]+(width+thickness)/4.0,
                                     pos[1]+(width+thickness)/4.0), width=(width-thickness)/2.0)
        sqr3 = rectangle(pos=(pos[0]+(width+thickness)/4.0,
                                     pos[1]-(width+thickness)/4.0), width=(width-thickness)/2.0)
        sqr4 = rectangle(pos=(pos[0]-(width+thickness)/4.0,
                                     pos[1]-(width+thickness)/4.0), width=(width-thickness)/2.0)
        poly = fsqr - sqr1 -sqr2 -sqr3 -sqr4
        cp = poly.contour(0)
        cp.append(cp[0])
        if rotate != 0.0: cp = rotatecp(cp, pos, rotate)
        pp = Polygon(cp)
        if xscale != 1.0 or yscale != 1.0: pp.scale(xscale,yscale)
        if roundness > 0:
                cp = roundc(pp.contour(0), roundness=roundness, invert=invert)
                return Polygon(cp)
        else: return pp
开发者ID:Emma920,项目名称:visual,代码行数:24,代码来源:shapes.py

示例12: Ellipse

# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import scale [as 别名]
img.blit( Ellipse(200,50,20,5).fill( Color(0, 255, 0) ) )

# The flag is constructed as such:
# ˆThe pole is a line with start and end points of (100,125) and (100,50).
line1 = Line(100, 125, 100, 50)

# ˆThe flag is a polygon with vertex points of (100,125), (100,95), and
# (60,110)
polygon1 = Polygon([(100,125), (100,95), (60,110)]).fill( Color(128, 0, 128) )

# ˆThe pole and flag are translated by (0,35), in order to fit in the right
# hand of the stick figure.
line1.translate(0,35)
polygon1.translate(0,35)

# ˆThe pole and flag are rotated by 45 degrees for a fix point of (100,100),
# so the flag and pole are tilted in the right hand of the stick figure.
line1.rotate(100,100,45)
polygon1.rotate(100,100,45)

# ˆThe pole and flag are scaled by 1.25 in the x and y values for a fix
# point of (100,100), to be larger in the right hand of the stick figure.
line1.scale(100,100,1.25,1.25)
polygon1.scale(100,100,1.25,1.25)

# Blit Rest
img.blit( line1 )
img.blit( polygon1 )

# Create/Write Image
img.save('test.ppm')
开发者ID:super3,项目名称:ClassDev,代码行数:33,代码来源:man.py

示例13: __init__

# 需要导入模块: from Polygon import Polygon [as 别名]
# 或者: from Polygon.Polygon import scale [as 别名]
class Shape:
    """Graphical polygon primitive for use with `pyglet`_.

    Alternative constructor methods:

    - |Shape.circle|
    - |Shape.rectangle|
    - |Shape.regular_polygon|
    - |Shape.from_dict|

    Parameters
    ----------
    vertices : array-like or |Polygon|.
        If a |Polygon| is passed, its points will be used.
        Otherwise, `vertices` should be a sequence of `[x, y]` locations or an array with x and y columns.
    color : str or 3-tuple of int, optional
        Color, in R, G, B format.
        Alternatively, a key that refers to an element of `colors`.
    velocity : array-like
        Speed and direction of motion, in [dx_dt, dy_dt] format.
    angular_velocity : float
        Speed of angular motion, in counter-clockwise radians per second.
    colors : dict of tuple, optional
        Named colors, defined as R, G, B tuples.
        Useful for easily switching between a set of colors.

    Attributes
    ----------
    poly : |Polygon|
        Associated |Polygon| object.
    vertices : |array|
        An array of points, with x and y columns. Read-only.
    center : |array|
        The centroid of the shape.
        Setting center calls |Shape.translate|.
    position : |array|
        Alias for `center`.
    radius : |array|
        Mean distance from each point to the center.
        Setting radius calls |Shape.scale|.
    color : str or tuple of int
        The current color, in R, G, B format if `colors` was not passed.
        Otherwise, the current color is represented as a key in `colors`.
    colors : dict of tuple
        Named colors.
    velocity : |array|
        Speed and direction of linear motion.
    Angular_velocity : float
        Speed of angular motion, in counter-clockwise radians per second.
    enabled : bool
        If False, the shape will not be drawn.

    """

    def __init__(self, vertices, color=(255, 255, 255), velocity=(0, 0), angular_velocity=0, colors=None):
        if isinstance(vertices, Polygon):
            self.poly = vertices
        else:
            self.poly = Polygon(vertices)

        self.colors = colors
        self._color = "primary"
        if colors:
            self.color = color

        else:
            self.colors = {"primary": color}

        self.velocity = np.asarray(velocity)
        self.angular_velocity = angular_velocity

        # Construct vertex_list.
        self._vertex_list = self._get_vertex_list()
        self.enabled = True

    @classmethod
    def regular_polygon(cls, center, radius, n_vertices, start_angle=0, **kwargs):
        """Construct a regular polygon.

        Parameters
        ----------
        center : array-like
        radius : float
        n_vertices : int
        start_angle : float, optional
            Where to put the first point, relative to `center`,
            in radians counter-clockwise starting from the horizontal axis.
        kwargs
            Other keyword arguments are passed to the |Shape| constructor.

        """
        angles = (np.arange(n_vertices) * 2 * np.pi / n_vertices) + start_angle
        return cls(center + radius * np.array([np.cos(angles), np.sin(angles)]).T, **kwargs)

    @classmethod
    def circle(cls, center, radius, n_vertices=50, **kwargs):
        """Construct a circle.

        Parameters
        ----------
#.........这里部分代码省略.........
开发者ID:hsharrison,项目名称:pyglet2d,代码行数:103,代码来源:pyglet2d.py


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