PEP 308: Obfuscated Nested Ternaries (INACAIS)
Steven Taschuk
staschuk at telusplanet.net
Sat Feb 22 17:11:22 EST 2003
Quoth Gerrit Holl:
[...]
> I use the code to draw an arrow, [...]
Ah!
How about a computational strategy instead of a lookup?
def arrow(x, y):
polyline = []
def addpoint(x, y)
polyline.append((15*x + 25, 15*y + 25))
if x == y == 0:
x, y = -1, -1
for i in range(5):
addpoint(y, -x)
x, y = y, -x
else:
addpoint(-x, -y)
addpoint(x, y)
diagonal = (x*y != 0) # whether pointing to corner
def wing(wingx, wingy):
if diagonal:
wingx = (x + wingx)/2
wingy = (y + wingy)/2
addpoint(wingx, wingy)
addpoint(x, y)
wing(-y, x) # left wing
wing(y, -x) # right wing
return polyline
--
Steven Taschuk "The world will end if you get this wrong."
staschuk at telusplanet.net (Brian Kernighan and Lorrinda Cherry,
"Typesetting Mathematics -- User's Guide")
More information about the Python-list
mailing list