Connecting...

This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of HTML
For more information, please see full course syllabus of HTML
HTML The Canvas Element
Lecture Description
In this lesson our instructor talks about the canvas element. He first talks about creating the element. Then he discusses creating the canvas in JavaScript. Finally he talks about methods for drawing in the canvas and some examples.
Bookmark & Share
Embed
Share this knowledge with your friends!
Copy & Paste this embed code into your website’s HTML
Please ensure that your website editor is in text mode when you paste the code.(In Wordpress, the mode button is on the top right corner.)
×
- - Allow users to view the embedded video in full-size.
Next Lecture
Previous Lecture
0 answers
Post by Eric Rapinchuk on May 10, 2012
add this at the top for the pic...
var img = new Image();
img.src = ("nightpan.jpg");
ctx.drawImage(img,0,0);
0 answers
Post by Eric Rapinchuk on May 10, 2012
This code works guys... ;)
<!DOCTYPE html>
<html>
<head>
<title>Canvas</title>
<link rel="stylesheet" href="css.css"></link>
</head>
<body onload="draw()"> <!-- I NEED THIS -->
<h1>Canvas Element</h1>
<p>This isn't an image, it's a canvas.</p>
<canvas id="draw" width="200" height="200">
Sorry, your browser doesn't support the canvas element :(
</canvas>
<script type = "application/javascript">
function draw() { <!-- i needed this?!!?!?!? -->
var paint = document.getElementById("draw");
var ctx = paint.getContext("2d");
ctx.fillStyle = "rgb(200,0,0)";
ctx.fillRect (10, 10, 55, 50);
ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
ctx.fillRect (20, 20, 55, 50);
ctx.fillStyle = "rgba(0,200,0, 0.5)";
ctx.fillRect (30, 30, 55, 50);
ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
ctx.fillRect (40, 40, 55, 50);
ctx.fillStyle = "rgba(200,0,200, 0.5)";
ctx.fillRect (50, 50, 55, 50);
ctx.fillStyle = "rgba(0, 200, 200, 0.5)";
ctx.fillRect (60, 60, 55, 50);
}
<!-- i took the if/else statement out :(-->
</script>
</body>
</html>
0 answers
Post by Richard C. Witt, Jr. on December 13, 2011
Brenton,
I've been able to replicate all the code example except this one. Did you have a CSS style sheet that was being referenced too? The only thing that appeared in my Browser was this:
Canvas Element
This isn't an image, it's a canvas
Nothing other than that appeared. I checked my code to make sure it was what you showed and I tried it in Firefox, Opera. Please advise.
Richard C. Witt
crgmohi@aol.com
0 answers
Post by Alisher Ulugbekov on January 23, 2011
Very instructive. Thanks Brenton.