Tuesday, July 15th, 2008
Paint Servers: SVG and Canvas
<p>Robert O'Callahan and Dave Hyatt have been chatting about paint servers as Robert creates SVG ones and then arbitary elements.This continues the meme of taking common use cases and making them easy via CSS (e.g. reflections).
Here is the SVG version:
-
-
<html xmlns="http://www.w3.org/1999/xhtml"
-
xmlns:svg="http://www.w3.org/2000/svg">
-
h1 { background:url(#h); }
-
p { background:url(#p); }
-
span { background:url(#h); }
-
</style>
-
</head>
-
<h1 style="width:95%;">Heading</h1>
-
<p style="width:90%; border:1px solid black; margin-left:2em;">
-
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
-
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
-
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
-
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
-
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
-
deserunt mollit anim id est laborum."
-
</p>
-
<div style="width:200px;">"Lorem ipsum dolor sit amet,
-
<span>consectetur adipisicing elit, sed do eiusmod</span>
-
tempor incididunt ut labore et dolore magna aliqua.</div>
-
<svg :svg style="height:0">
-
</svg><svg :linearGradient id="h" x2="1" y2="0">
-
<svg :stop stop-color="yellow" offset="0"/>
-
<svg :stop stop-color="yellow" stop-opacity="0" offset="1"/>
-
</svg>
-
<svg :pattern id="p" patternUnits="userSpaceOnUse"
-
x="0" y="0" width="50" height="50"
-
viewBox="-1 -1 9 5.5">
-
<svg :path d="M 0 0 L 7 0 L 3.5 7 z" fill="red" stroke="blue" opacity="0.3"/>
-
</svg>
-
-
</body>
-
</html>
-
And here for canvas:
-
-
<!DOCTYPE HTML>
-
p { background:url(#d); }
-
</style>
-
</head>
-
<body style="background:yellow;">
-
<p style="width:60%; border:1px solid black; margin-left:100px;">
-
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
-
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
-
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
-
irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
-
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
-
deserunt mollit anim id est laborum."
-
</p>
-
<canvas id="d" width="50" height="50"></canvas>
-
var d = document.getElementById("d");
-
var iteration = 0;
-
function iterate() {
-
++iteration;
-
var ctx = d.getContext("2d");
-
ctx.save();
-
ctx.clearRect(0, 0, 50, 50);
-
ctx.translate(25,25);
-
ctx.rotate(Math.PI*iteration/180);
-
ctx.fillStyle = "lime";
-
ctx.fillRect(-10, -10, 20, 20);
-
ctx.restore();
-
setTimeout(iterate, 10);
-
}
-
iterate();
-
</script>
-
</body>
-
</html>
-
Exciting!
Related Content:











Hopefully someone will post and elaborate on the 10 words that were rudely thrown together to make what appears to be a completely pointless article.
I mean seriously, there is no substance to this post. Ajaxian needs to re-evaluate their staff.
A paint server is an SVG concept used to generate fills: http://www.w3.org/TR/1999/WD-SVG-19990211/painting.html
I agree with Sean — thanks for the code samples, I guess.