def draw_align_ruler(self, pos, start, end): worldx1, worldy1, worldx2, worldy2 = self.win.get_visible() screenwidth, screenheight = self.win.get_size() worldwidth = worldx2 - worldx1 worldx1 -= worldwidth / 2.0 worldx2 += worldwidth / 2.0 # find appropriate unit if one is not given unit = visual.getRulerAutoSize(screenwidth, worldwidth) order = int(math.log10(unit)) unit2, unitstr = visual.getUnitSuffix(unit) x, y = pos vis = [] # make mini hashes vis.append(self.minicolor) i = unit * (max(start, worldx1 - x + start) // unit) while x + i - start <= worldx2 and i < end: if i >= start: vis.append( lines(x + i - start, y + self.bottom, x + i - start, y + self.height)) i += max(unit // 10, 1) # make main hashes # find starting local coord seqi = unit * ((start + self.coords.align2local(max(0, worldx1 - x), clamp=True)) // unit) \ - start-1 # find starting align coord i = self.coords.local2align(seqi) endseqi = min(self.coords.align2local(end, clamp=True), self.coords.align2local(worldx2 - x, clamp=True)) # draw all hashes in view while seqi <= endseqi: vis.append(self.maincolor) vis.append(lines(x + i + 1, y, x + i + 1, y + self.height)) vis.append(self.text_color) vis.append( text( str(int((seqi + start + 1) // unit2)) + unitstr, x + i + 1, y, x + i + 1 - unit, y + self.height, self.text_align, "right")) seqi += unit i = self.coords.local2align(seqi, clamp=True) # base line vis.append(lines(self.maincolor, x, y, x + end - start, y)) return group(*vis)
def draw_align_ruler(self, pos, start, end): worldx1, worldy1, worldx2, worldy2 = self.win.get_visible() screenwidth, screenheight = self.win.get_size() worldwidth = worldx2 - worldx1 worldx1 -= worldwidth / 2.0 worldx2 += worldwidth / 2.0 # find appropriate unit if one is not given unit = visual.getRulerAutoSize(screenwidth, worldwidth) order = int(math.log10(unit)) unit2, unitstr = visual.getUnitSuffix(unit) x, y = pos vis = [] # make mini hashes vis.append(self.minicolor) i = unit * (max(start, worldx1 - x + start) // unit) while x + i - start <= worldx2 and i < end: if i >= start: vis.append(lines(x + i - start, y + self.bottom, x + i - start, y + self.height)) i += max(unit // 10, 1) # make main hashes # find starting local coord seqi = unit * ((start + self.coords.align2local(max(0, worldx1 - x), clamp=True)) // unit) \ - start-1 # find starting align coord i = self.coords.local2align(seqi) endseqi = min(self.coords.align2local(end, clamp=True), self.coords.align2local(worldx2-x, clamp=True)) # draw all hashes in view while seqi <= endseqi: vis.append(self.maincolor) vis.append(lines(x + i+1, y, x + i+1, y + self.height)) vis.append(self.text_color) vis.append(text(str(int((seqi+start+1)//unit2)) + unitstr, x + i+1, y, x + i+1 - unit, y + self.height, self.text_align, "right")) seqi += unit i = self.coords.local2align(seqi, clamp=True) # base line vis.append(lines(self.maincolor, x, y, x + end - start, y)) return group(* vis)
def draw_ruler(self, pos, start, end): worldx1, worldy1, worldx2, worldy2 = self.win.get_visible() screenwidth, screenheight = self.win.get_size() worldwidth = worldx2 - worldx1 worldx1 -= worldwidth / 2.0 worldx2 += worldwidth / 2.0 # find appropriate unit if one is not given unit = visual.getRulerAutoSize(screenwidth, worldwidth) order = int(math.log10(unit)) unit2, unitstr = visual.getUnitSuffix(unit) x, y = pos vis = [] # make mini hashes if unit >= 10: vis.append(self.minicolor) i = unit * (max(start, worldx1 - x + start) // unit) while x + i - start <= worldx2 and i < end: if i >= start: vis.append( lines(x + i - start, y + self.bottom, x + i - start, y + self.top)) i += unit // 10 # make main hashes i = unit * (max(start, worldx1 - x + start) // unit) while x + i - start <= worldx2 and i < end: if i >= start: vis.append(self.maincolor) vis.append(lines(x + i - start, y, x + i - start, y + self.top)) vis.append(self.text_color) vis.append( text( str(int(i // unit2)) + unitstr, x + i - start, y, x + i - start - unit, y + self.top, self.text_align, "right")) i += unit # base line vis.append(lines(self.maincolor, x, y, x + end - start, y)) return group(*vis)
def draw_ruler(self, pos, start, end): worldx1, worldy1, worldx2, worldy2 = self.win.get_visible() screenwidth, screenheight = self.win.get_size() worldwidth = worldx2 - worldx1 worldx1 -= worldwidth / 2.0 worldx2 += worldwidth / 2.0 # find appropriate unit if one is not given unit = visual.getRulerAutoSize(screenwidth, worldwidth) order = int(math.log10(unit)) unit2, unitstr = visual.getUnitSuffix(unit) x, y = pos vis = [] # make mini hashes if unit >= 10: vis.append(self.minicolor) i = unit * (max(start, worldx1 - x + start) // unit) while x + i - start <= worldx2 and i < end: if i >= start: vis.append(lines(x + i - start, y+self.bottom, x + i - start, y+self.top)) i += unit // 10 # make main hashes i = unit * (max(start, worldx1 - x + start) // unit) while x + i - start <= worldx2 and i < end: if i >= start: vis.append(self.maincolor) vis.append(lines(x + i - start, y, x + i - start, y + self.top)) vis.append(self.text_color) vis.append(text(str(int(i//unit2)) + unitstr, x + i - start, y, x + i -start - unit, y + self.top, self.text_align, "right")) i += unit # base line vis.append(lines(self.maincolor, x, y, x + end - start, y)) return group(* vis)