python类rect()的实例源码

Penrose.py 文件源码 项目:WXMLTilingsHOWTO 作者: maxieds 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_tiles(self): 

          #radiusR = DEFAULT_RADIUS_R; 
          #triangles = [(COLOR_RED, 0, 4 * radiusR, 4 * radiusR * ((0j-1)**-.2))]
          # Create an initial wheel of red triangles around the origin 
          # (from the comments section of the reference): 
          radiusR = DEFAULT_RADIUS_R; 
          triangles = []
          for i in xrange(10):
               B = cmath.rect(1, (2*i - 1) * math.pi / radiusR)
               C = cmath.rect(1, (2*i + 1) * math.pi / radiusR)
               if i % 2 == 0:
                    B, C = C, B # Make sure to mirror every second triangle
               ##
               triangles.append((COLOR_RED, B, 0j, C)) 
          ##         

          for i in range(self.num_steps):
               triangles = self.subdivide(triangles)

          point_to_vector = lambda pt: Penrose_Tiling.complex_to_vector(pt);

          tile_list = []; 
          for (color, A, B, C) in triangles:
               tile_list.append([point_to_vector(A), point_to_vector(B), point_to_vector(C)]); 
          return tile_list; 

     ## def 

## class
PenroseKD.py 文件源码 项目:WXMLTilingsHOWTO 作者: maxieds 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def get_tiles(self): 

          # Create an initial wheel of red triangles around the origin 
          # (from the comments section of the reference): 
          radiusR = DEFAULT_RADIUS_R; 
          triangles = []
          for i in xrange(10):
               B = cmath.rect(1, (2*i - 1) * math.pi / radiusR)
               C = cmath.rect(1, (2*i + 1) * math.pi / radiusR)
               if i % 2 == 0:
                    B, C = C, B # Make sure to mirror every second triangle
               ##
               triangles.append((COLOR_RED, B, 0j, C)) 
          ##

          for i in range(self.num_steps):
               triangles = self.subdivide(triangles)

          point_to_vector = lambda pt: PenroseKD_Tiling.complex_to_vector(pt);

          tile_list = []; 
          for (color, A, B, C) in triangles:
               tile_list.append([point_to_vector(A), point_to_vector(B), \
                                 point_to_vector(C)]); 
          return tile_list; 

     ## def 

## class
quickjoint.py 文件源码 项目:QuickJoint 作者: JarrettR 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def draw_box(self, start, guideLine, xDistance, yDistance, kerf):
        polR, polPhi = cmath.polar(guideLine)

        #Kerf expansion
        if self.flipside:  
            start -= cmath.rect(kerf / 2, polPhi)
            start -= cmath.rect(kerf / 2, polPhi + (cmath.pi / 2))
        else:
            start -= cmath.rect(kerf / 2, polPhi)
            start -= cmath.rect(kerf / 2, polPhi - (cmath.pi / 2))

        lines = []
        lines.append(['M', [start.real, start.imag]])

        #Horizontal
        polR = xDistance
        move = cmath.rect(polR + kerf, polPhi) + start
        lines.append(['L', [move.real, move.imag]])
        start = move

        #Vertical
        polR = yDistance
        if self.flipside:  
            polPhi += (cmath.pi / 2)
        else:
            polPhi -= (cmath.pi / 2)
        move = cmath.rect(polR  + kerf, polPhi) + start
        lines.append(['L', [move.real, move.imag]])
        start = move

        #Horizontal
        polR = xDistance
        if self.flipside:  
            polPhi += (cmath.pi / 2)
        else:
            polPhi -= (cmath.pi / 2)
        move = cmath.rect(polR + kerf, polPhi) + start
        lines.append(['L', [move.real, move.imag]])
        start = move

        lines.append(['Z', []])

        return lines
quickjoint.py 文件源码 项目:QuickJoint 作者: JarrettR 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def draw_slots(self, path):
        #Female slot creation

        start = self.to_complex(path[0][1])
        end = self.to_complex(path[1][1])

        if self.edgefeatures == False:
            segCount = (self.numslots * 2) 
        else:
            segCount = (self.numslots * 2) - 1

        distance = end - start
        debugMsg(distance)
        debugMsg("segCount - " + str(segCount))

        try:
            if self.edgefeatures:
                segLength = self.get_length(distance) / segCount
            else:
                segLength = self.get_length(distance) / (segCount + 1)
        except:
            segLength = self.get_length(distance)

        debugMsg("segLength - " + str(segLength))
        newLines = []

        line_style = simplestyle.formatStyle({ 'stroke': '#000000', 'fill': 'none', 'stroke-width': str(self.unittouu('1px')) })

        for i in range(segCount):
            if (self.edgefeatures and (i % 2) == 0) or (not self.edgefeatures and (i % 2)):
                newLines = self.draw_box(start, distance, segLength, self.thickness, self.kerf)
                debugMsg(newLines)

                slot_id = self.uniqueId('slot')
                g = inkex.etree.SubElement(self.current_layer, 'g', {'id':slot_id})

                line_atts = { 'style':line_style, 'id':slot_id+'-inner-close-tab', 'd':simplepath.formatPath(newLines) }
                inkex.etree.SubElement(g, inkex.addNS('path','svg'), line_atts )

            #Find next point
            polR, polPhi = cmath.polar(distance)
            polR = segLength
            start = cmath.rect(polR, polPhi) + start


问题


面经


文章

微信
公众号

扫码关注公众号