Using Curve objects
This test program is in the main function of curve.py
. Uncomment
out portions of the function as you implement methods in the Curve
class. The full function graphs the function f(x) = x^3 - 15x
.
def main():
curve = Curve()
print(curve)
x=-5
while x <= 5:
curve.add_point(x, x**3 - 15*x)
x += 0.05
print(curve)
#curve.set_color("green")
#print(curve)
#win = GraphWin("Testing Curve class", 1000, 1000)
#xmin = curve.get_min_x()
#xmax = curve.get_max_x()
#ymin = curve.get_min_y()
#ymax = curve.get_max_y()
#print("%.2f, %.2f, %.2f, %.2f" % (xmin,ymin,xmax,ymax))
#win.setCoords(xmin,ymin,xmax,1.2*ymax)
#curve.draw(win)
#win.getMouse()
#baseline = curve.get_baseline()
#baseline.set_color("red")
#baseline.draw(win)
#win.getMouse()
if __name__ == "__main__":
main()
Go ahead and run python3 curve.py
. The program should now print out
basic information for a Curve object that has no points, then (since
you added points) print out information for a Curve object that has
several points, representing the curve f(x) = x^3 - 15x
.
$ python3 curve.py Number of points: 0 Color = black ------ Points: ------ Number of points: 201 Color = black ------ Points: Point(-5.0, -50.0) Point(-4.95, -47.03737500000001) Point(-4.9, -44.14900000000003) Point(-4.8500000000000005, -41.33412500000003) Point(-4.800000000000001, -38.59200000000004) ... ------