var ctx = document.getElementById('canvas').getContext('2d');
for (var x = 0.5; x < 300; x += 10) {ctx.moveTo(x, 0);ctx.lineTo(x, 300);}for (var y = 0.5; y < 300; y += 10) {ctx.moveTo(0, y);ctx.lineTo(300, y);}ctx.strokeStyle = "#ddd";ctx.stroke(); // Grid
ctx.save();
ctx.fillRect(10,10,100,100);
ctx.fillStyle = 'rgb(10, 100, 200)';
ctx.save();
ctx.fillRect(30, 30, 100, 100);
ctx.fillStyle = 'rgb(10, 200, 100)';
ctx.fillRect(50, 50, 100, 100);
ctx.restore();
ctx.fillRect(70, 70, 100, 100);
ctx.restore();
ctx.fillRect(90, 90, 100, 100);
// WARNING
// For simple usage, like this one, saving values in variables is quicker.
// ctx.save() is saving a LOT of information therefore use with caution.
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.