Friday, April 4, 2014

Drawing Bezier Curves in Python

I found a great algorithm in Python that draw the Bezier curve (more about Bezier curve HERE) defined by a set of control points.
You can find the original algorithm HERE and my opinion about it is that its brilliant but I had an objection on it. I didnt like the ideea of defining the control points in source code, I wanted to input the number of control points and the values after xOy axis.
So... I made some changes:

  • I deleted the initialization of controlPoints from doDrawing(...) function;
  • I created a new function def inputpoints() in which I input the number of controlPoints and the xOy coordinates and I declared globally the variable controlPoints:
def inputpoints():
global controlPoints
        print("nr of points")
nr=int(input())#nr of points
controlPoints=np.zeros((nr,2),int)   
for i in xrange(nr):
controlPoints[i][0]=int(input())
controlPoints[i][1]=int(input())
  • I added a new line inputpoints() before main(sys.argv[1:])
And the result is:

PS: I wont put the code because it isnt mine but if you want to try the original code or to try it with my modifications, you have a link at the beginning of this article!


Related Posts by Categories

0 comments:

Post a Comment