Beispiel #1
0
def drawTree(a, b, maxDepth, sizes, depth=0):
    yield (a, b)
    if depth<maxDepth:
        height = sizes[depth]
        yield drawTree(b, vec2.add(b, (-height,height)),
                       maxDepth, sizes, depth+1)
        yield drawTree(b, vec2.add(b, (+height,height)),
                       maxDepth, sizes, depth+1)
Beispiel #2
0
def drawTree(a, b, maxDepth, sizes, depth=0):
    yield (a, b)
    if depth < maxDepth:
        height = sizes[depth]
        yield drawTree(b, vec2.add(b, (-height, height)),
                       maxDepth, sizes, depth + 1)
        yield drawTree(b, vec2.add(b, (+height, height)),
                       maxDepth, sizes, depth + 1)
Beispiel #3
0
def makeTreeGraph(output, symPath, count, shuffle=False):
    random.seed(10)
    c = PdfCanvas(output,
                  basePos=(0, 0),
                  baseScale=(72 * 5, 72 * 5),
                  pageSize=(72 * 10, 72 * 10))

    c.startDrawing()
    c.setColor(1, 1, 1)
    c.drawFilledCircle((0, 0), .9)
    c.setColor(0, 0, 0)
    c.setLineWidth(5)
    c.drawOutlineCircle((0, 0), .9)
    c.setLineWidth(1)
    #    c.setColor(.2,.6,.3)

    N = 8
    sizes = [.5**(i + 1) for i in range(N)]
    res = drawTree((0., -.9), (0., -.5), N,
                   [1.3 * s / sum(sizes) for s in sizes])

    #    [c.drawLine(a,b) for a,b in generator_fold(res)]

    def mapIt(center, radius, spanAngle, (x, y)):
        a = vec2.sub(center, (0, radius))
        b = vec2.add(center,
                     vec2.fromangle(math.pi * .5 + 2 * x * spanAngle, radius))
        return vec2.lerp(a, b, y)
Beispiel #4
0
    def drawStringCentered(self, boxLL, boxUR, text):
        ll, ur = self.getStringBBox(text)
        stringSize = vec2.sub(ur, ll)
        boxSize = vec2.sub(boxUR, boxLL)
        deltaSize = vec2.sub(boxSize, stringSize)
        halfDeltaSize = vec2.mulN(deltaSize, .5)

        self.drawString(vec2.add(boxLL, halfDeltaSize), text)
Beispiel #5
0
	def drawStringCentered(self, boxLL, boxUR, text):
		ll,ur = self.getStringBBox(text)
		stringSize = vec2.sub(ur,ll)
		boxSize = vec2.sub(boxUR,boxLL)
		deltaSize = vec2.sub(boxSize, stringSize)
		halfDeltaSize = vec2.mulN(deltaSize, .5)
		
		self.drawString(vec2.add(boxLL,halfDeltaSize), text)
Beispiel #6
0
 def getTreePos(depth, maxDepth, index, ranges=None, depthOrder=None):
     isoT = depth/(maxDepth-1)
     isoCent = vec2.add((0.,-.9),(0.,isoT*.9))
     isoRadius = zeroRad + (oneRad-zeroRad)*isoT        
     total = 2**(depth+1)
     #        isoSpanAngle = math.pi*.5 - vec2.toangle(vec2.sub(vec2.fromangle(math.pi*.5 + spanAngle,.9),
     #                                             isoCent))
     isoSpanAngle = math.pi*.1 + (math.pi*.7 - math.pi*.1)*isoT
     if ranges:
         min,max = ranges
         if max[depth]==min[depth]:
             x = 0.
         else:
             x = (index - min[depth])/(max[depth]-min[depth])
     elif depthOrder:
         idx = depthOrder[depth].index(index)
         x = idx/(len(depthOrder[depth])-1)
     else:
         x = index/(total-1)
     return vec2.add(isoCent,vec2.fromangle(math.pi*.5 + (2*x-1)*isoSpanAngle, isoRadius))
Beispiel #7
0
 def getTreePos(depth, maxDepth, index, ranges=None, depthOrder=None):
     isoT = depth / (maxDepth - 1)
     isoCent = vec2.add((0., -.9), (0., isoT * .9))
     isoRadius = zeroRad + (oneRad - zeroRad) * isoT        
     total = 2 ** (depth + 1)
     #        isoSpanAngle = math.pi*.5 - vec2.toangle(vec2.sub(vec2.fromangle(math.pi*.5 + spanAngle,.9),
     #                                             isoCent))
     isoSpanAngle = math.pi * .1 + (math.pi * .7 - math.pi * .1) * isoT
     if ranges:
         min, max = ranges
         if max[depth] == min[depth]:
             x = 0.
         else:
             x = (index - min[depth]) / (max[depth] - min[depth])
     elif depthOrder:
         idx = depthOrder[depth].index(index)
         x = idx / (len(depthOrder[depth]) - 1)
     else:
         x = index / (total - 1)
     return vec2.add(isoCent, vec2.fromangle(math.pi * .5 + (2 * x - 1) * isoSpanAngle, isoRadius))
Beispiel #8
0
def makeTreeGraph(output, symPath, count, shuffle=False):
    random.seed(10)
    c = PdfCanvas(output, basePos=(0,0), baseScale=(72*5,72*5),
                  pageSize=(72*10,72*10))

    c.startDrawing()
    c.setColor(1,1,1)
    c.drawFilledCircle((0,0),.9)
    c.setColor(0,0,0)
    c.setLineWidth(5)
    c.drawOutlineCircle((0,0),.9)
    c.setLineWidth(1)
#    c.setColor(.2,.6,.3)

    N = 8
    sizes = [.5**(i+1) for i in range(N)]
    res = drawTree((0.,-.9), (0.,-.5), N, [1.3*s/sum(sizes) for s in sizes])
#    [c.drawLine(a,b) for a,b in generator_fold(res)]

    def mapIt(center, radius, spanAngle, (x,y)):
        a = vec2.sub(center,(0,radius))
        b = vec2.add(center,vec2.fromangle(math.pi*.5 + 2*x*spanAngle, radius))
        return vec2.lerp(a, b, y)
Beispiel #9
0
    c.setLineWidth(5)
    c.drawOutlineCircle((0,0),.9)
    c.setLineWidth(1)
#    c.setColor(.2,.6,.3)

    N = 8
    sizes = [.5**(i+1) for i in range(N)]
    res = drawTree((0.,-.9), (0.,-.5), N, [1.3*s/sum(sizes) for s in sizes])
#    [c.drawLine(a,b) for a,b in generator_fold(res)]

    def mapIt(center, radius, spanAngle, (x,y)):
        a = vec2.sub(center,(0,radius))
        b = vec2.add(center,vec2.fromangle(math.pi*.5 + 2*x*spanAngle, radius))
        return vec2.lerp(a, b, y)
    m = lambda pt: mapIt((0,0),.9,math.pi*.7, pt)
    toBox = lambda pt: vec2.div(vec2.add(pt,(0.,.9)),
                                      (2*1.3,1.7))
    def lm((x,y)):
        x,y = toBox((x,y))
        N = 100
        return m((x,1-math.log(1+(1-y**4),2)))
        return m((x,(N**(1+y)-N)/(N**2-N)))
        return m((x,y))
#    c.drawOutlineBox((-.5,0),(.5,1))
    
    #[c.drawLine(lm(a),lm(b)) for a,b in generator_fold(res)]

    spanAngle = math.pi*.9
    zeroRad = vec2.length(vec2.sub(vec2.fromangle(math.pi*3/2,.9),
                                   vec2.fromangle(math.pi*.5 + spanAngle,.9)))
    oneRad = .9
Beispiel #10
0
    c.setLineWidth(5)
    c.drawOutlineCircle((0, 0), .9)
    c.setLineWidth(1)
#    c.setColor(.2,.6,.3)

    N = 8
    sizes = [.5 ** (i + 1) for i in range(N)]
    res = drawTree((0., -.9), (0., -.5), N, [1.3 * s / sum(sizes) for s in sizes])
#    [c.drawLine(a,b) for a,b in generator_fold(res)]

    def mapIt(center, radius, spanAngle, (x, y)):
        a = vec2.sub(center, (0, radius))
        b = vec2.add(center, vec2.fromangle(math.pi * .5 + 2 * x * spanAngle, radius))
        return vec2.lerp(a, b, y)
    m = lambda pt: mapIt((0, 0), .9, math.pi * .7, pt)
    toBox = lambda pt: vec2.div(vec2.add(pt, (0., .9)),
                                      (2 * 1.3, 1.7))
    def lm((x, y)):
        x, y = toBox((x, y))
        N = 100
        return m((x, 1 - math.log(1 + (1 - y ** 4), 2)))
        return m((x, (N ** (1 + y) - N) / (N ** 2 - N)))
        return m((x, y))
#    c.drawOutlineBox((-.5,0),(.5,1))
    
    # [c.drawLine(lm(a),lm(b)) for a,b in generator_fold(res)]

    spanAngle = math.pi * .9
    zeroRad = vec2.length(vec2.sub(vec2.fromangle(math.pi * 3 / 2, .9),
                                   vec2.fromangle(math.pi * .5 + spanAngle, .9)))
    oneRad = .9