Canvas: Difference between revisions
No edit summary |
No edit summary |
||
Line 17: | Line 17: | ||
p.fillRect(0, 0, 100, 100); | p.fillRect(0, 0, 100, 100); | ||
== Examples == | |||
<source lang="javascript"> <!DOCTYPE html> | |||
<html> | |||
<head> | |||
<meta charset="utf-8" /> | |||
<script> | |||
function draw(){ | |||
c = document.getElementById("c") | |||
//console.log("c is",c) | |||
p = c.getContext("2d") | |||
x = 10 | |||
while (x<3000) { | |||
p.strokeRect(x,100,20,40) | |||
x+=60 | |||
} | |||
} | |||
</script> | |||
</head> | |||
<body onload="draw()"> | |||
<h1>Hello canvas</h1> | |||
<canvas id="c" width="640" height="640" style="border: 3px dotted red"></canvas> | |||
</body> | |||
</html> | |||
</source> | |||
== Tutorials & Reference == | == Tutorials & Reference == |
Revision as of 16:36, 24 September 2012
The canvas tag was introduced by Apple and has been standardized to become part of HTML5.
A example for color cycling with the canvas element [[1]]
Get the canvas tag:
c=document.getElementById("c")
Get the "context" (like a paper):
p=c.getContext("2d");
Draw something!
p.fillRect(0, 0, 100, 100);
Examples
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script>
function draw(){
c = document.getElementById("c")
//console.log("c is",c)
p = c.getContext("2d")
x = 10
while (x<3000) {
p.strokeRect(x,100,20,40)
x+=60
}
}
</script>
</head>
<body onload="draw()">
<h1>Hello canvas</h1>
<canvas id="c" width="640" height="640" style="border: 3px dotted red"></canvas>
</body>
</html>