Glass and Bottle
A simple drawing detailing a glass and bottle with water in them.
Canvas (your drawing will display here)
Editor (write code below)
var canvas = document.getElementById('my_drawings_canvas'); var context = canvas.getContext("2d"); function drawCanvas() { context.save(); context.translate(100, 40); drawBottle(); context.translate(-60, 100); drawGlass(); context.restore(); } function drawGlass() { context.save(); context.lineWidth = 1; context.strokeStyle = "rgba(0, 0, 0, 1)"; context.fillStyle = "rgba(235, 245, 255, 1)"; context.save(); context.translate(0, 60); context.scale(1, 0.2); context.lineWidth = 2; context.beginPath(); context.arc(0, 0, 16, 0, 2 * Math.PI, false); context.stroke(); context.restore(); context.beginPath(); context.moveTo(-17, 30); context.lineTo(-16, 60); context.lineTo(16, 60); context.lineTo(17, 30); context.closePath(); context.fill(); context.save(); context.translate(0, 0); context.scale(1, 0.2); context.lineWidth = 2; context.beginPath(); context.arc(0, 0, 18, 0, 2 * Math.PI, false); context.stroke(); context.restore(); context.save(); context.translate(0, 59.5); context.scale(1, 0.2); context.strokeStyle = "rgba(0, 0, 0, 0.25)"; context.beginPath(); context.arc(0, 0, 16, 0, 2 * Math.PI, false); context.fill(); context.stroke(); context.restore(); context.save(); context.fillStyle = "rgba(245, 250, 255, 1)"; context.fillRect(3, 30, 8, 31); context.restore(); context.save(); context.translate(0, 30); context.scale(1, 0.2); context.beginPath(); context.arc(0, 0, 17, 0, 2 * Math.PI, false); context.fill(); context.stroke(); context.restore(); context.beginPath(); context.moveTo(-18, 0); context.lineTo(-16, 60); context.stroke(); context.beginPath(); context.moveTo(18, 0); context.lineTo(16, 60); context.stroke(); context.restore(); } function drawBottle() { context.save(); context.lineWidth = 1; context.strokeStyle = "rgba(0, 0, 0, 1)"; context.fillStyle = "rgba(235, 245, 255, 1)"; drawBottleOutline(); context.fill(); context.clearRect(-20, 0, 40, 80); context.save(); context.fillStyle = "rgba(245, 250, 255, 1)"; context.fillRect(4, 80, 10, 80); context.restore(); context.save(); context.translate(0, 80); context.scale(1, 0.2); context.beginPath(); context.arc(0, 0, 20, 0, 2 * Math.PI, false); context.fill(); context.stroke(); context.restore(); drawBottleOutline(); context.stroke(); context.beginPath(); context.moveTo(-8, 152); context.bezierCurveTo(-6, 156, -4, 162, 0, 162); context.bezierCurveTo(4, 162, 6, 156, 8, 152); context.fill(); context.stroke(); context.fillStyle = "rgba(102, 102, 102, 1)"; context.fillRect(-8, 0, 16, 14); context.restore(); } function drawBottleOutline() { context.beginPath(); context.moveTo(6, 0); context.lineTo(6, 20); context.bezierCurveTo(10, 28, 20, 70, 20, 80); context.lineTo(20, 140); context.bezierCurveTo(20, 144, 18, 160, 14, 160); context.bezierCurveTo(10, 160, 6, 154, 0, 154); context.bezierCurveTo(-6, 154, -10, 160, -14, 160); context.bezierCurveTo(-18, 160, -20, 144, -20, 140); context.lineTo(-20, 80); context.bezierCurveTo(-20, 70, -10, 28, -6, 20); context.lineTo(-6, 0); context.closePath(); } drawCanvas();
Message Log
This is a lesson, not a challenge, the code runs automatically.

But change it! Play with it! Click "Run" to see your changes.

Run
Run and Focus Canvas
Reset