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()

Below is sample output from running the sample program with the lines commented as above.

$ 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)
...
------
Number of points: 201
Color = green
------
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)
...
------
-5.00, -50.00, 5.00, 50.00

And here’s the graphics window resulting from the above code, before and after drawing the baseline curve.

curve example with baseline