Kindly note the error which i made in my code :

<html>
<head>
<script type="text/javascript">
function createCanopyPath(context) {
// Draw the tree canopy
context.beginPath();
context.moveTo(-25, -50);
context.lineTo(-10, -80);
context.lineTo(-20, -80);
context.lineTo(-5, -110);
context.lineTo(-15, -110);
// Top of the tree
context.lineTo(0, -140);
context.lineTo(15, -110);
context.lineTo(5, -110);
context.lineTo(20, -80);
context.lineTo(10, -80);
context.lineTo(25, -50);
// Close the path back to its start point
context.closePath();
}
function drawTrails() {
var canvas = document.getElementById('trails');
var context = canvas.getContext('2d');
context.save();
context.translate(130, 250);
// Create the shape for our canopy path
createCanopyPath(context);
// Stroke the current path
context.stroke();
context.restore();
}
</script>
</head>
<body onload="drawTrails()">
   <canvas id="trials" style="border: 1px solid;" width="600" height="600"></canvas>
</body>
</html>

Recommended Answers

All 3 Replies

getContext is available for html5 only. You should declare the doctype on top of your file.

<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
    </body>
</html>

hope that works

pritaeas is right, "trails" (keen eyes you have)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.