HTML and CSS Reference
In-Depth Information
Figure 4-2. Multiple curves with midpoints
Notice in Figure 4-2 that the first and last midpoints are not used, and the first and last original points
remain terminal points for the curves. You need to make in-between points only for the second point up to
the second-to-last point. Here's an updated version of the previous random curves example (document
05-multi-curve-2.html ):
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Multi Curve 2</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<canvas id="canvas" width="400" height="400"></canvas>
<script>
window.onload = function () {
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d'),
points = [],
numPoints = 9,
ctrlPoint = {};
for (var i = 0; i < numPoints; i++) {
points.push({
x: Math.random() * canvas.width,
y: Math.random() * canvas.height
});
}
//move to the first point
context.beginPath();
context.moveTo(points[0].x, points[1].y);
//curve through the rest, stopping at each midpoint
 
Search WWH ::




Custom Search