Returns a fixed point string approximating the number x, limiting the number of places past the decimal point if there would be more than digitCutoff significant digits, and removing unneeded trailing '0's and '.'. Assuming window dimensions under 10**digitCutoff pixels, and at lea
(x, digitCutoff = 5)
| 970 | return "#%02x%02x%02x" % (r,g,b) |
| 971 | |
| 972 | def approx(x, digitCutoff = 5): |
| 973 | """ Returns a fixed point string approximating the number x, limiting |
| 974 | the number of places past the decimal point if there would be more than |
| 975 | digitCutoff significant digits, and removing unneeded trailing '0's and '.'. |
| 976 | Assuming window dimensions under 10**digitCutoff pixels, and at least some |
| 977 | legal world coordinate having magnitude at least 1, this system should |
| 978 | provide concise approximations that distinguish all pixel coordinates. |
| 979 | """ |
| 980 | fracDig = max(0, digitCutoff - len(str(int(abs(x))).lstrip('0'))) |
| 981 | format = "%%.%df" % fracDig |
| 982 | return (format % x).rstrip('0').rstrip('.') |
| 983 | |
| 984 | def test(): |
| 985 | win = GraphWin() |