Tuesday 15 March 2011

graphics - how to create bezier curve in JavaScript? -



graphics - how to create bezier curve in JavaScript? -

i trying create bezier curve using javascript on html5 canvas. below code have written in drawbeziercurve function. result that, 4 points, cant bezier curve appear. help guys?

function drawbeziercurve() { "use strict"; var t, i, x, y, x0, x1, x2, x3; // (t = 1; t <= nsteps; t++) { //t = 1/nsteps q0 = calculatebezierpoint(0, x0, x1, x2, x3); for(i = 0; <= nsteps; i++) { t = / nsteps; q1 = calculatebezierpoint(t, x0, x1, x2, x3); drawline(q0, q1); q0 = q1; } //[x] = (1-t)³x0 + 3(1-t)²tx1+3(1-t)t²x2+t³x3 //[y] = (1-t)³y0 + 3(1-t)²ty1+3(1-t)t²y2+t³y3 procedure draw_bezier(a, v1, v2, d) b = + v1 c = d + v2 //loop t 0 1 in steps of .01 for(t=0; t <=1; t+ 0.1){ = t b = 1 - t point = a*b³ + 3*b*b²*a + 3c*b*a2 + d*a³ //drawpixel (point) drawline(arrayx[0], arrayy[0], (arrayx[0] + arrayx[1] + arrayx[2] + arrayx[3]) / 4, (arrayy[0] + arrayy[1] + arrayy[2] + arrayy[3]) / 4, 'blue'); //end of loop } end of draw_bezier /* drawline(arrayx[0], arrayy[0], (arrayx[0] + arrayx[1] + arrayx[2] + arrayx[3]) / 4, (arrayy[0] + arrayy[1] + arrayy[2] + arrayy[3]) / 4, 'blue'); drawline((arrayx[0] + arrayx[1] + arrayx[2] + arrayx[3]) / 4, (arrayy[0] + arrayy[1] + arrayy[2] + arrayy[3]) / 4, arrayx[3], arrayy[3], 'blue'); */ } // points array

please check url, explaining procedure properly:

http://devmag.org.za/2011/04/05/bzier-curves-a-tutorial/

javascript graphics bezier bezier-curve cubic

No comments:

Post a Comment