Kindly note the error which i made in my code :

<script type="text/javascript">
function createCanopyPath(context) {
// Draw the tree canopy
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
function drawTrails() {
var canvas = document.getElementById('trails');
var context = canvas.getContext('2d');;
context.translate(130, 250);
// Create the shape for our canopy path
// Stroke the current path
<body onload="drawTrails()">
   <canvas id="trials" style="border: 1px solid;" width="600" height="600"></canvas>

Recommended Answers

All 3 Replies


Should be id="trails"

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

<!DOCTYPE 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, learning, and sharing knowledge.