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)
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)
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)
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)
def getStringSize(self, string): ll, ur = self.getStringBBox(string) return vec2.sub(ur, ll)
def getStringSize(self, string): ll,ur = self.getStringBBox(string) return vec2.sub(ur,ll)
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 if 0: for i in range(N): t = i/(N-1) c.drawOutlineCircle(vec2.add((0.,-.9), (0.,t*.9)), zeroRad + (oneRad-zeroRad)*t) 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
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 if 0: for i in range(N): t = i / (N - 1) c.drawOutlineCircle(vec2.add((0., -.9), (0., t * .9)), zeroRad + (oneRad - zeroRad) * t) 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