pygame is
Python
Simple DirectMedia Layer
 
 
pygame.org is
Site Swing
pycurve

pycurve - 1

Chandler Armstrong (omnirizon)

Tags:

Description

Python implementation of LaGrange, Bezier, and B-spline curves. The algorithms use their respective interpolation/basis functions, so are capable of producing curves of any order. The B-splines use Cox-De Boor and support knot insertion. 2-d only.

see examples, in the download, for a runnable example

To use this library on your own, you will need to know a little bit, but I've done most of the hard work, OK?

This library includes LaGrange, Bezier, and B-spline curves. Lagrange and Bezier are mostly just for educational purposes, what we really want are the B-splines.

B-splines are really just Bezier curves glued together. To make a B-spline you need three things: a set of control points, a vector of knots, and a degree. The control points guide the curve, and the knots direct the curve via these guides. The more knots you have in a curve, the more control you have over how it behaves via the control points. The degree of the curve is actually the order of the comprising Bezier curves (an order 3 Bezier curve is made using three control points). For certain reasons, high order Bezier curves don't behave very well (thus the reason to use B-splines!). This means you should keep the degree low, usually 3 is good enough (in fact, most other B-spline algorithms, including those on this site, just hardcode the algorithms to degree 3, or cubic B-Splines).

There are certain relationships between the number of control points, knots, and the degree, such that if you set two of these numbers, the third must necessary be some value. Look inside my example code for a quick example on how to use these identities to start making B-spline curves. Usually, you will set your control points and degree, and then let the knots be generated automatically as the necessary number of evenly spaced values between 0 and 1 (once again, see the example code). However, this is not necessary, you may want to make your knots not be evenly spaced, in which case you must provide them yourself.

Ok then, just run the demo, inspect that code, and try making your own curves. (no need to worry about diving into the algorithm code, unless you want to learn it, and if you do it is pretty well documented)

Links

Home Page: http://code.google.com/p/pycurve/

Screenshot


click to view original size

Releases

pycurve - 1.0.2 - Jul 23, 2011
pycurve - 1.0.1 - Jul 15, 2011
pycurve - 1 - Jan 18, 2010

Pygame.org account Comments

If you wish to leave a comment with your pygame.org account, please sign in first.

March 5, 2011 5:38pm - Chandler Armstrong - nickname: (omnirizon)
I've released a distribution built with distutils, it is 'curve-1.0.0.zip'. If you want to put curve in your site-packages, download it and install with 'python setup.py install'. I've changed the demo so it only computes 1000 steps instead of millions. the results compute in a flash, but the line has some small gaps in it. the demo can be run with:

from curve.demos.bspline import main as demo_bspline
demo_bspline()

the demo requires pygame, but the curve package itself does not.
March 5, 2010 10:19am - Davide - nickname: (boyska) - 4/5
I implemented DR0ID idea.
http://pastie.org/853308
I just divide step_len by a factor, and join the resulting points with a line.
The greater the factore, the fastest the program, the less accurate the result.
With a factor of 100 you have good times and almost-perfect quality.
With a factor of 5000 it computes in a blink, and quality is almost decent
January 24, 2010 11:45am - DR0ID - nickname: (dr0id)
First I thought it does not work, but then I realized that the step_len was far to big (or the step to small) and therefor took some time. You could use far fewer steps and using pygame.draw.line instead setting single points (I know, it would not be that smooth, but faster). I'm pretty sure you know <a href="http://www.pygame.org/wiki/BezierCurve?parent=CookBook">this</a> cookbook entry (it is Bezier only, but really fast). Good work.
spotlight

 
our projects
pygame.org welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
 
recent releases
Apr 21, 2014


Apr 19, 2014

Apr 16, 2014

Apr 13, 2014

Apr 9, 2014

Mar 18, 2014


Mar 15, 2014


Mar 14, 2014

Mar 13, 2014

... more!
 
for pygame related questions, comments, and suggestions, please see help (lists, irc)