2 import gfxprim
.core
as core
3 import gfxprim
.backends
as backends
4 import gfxprim
.gfx
as gfx
17 def compute(func
, x
, y_min
, y_max
):
21 except ZeroDivisionError:
24 return - H
* ret
/ (y_max
- y_min
) + (H
* y_max
) / (y_max
- y_min
)
26 def x_to_x(x
, x_min
, x_max
):
27 return (x_max
- x_min
) * x
/ W
+ x_min
29 class plotter(object):
30 def __init__(self
, func
, x_min
, x_max
, y_min
, y_max
):
32 self
.y
= compute(func
, x_to_x(self
.x
, x_min
, x_max
), y_min
, y_max
)
39 x
= x_to_x(self
.x
+ 1, self
.x_min
, self
.x_max
)
40 new_y
= compute(self
.func
, x
, self
.y_min
, self
.y_max
)
44 while (abs(new_y
- self
.y
) > 1 and inc
> EPS
):
45 x
= x_to_x(self
.x
+ inc
, self
.x_min
, self
.x_max
)
46 new_y
= compute(self
.func
, x
, self
.y_min
, self
.y_max
)
56 bk
= backends
.BackendSDLInit(W
, H
, 0, 0, "Plot AA")
59 print("Modify source for parameters,")
60 print("Kill to terminate ;-)")
61 print("Usage: function x_min x_max y_min y_max")
62 black
= bk
.context
.RGBToPixel(0, 0, 0)
64 x_min
= float(sys
.argv
[2])
65 x_max
= float(sys
.argv
[3])
66 y_min
= float(sys
.argv
[4])
67 y_max
= float(sys
.argv
[5])
68 p
= plotter(sys
.argv
[1], x_min
, x_max
, y_min
, y_max
)
75 x
= int((p
.x
+ 0.5) * 0x100)
76 y
= int((p
.y
+ 0.5) * 0x100)
77 gfx
.PutPixelAA(bk
.context
, x
, y
, bk
.context
.RGBToPixel(int(r
), int(g
), int(b
)))
84 if __name__
== '__main__':