MCPcopy Create free account
hub / github.com/ActiveState/code / transformer

Class transformer

recipes/Python/576830_analog_clock/recipe-576830.py:24–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22 sys.stdin.__class__.__name__ == 'PyShell'
23
24class transformer:
25
26 def __init__(self, world, viewport):
27 self.world = world
28 self.viewport = viewport
29
30 def point(self, x, y):
31 x_min, y_min, x_max, y_max = self.world
32 X_min, Y_min, X_max, Y_max = self.viewport
33 f_x = float(X_max-X_min) /float(x_max-x_min)
34 f_y = float(Y_max-Y_min) / float(y_max-y_min)
35 f = min(f_x,f_y)
36 x_c = 0.5 * (x_min + x_max)
37 y_c = 0.5 * (y_min + y_max)
38 X_c = 0.5 * (X_min + X_max)
39 Y_c = 0.5 * (Y_min + Y_max)
40 c_1 = X_c - f * x_c
41 c_2 = Y_c - f * y_c
42 X = f * x + c_1
43 Y = f * y + c_2
44 return X , Y
45
46 def twopoints(self,x1,y1,x2,y2):
47 return self.point(x1,y1),self.point(x2,y2)
48
49class clock:
50

Callers 2

__init__Method · 0.70
redrawMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected