Tuesday, January 24, 2012

HTML5: more on quadraticCurveTo() - how the Quadratic Curve affected by the control point

Refer to last post "HTML5: draw quadratic Bézier curve using quadraticCurveTo()". We are going to change the control point's x and y to know more about the how the Quadratic Curve affected.

Example:
how the Quadratic Curve affected by the control point
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mobile-Web-App: HTML5 Canvas</title>
<script type="text/javascript">
function loadcanvas(){
var canvas;
var context;

//get element by ID of "mycanvas"
canvas = document.getElementById("mycanvas");

//create a "2d" context object
context = canvas.getContext("2d");

drawPath(context);
}

function drawPath(c){
drawQuadraticCurveTo(c, 100);

for (i = 0; i <= 300; i = i + 20)
{
drawQuadraticCurveTo(c, i, i, i);
}
}

function drawQuadraticCurveTo(c, cpx, cpy){

c.lineWidth = 3;

c.strokeStyle = "#000000";
c.beginPath();
c.moveTo(50, 150)
c.quadraticCurveTo(cpx, cpy, 250, 150); //(cpx, cpy, x, y)
c.stroke();
}

</script>
</head>
<body onload="loadcanvas();">
<h1>Mobile-Web-App: HTML5 canvas</h1>

<canvas id="mycanvas" style="border: 5px solid;" width="300" height="300">
Sorry! Your browser doesn't support Canvas.
</canvas>
</body>
</html>

No comments:

Post a Comment